Skip to content

Commit 137d8cb

Browse files
authored
Add support for Typescript 4.9 (#1365)
* Update typescript dependency * Remove test cases which are now TS errors * Remove deprecated API usages * Add support for satisfies expressions * Cleanup issues found by code analysis * Fix prettier
1 parent 2ecf2bf commit 137d8cb

File tree

21 files changed

+52
-47
lines changed

21 files changed

+52
-47
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"node": ">=16.10.0"
4343
},
4444
"peerDependencies": {
45-
"typescript": "~4.8.2"
45+
"typescript": "~4.9.3"
4646
},
4747
"dependencies": {
4848
"@typescript-to-lua/language-extensions": "1.0.0",
@@ -70,6 +70,6 @@
7070
"prettier": "^2.3.2",
7171
"ts-jest": "^28.0.8",
7272
"ts-node": "^10.9.1",
73-
"typescript": "~4.8.2"
73+
"typescript": "~4.9.3"
7474
}
7575
}

src/LuaAST.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// because we don't create the AST from text
66

77
import * as ts from "typescript";
8-
import { LuaLibFeature } from "./transformation/utils/lualib";
8+
import { LuaLibFeature } from "./LuaLib";
99
import { castArray } from "./utils";
1010

1111
export enum SyntaxKind {
@@ -816,6 +816,7 @@ export function createTableIndexExpression(
816816
}
817817

818818
export type AssignmentLeftHandSideExpression = Identifier | TableIndexExpression;
819+
819820
export function isAssignmentLeftHandSideExpression(node: Node): node is AssignmentLeftHandSideExpression {
820821
return isIdentifier(node) || isTableIndexExpression(node);
821822
}

src/LuaPrinter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Mapping, SourceMapGenerator, SourceNode } from "source-map";
33
import * as ts from "typescript";
44
import { CompilerOptions, isBundleEnabled, LuaLibImportKind, LuaTarget } from "./CompilerOptions";
55
import * as lua from "./LuaAST";
6-
import { loadInlineLualibFeatures, LuaLibFeature, loadImportedLualibFeatures } from "./LuaLib";
6+
import { loadImportedLualibFeatures, loadInlineLualibFeatures, LuaLibFeature } from "./LuaLib";
77
import { isValidLuaIdentifier, shouldAllowUnicode } from "./transformation/utils/safe-names";
88
import { EmitHost, getEmitPath } from "./transpilation";
99
import { intersperse, normalizeSlashes } from "./utils";
@@ -899,9 +899,9 @@ export class LuaPrinter {
899899
map.addMapping(currentMapping);
900900
}
901901

902-
for (const chunk of sourceNode.children) {
902+
for (const chunk of sourceNode.children as SourceChunk[]) {
903903
if (typeof chunk === "string") {
904-
const lines = (chunk as string).split("\n");
904+
const lines = chunk.split("\n");
905905
if (lines.length > 1) {
906906
generatedLine += lines.length - 1;
907907
generatedColumn = 0;

src/cli/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function updateParsedCommandLine(parsedCommandLine: ts.ParsedCommandLine, args:
147147
if (!args[i].startsWith("-")) continue;
148148

149149
const isShorthand = !args[i].startsWith("--");
150-
const argumentName = args[i].substr(isShorthand ? 1 : 2);
150+
const argumentName = args[i].substring(isShorthand ? 1 : 2);
151151
const option = optionDeclarations.find(option => {
152152
if (option.name.toLowerCase() === argumentName.toLowerCase()) return true;
153153
if (isShorthand && option.aliases) {

src/lualib/ParseInt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export function __TS__ParseInt(this: void, numberString: string, base?: number):
1010
if (hexMatch) {
1111
base = 16;
1212
numberString = __TS__Match(hexMatch, "-")[0]
13-
? "-" + numberString.substr(hexMatch.length)
14-
: numberString.substr(hexMatch.length);
13+
? "-" + numberString.substring(hexMatch.length)
14+
: numberString.substring(hexMatch.length);
1515
}
1616
}
1717

@@ -22,7 +22,7 @@ export function __TS__ParseInt(this: void, numberString: string, base?: number):
2222

2323
// Calculate string match pattern to use
2424
const allowedDigits =
25-
base <= 10 ? parseIntBasePattern.substring(0, base) : parseIntBasePattern.substr(0, 10 + 2 * (base - 10));
25+
base <= 10 ? parseIntBasePattern.substring(0, base) : parseIntBasePattern.substring(0, 10 + 2 * (base - 10));
2626
const pattern = `^%s*(-?[${allowedDigits}]*)`;
2727

2828
// Try to parse with Lua tonumber

src/lualib/SetDescriptor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ export function __TS__SetDescriptor(
7373
if (value !== undefined) rawset(target, key, undefined);
7474

7575
if (!rawget(metatable, "_descriptors")) metatable._descriptors = {};
76-
const descriptor = __TS__CloneDescriptor(desc);
77-
metatable._descriptors[key] = descriptor;
76+
metatable._descriptors[key] = __TS__CloneDescriptor(desc);
7877
metatable.__index = descriptorIndex;
7978
metatable.__newindex = descriptorNewIndex;
8079
}

src/transformation/context/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ export class TransformationContext {
6565
/** @internal */
6666
public transformNodeRaw(node: ts.Node, isExpression?: boolean) {
6767
// TODO: Move to visitors?
68-
if (node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
68+
if (
69+
ts.canHaveModifiers(node) &&
70+
node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)
71+
) {
6972
return [];
7073
}
7174

src/transformation/context/visitors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ interface NodesBySyntaxKind {
6161
[ts.SyntaxKind.AsExpression]: ts.AsExpression;
6262
[ts.SyntaxKind.NonNullExpression]: ts.NonNullExpression;
6363
[ts.SyntaxKind.MetaProperty]: ts.MetaProperty;
64+
[ts.SyntaxKind.SatisfiesExpression]: ts.SatisfiesExpression;
6465
[ts.SyntaxKind.TemplateSpan]: ts.TemplateSpan;
6566
[ts.SyntaxKind.SemicolonClassElement]: ts.SemicolonClassElement;
6667
[ts.SyntaxKind.Block]: ts.Block;
@@ -148,6 +149,7 @@ export type VisitorResult<T extends ts.Node> = T extends ExpressionLikeNode
148149

149150
export type Visitor<T extends ts.Node> = FunctionVisitor<T> | ObjectVisitor<T>;
150151
export type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
152+
151153
export interface ObjectVisitor<T extends ts.Node> {
152154
transform: FunctionVisitor<T>;
153155

src/transformation/utils/diagnostics.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,13 @@ export const invalidMultiFunctionReturnType = createErrorDiagnosticFactory(
119119
"The $multi function cannot be cast to a non-LuaMultiReturn type."
120120
);
121121

122-
export const invalidMultiTypeToNonArrayLiteral = createErrorDiagnosticFactory("Expected an array literal.");
123-
124-
export const invalidMultiTypeToEmptyPatternOrArrayLiteral = createErrorDiagnosticFactory(
125-
"There must be one or more elements specified here."
126-
);
127-
128122
export const invalidMultiReturnAccess = createErrorDiagnosticFactory(
129123
"The LuaMultiReturn type can only be accessed via an element access expression of a numeric type."
130124
);
131125

132126
export const invalidCallExtensionUse = createErrorDiagnosticFactory(
133127
"This function must be called directly and cannot be referred to."
134128
);
135-
136-
export const annotationRemoved = createErrorDiagnosticFactory(
137-
(kind: AnnotationKind) =>
138-
`'@${kind}' has been removed and will no longer have any effect.` +
139-
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`
140-
);
141-
142129
export const annotationDeprecated = createWarningDiagnosticFactory(
143130
(kind: AnnotationKind) =>
144131
`'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +

0 commit comments

Comments
 (0)