Skip to content

Commit 591989b

Browse files
authored
Upgrade to TypeScript 6.0 (#1704)
* Upgarde to TypeScript 6.0 * fix module-resolution tests * fix array tests except splice * fix more tests * update deps to ts6 support * fix more tests * updated snapshots * fix more tests * fix optional chaining tests * only module-resolution test failing * revert utils * fix last test * remove debug code from module-resolution.spec.ts * update benchmark to nodenext module
1 parent 843544d commit 591989b

55 files changed

Lines changed: 668 additions & 725 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"lib": ["esnext"],
55
// Dev types are JIT
66
"types": ["lua-types/jit", "@typescript-to-lua/language-extensions"],
7-
"moduleResolution": "node",
7+
"module": "nodenext",
8+
"moduleResolution": "nodenext",
89
"outDir": "dist",
910
"rootDir": "src",
1011
"strict": true,

package-lock.json

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

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
3232
"lint:eslint": "eslint .",
3333
"fix:prettier": "prettier --write .",
34-
"check:language-extensions": "tsc --strict language-extensions/index.d.ts",
34+
"check:language-extensions": "tsc --strict --ignoreConfig language-extensions/index.d.ts",
3535
"preversion": "npm run build && npm test",
3636
"postversion": "git push && git push --tags"
3737
},
@@ -42,7 +42,7 @@
4242
"node": ">=16.10.0"
4343
},
4444
"peerDependencies": {
45-
"typescript": "5.9.3"
45+
"typescript": "6.0.2"
4646
},
4747
"dependencies": {
4848
"@typescript-to-lua/language-extensions": "1.19.0",
@@ -58,18 +58,18 @@
5858
"@types/node": "^22.10.0",
5959
"@types/picomatch": "^2.3.0",
6060
"@types/resolve": "1.14.0",
61-
"eslint": "^9.22.0",
62-
"eslint-plugin-jest": "^28.8.3",
61+
"eslint": "^9.39.4",
62+
"eslint-plugin-jest": "^28.14.0",
6363
"fs-extra": "^8.1.0",
6464
"javascript-stringify": "^2.0.1",
65-
"jest": "^29.5.0",
65+
"jest": "^29.7.0",
6666
"jest-circus": "^29.7.0",
6767
"lua-types": "^2.14.1",
6868
"lua-wasm-bindings": "^0.5.3",
6969
"prettier": "^2.8.8",
70-
"ts-jest": "^29.2.5",
70+
"ts-jest": "^29.4.9",
7171
"ts-node": "^10.9.2",
72-
"typescript": "5.9.3",
73-
"typescript-eslint": "^8.46.3"
72+
"typescript": "6.0.2",
73+
"typescript-eslint": "^8.58.0"
7474
}
7575
}

src/CompilerOptions.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,5 @@ export function validateOptions(options: CompilerOptions): ts.Diagnostic[] {
9999
diagnostics.push(diagnosticFactories.unsupportedJsxEmit());
100100
}
101101

102-
if (options.paths && !options.baseUrl) {
103-
diagnostics.push(diagnosticFactories.pathsWithoutBaseUrl());
104-
}
105-
106102
return diagnostics;
107103
}

src/transformation/utils/function-context.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ function computeDeclarationContextType(context: TransformationContext, signature
108108
const thisParameter = getExplicitThisParameter(signatureDeclaration);
109109
if (thisParameter) {
110110
// Explicit 'this'
111-
return thisParameter.type && thisParameter.type.kind === ts.SyntaxKind.VoidKeyword
112-
? ContextType.Void
113-
: ContextType.NonVoid;
111+
return thisParameter.type?.kind === ts.SyntaxKind.VoidKeyword ? ContextType.Void : ContextType.NonVoid;
114112
}
115113

116114
// noSelf declaration on function signature

src/transformation/visitors/variable-declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function transformBindingPattern(
6262
}
6363

6464
// Build the path to the table
65-
const tableExpression = propertyAccessStack.reduce<lua.Expression>(
65+
const tableExpression = propertyAccessStack.reduce(
6666
(path, property) => lua.createTableIndexExpression(path, transformPropertyName(context, property)),
6767
table
6868
);

src/transpilation/diagnostics.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export const cannotBundleLibrary = createDiagnosticFactory(
5656

5757
export const unsupportedJsxEmit = createDiagnosticFactory(() => 'JSX is only supported with "react" jsx option.');
5858

59-
export const pathsWithoutBaseUrl = createDiagnosticFactory(
60-
() => "When configuring 'paths' in tsconfig.json, the option 'baseUrl' must also be provided."
61-
);
62-
6359
export const emitPathCollision = createDiagnosticFactory(
6460
(outputPath: string, file1: string, file2: string) =>
6561
`Output path '${outputPath}' is used by both '${file1}' and '${file2}'. ` +

src/transpilation/resolve.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface ResolutionResult {
2727
}
2828

2929
class ResolutionContext {
30-
private noResolvePaths: picomatch.Matcher[];
30+
private noResolvePaths: picomatch.Glob[];
3131

3232
public diagnostics: ts.Diagnostic[] = [];
3333
public resolvedFiles = new Map<string, ProcessedFile>();
@@ -38,9 +38,7 @@ class ResolutionContext {
3838
private readonly emitHost: EmitHost,
3939
private readonly plugins: Plugin[]
4040
) {
41-
const unique = [...new Set(options.noResolvePaths)];
42-
const matchers = unique.map(x => picomatch(x));
43-
this.noResolvePaths = matchers;
41+
this.noResolvePaths = [...new Set(options.noResolvePaths)];
4442
}
4543

4644
public addAndResolveDependencies(file: ProcessedFile): void {
@@ -73,7 +71,7 @@ class ResolutionContext {
7371
return;
7472
}
7573

76-
if (this.noResolvePaths.find(isMatch => isMatch(required.requirePath))) {
74+
if (this.noResolvePaths.find(glob => picomatch.isMatch(required.requirePath, glob))) {
7775
if (this.options.tstlVerbose) {
7876
console.log(
7977
`Skipping module resolution of ${required.requirePath} as it is in the tsconfig noResolvePaths.`
@@ -215,14 +213,16 @@ class ResolutionContext {
215213
const fileFromPath = this.getFileFromPath(resolvedPath);
216214
if (fileFromPath) return fileFromPath;
217215

218-
if (this.options.paths && this.options.baseUrl) {
216+
if (this.options.paths) {
219217
// If no file found yet and paths are present, try to find project file via paths mappings
220-
const fileFromPaths = this.tryGetModuleNameFromPaths(
221-
dependencyPath,
222-
this.options.paths,
223-
this.options.baseUrl
224-
);
225-
if (fileFromPaths) return fileFromPaths;
218+
// When baseUrl is not set, resolve paths relative to the tsconfig directory (TS 6.0+ behavior)
219+
const pathsBase =
220+
this.options.baseUrl ??
221+
(this.options.configFilePath ? path.dirname(this.options.configFilePath) : undefined);
222+
if (pathsBase) {
223+
const fileFromPaths = this.tryGetModuleNameFromPaths(dependencyPath, this.options.paths, pathsBase);
224+
if (fileFromPaths) return fileFromPaths;
225+
}
226226
}
227227

228228
// Not a TS file in our project sources, use resolver to check if we can find dependency

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function cast<TOriginal, TCast extends TOriginal>(
7777
}
7878

7979
export function assert(value: any, message?: string | Error): asserts value {
80-
nativeAssert(value, message);
80+
nativeAssert.ok(value, message);
8181
}
8282

8383
export function assertNever(_value: never): never {

test/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare global {
1313

1414
expect.extend({
1515
toHaveDiagnostics(diagnostics: ts.Diagnostic[], expected?: number[]): jest.CustomMatcherResult {
16-
assert(Array.isArray(diagnostics));
16+
assert.ok(Array.isArray(diagnostics));
1717
// @ts-ignore
1818
const matcherHint = this.utils.matcherHint("toHaveDiagnostics", undefined, "", this);
1919

0 commit comments

Comments
 (0)