Skip to content

Commit 0bfdaf5

Browse files
authored
Upgrade TypeScript to 4.4 (#1138)
* Upgrade TypeScript to 4.4 * Add back direct dependency to ts * Add assert to test runner * Removed unused import * fix assert issue again
1 parent 0364cdf commit 0bfdaf5

File tree

10 files changed

+291
-725
lines changed

10 files changed

+291
-725
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ module.exports = {
6868

6969
"jest/expect-expect": "off",
7070
"jest/consistent-test-it": ["error", { fn: "test", withinDescribe: "test" }],
71+
"jest/no-disabled-tests": "error",
7172
"jest/no-expect-resolves": "error",
73+
"jest/no-identical-title": "off",
7274
"jest/no-test-return-statement": "error",
7375
"jest/no-truthy-falsy": "error",
7476
"jest/prefer-spy-on": "error",

package-lock.json

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

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,26 @@
4141
"engines": {
4242
"node": ">=12.13.0"
4343
},
44+
"peerDependencies": {
45+
"typescript": "~4.4.3"
46+
},
4447
"dependencies": {
4548
"enhanced-resolve": "^5.8.2",
4649
"resolve": "^1.15.1",
4750
"source-map": "^0.7.3",
48-
"typescript": "~4.3.5"
51+
"typescript": "~4.4.3"
4952
},
5053
"devDependencies": {
5154
"@types/fs-extra": "^8.1.0",
5255
"@types/glob": "^7.1.1",
5356
"@types/jest": "^25.1.3",
5457
"@types/node": "^13.7.7",
5558
"@types/resolve": "1.14.0",
56-
"@typescript-eslint/eslint-plugin": "^4.26.1",
57-
"@typescript-eslint/parser": "^4.26.1",
58-
"eslint": "^7.28.0",
59-
"eslint-plugin-import": "^2.20.1",
60-
"eslint-plugin-jest": "^23.8.2",
59+
"@typescript-eslint/eslint-plugin": "^4.31.0",
60+
"@typescript-eslint/parser": "^4.31.0",
61+
"eslint": "^7.32.0",
62+
"eslint-plugin-import": "^2.24.2",
63+
"eslint-plugin-jest": "^24.4.0",
6164
"fs-extra": "^8.1.0",
6265
"javascript-stringify": "^2.0.1",
6366
"jest": "^26.0.1",
@@ -66,6 +69,6 @@
6669
"lua-wasm-bindings": "^0.2.2",
6770
"prettier": "^2.3.2",
6871
"ts-jest": "^26.3.0",
69-
"ts-node": "^8.6.2"
72+
"ts-node": "^10.2.1"
7073
}
7174
}

src/lualib/Symbol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ____symbolMetatable = {
55
};
66

77
function __TS__Symbol(this: void, description?: string | number): symbol {
8-
return setmetatable({ description }, ____symbolMetatable) as symbol;
8+
return setmetatable({ description }, ____symbolMetatable) as unknown as symbol;
99
}
1010

1111
Symbol = {

src/transpilation/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ export function resolvePlugin(
4646
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "string") };
4747
}
4848

49+
const isModuleNotFoundError = (error: any) => error.code === "MODULE_NOT_FOUND";
50+
4951
let resolved: string;
5052
try {
5153
resolved = resolve.sync(query, { basedir, extensions: [".js", ".ts", ".tsx"] });
5254
} catch (err) {
53-
if (err.code !== "MODULE_NOT_FOUND") throw err;
55+
if (!isModuleNotFoundError(err)) throw err;
5456
return { error: diagnosticFactories.couldNotResolveFrom(kind, query, basedir) };
5557
}
5658

@@ -61,7 +63,7 @@ export function resolvePlugin(
6163
const tsNode: typeof import("ts-node") = require(tsNodePath);
6264
tsNode.register({ transpileOnly: true });
6365
} catch (err) {
64-
if (err.code !== "MODULE_NOT_FOUND") throw err;
66+
if (!isModuleNotFoundError(err)) throw err;
6567
return { error: diagnosticFactories.toLoadItShouldBeTranspiled(kind, query) };
6668
}
6769
}

test/unit/builtins/numbers.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ test.each([
2222
util.testExpression(code).expectToMatchJsResult();
2323
});
2424

25+
// Current implementation does not allow this
26+
// eslint-disable-next-line jest/no-disabled-tests
2527
test.skip.each(["NaN", "Infinity"])("%s reassignment", name => {
2628
util.testFunction`
2729
const ${name} = 1;

test/unit/error.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ test("throwString", () => {
66
`.expectToEqual(new util.ExecutionError("Some Error"));
77
});
88

9+
// TODO: Finally does not behave like it should, see #1137
10+
// eslint-disable-next-line jest/no-disabled-tests
911
test.skip.each([0, 1, 2])("re-throw (%p)", i => {
1012
util.testFunction`
1113
const i: number = ${i};

test/unit/functions/validation/__snapshots__/invalidFunctionAssignments.spec.ts.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,10 @@ main.ts(4,24): error TSTL: Unable to convert function with no 'this' parameter t
15381538

15391539
exports[`Invalid function tuple assignment: diagnostics 1`] = `
15401540
"main.ts(5,13): error TS2322: Type '[number, Meth]' is not assignable to type '[number, Func]'.
1541-
Type 'Meth' is not assignable to type 'Func'.
1542-
The 'this' types of each signature are incompatible.
1543-
Type 'void' is not assignable to type '{}'.
1541+
Type at position 1 in source is not compatible with type at position 1 in target.
1542+
Type 'Meth' is not assignable to type 'Func'.
1543+
The 'this' types of each signature are incompatible.
1544+
Type 'void' is not assignable to type '{}'.
15441545
main.ts(5,38): error TSTL: Unable to convert function with a 'this' parameter to function with no 'this'. To fix, wrap in an arrow function, or declare with 'this: void'."
15451546
`;
15461547

test/unit/loops.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,12 @@ describe("for...of empty destructuring", () => {
467467
});
468468
};
469469

470-
describe("declaration", () => declareTests("const "));
471-
describe("assignment", () => declareTests(""));
470+
describe("declaration", () => {
471+
declareTests("const ");
472+
});
473+
describe("assignment", () => {
474+
declareTests("");
475+
});
472476
});
473477

474478
for (const testCase of [

test/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ end)());`;
491491
try {
492492
result = vm.runInContext(this.getJsCodeWithWrapper(), globalContext);
493493
} catch (error) {
494+
const hasMessage = (error: any): error is { message: string } => error.message !== undefined;
495+
assert(hasMessage(error));
494496
return new ExecutionError(error.message);
495497
}
496498

0 commit comments

Comments
 (0)