Skip to content

Commit 0d7e54b

Browse files
authored
Upgrade to TypeScript 4.8 (#1338)
* Upgrade to TypeScript 4.8 * Try without upgrading lua-types * also revert package lock * more upgrades * Try to fix package-lock * Upgrade lua-types
1 parent e1a1fa6 commit 0d7e54b

File tree

10 files changed

+7108
-5020
lines changed

10 files changed

+7108
-5020
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const isCI = require("is-ci");
1+
const isCI = process.env.GITHUB_ACTIONS !== undefined;
22

33
/** @type {Partial<import("@jest/types").Config.DefaultOptions>} */
44
module.exports = {

language-extensions/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,11 @@ declare interface ReadonlyLuaSet<T extends AnyNotNil = AnyNotNil> extends LuaPai
666666

667667
interface ObjectConstructor {
668668
/** Returns an array of keys of an object, when iterated with `pairs`. */
669-
keys<K>(o: LuaPairsIterable<K, any> | LuaPairsKeyIterable<K>): K[];
669+
keys<K extends AnyNotNil>(o: LuaPairsIterable<K, any> | LuaPairsKeyIterable<K>): K[];
670670

671671
/** Returns an array of values of an object, when iterated with `pairs`. */
672672
values<V>(o: LuaPairsIterable<any, V>): V[];
673673

674674
/** Returns an array of key/values of an object, when iterated with `pairs`. */
675-
entries<K, V>(o: LuaPairsIterable<K, V>): Array<[K, V]>;
675+
entries<K extends AnyNotNil, V>(o: LuaPairsIterable<K, V>): Array<[K, V]>;
676676
}

package-lock.json

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

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
3333
"lint:eslint": "eslint . --ext .js,.ts",
3434
"fix:prettier": "prettier --write .",
35-
"check:language-extensions": "tsc language-extensions/index.d.ts",
35+
"check:language-extensions": "tsc --strict language-extensions/index.d.ts",
3636
"preversion": "npm run build && npm test",
3737
"postversion": "git push && git push --tags"
3838
},
3939
"bin": {
4040
"tstl": "dist/tstl.js"
4141
},
4242
"engines": {
43-
"node": ">=12.13.0"
43+
"node": ">=16.10.0"
4444
},
4545
"peerDependencies": {
46-
"typescript": "~4.7.3"
46+
"typescript": "~4.8.2"
4747
},
4848
"dependencies": {
4949
"enhanced-resolve": "^5.8.2",
@@ -56,20 +56,20 @@
5656
"@types/jest": "^27.5.2",
5757
"@types/node": "^13.7.7",
5858
"@types/resolve": "1.14.0",
59-
"@typescript-eslint/eslint-plugin": "^5.27.0",
60-
"@typescript-eslint/parser": "^5.27.0",
61-
"eslint": "^8.17.0",
59+
"@typescript-eslint/eslint-plugin": "^5.35.1",
60+
"@typescript-eslint/parser": "^5.35.1",
61+
"eslint": "^8.23.0",
6262
"eslint-plugin-import": "^2.26.0",
63-
"eslint-plugin-jest": "^26.4.6",
63+
"eslint-plugin-jest": "^26.8.7",
6464
"fs-extra": "^8.1.0",
6565
"javascript-stringify": "^2.0.1",
66-
"jest": "^27.3.0",
67-
"jest-circus": "^27.3.0",
68-
"lua-types": "^2.11.0",
66+
"jest": "^28.1.3",
67+
"jest-circus": "^29.0.1",
68+
"lua-types": "^2.12.1",
6969
"lua-wasm-bindings": "^0.2.2",
7070
"prettier": "^2.3.2",
71-
"ts-jest": "^27.1.3",
72-
"ts-node": "^10.3.0",
73-
"typescript": "~4.7.3"
71+
"ts-jest": "^28.0.8",
72+
"ts-node": "^10.9.1",
73+
"typescript": "~4.8.2"
7474
}
7575
}

src/transformation/utils/typescript/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function isExpressionWithEvaluationEffect(node: ts.Expression): boolean {
9191

9292
export function getFunctionTypeForCall(context: TransformationContext, node: ts.CallExpression) {
9393
const signature = context.checker.getResolvedSignature(node);
94-
if (!signature || !signature.declaration) {
94+
if (!signature?.declaration) {
9595
return;
9696
}
9797
const typeDeclaration = findFirstNodeAbove(signature.declaration, ts.isTypeAliasDeclaration);
@@ -110,7 +110,7 @@ export function isConstIdentifier(context: TransformationContext, node: ts.Node)
110110
return false;
111111
}
112112
const symbol = context.checker.getSymbolAtLocation(identifier);
113-
if (!symbol || !symbol.declarations) {
113+
if (!symbol?.declarations) {
114114
return false;
115115
}
116116
return symbol.declarations.some(

src/transformation/visitors/class/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ function transformClassLikeDeclaration(
187187
result.push(...decorationStatements);
188188

189189
// Decorate the class
190-
if (classDeclaration.decorators) {
190+
if (ts.canHaveDecorators(classDeclaration) && ts.getDecorators(classDeclaration)) {
191191
const decoratingExpression = createDecoratingExpression(
192192
context,
193193
classDeclaration.kind,
194-
classDeclaration.decorators.map(d => transformDecoratorExpression(context, d)),
194+
ts.getDecorators(classDeclaration)?.map(d => transformDecoratorExpression(context, d)) ?? [],
195195
localClassName
196196
);
197197
const decoratingStatement = lua.createAssignmentStatement(localClassName, decoratingExpression);

src/transformation/visitors/class/members/fields.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export function createPropertyDecoratingExpression(
1212
node: ts.PropertyDeclaration | ts.AccessorDeclaration,
1313
className: lua.Identifier
1414
): lua.Expression | undefined {
15-
if (!node.decorators) return;
15+
if (!ts.canHaveDecorators(node)) return;
16+
const decorators = ts.getDecorators(node);
17+
if (!decorators) return;
1618
const propertyName = transformPropertyName(context, node.name);
1719
const propertyOwnerTable = transformMemberExpressionOwnerName(node, className);
1820
return createDecoratingExpression(
1921
context,
2022
node.kind,
21-
node.decorators.map(d => transformDecoratorExpression(context, d)),
23+
decorators.map(d => transformDecoratorExpression(context, d)),
2224
propertyOwnerTable,
2325
propertyName
2426
);

src/transformation/visitors/class/members/method.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,21 @@ export function createMethodDecoratingExpression(
5353

5454
const parameterDecorators = node.parameters
5555
.flatMap((parameter, index) =>
56-
parameter.decorators?.map(decorator =>
57-
transformLuaLibFunction(
58-
context,
59-
LuaLibFeature.DecorateParam,
60-
node,
61-
lua.createNumericLiteral(index),
62-
transformDecoratorExpression(context, decorator)
56+
ts
57+
.getDecorators(parameter)
58+
?.map(decorator =>
59+
transformLuaLibFunction(
60+
context,
61+
LuaLibFeature.DecorateParam,
62+
node,
63+
lua.createNumericLiteral(index),
64+
transformDecoratorExpression(context, decorator)
65+
)
6366
)
64-
)
6567
)
6668
.filter(isNonNull);
6769

68-
const methodDecorators = node.decorators?.map(d => transformDecoratorExpression(context, d)) ?? [];
70+
const methodDecorators = ts.getDecorators(node)?.map(d => transformDecoratorExpression(context, d)) ?? [];
6971

7072
if (methodDecorators.length > 0 || parameterDecorators.length > 0) {
7173
const decorateMethod = createDecoratingExpression(

src/transformation/visitors/modules/export.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ function transformExportSpecifiersFrom(
136136
)
137137
);
138138

139-
const importDeclaration = ts.factory.createImportDeclaration(
140-
statement.decorators,
141-
statement.modifiers,
142-
importClause,
143-
moduleSpecifier
144-
);
139+
const importDeclaration = ts.factory.createImportDeclaration(statement.modifiers, importClause, moduleSpecifier);
145140

146141
// Wrap in block to prevent imports from hoisting out of `do` statement
147142
const [block] = transformScopeBlock(context, ts.factory.createBlock([importDeclaration]), ScopeType.Block);

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from "path";
55
export function castArray<T>(value: T | T[]): T[];
66
export function castArray<T>(value: T | readonly T[]): readonly T[];
77
export function castArray<T>(value: T | readonly T[]): readonly T[] {
8-
return Array.isArray(value) ? value : [value];
8+
return Array.isArray(value) ? value : [value as T];
99
}
1010

1111
export const intersperse = <T>(values: readonly T[], separator: T): T[] =>

0 commit comments

Comments
 (0)