Skip to content

Commit 2352fd4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix/for-let-per-iteration-binding
2 parents e2c8f43 + ef946a3 commit 2352fd4

58 files changed

Lines changed: 853 additions & 748 deletions

Some content is hidden

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

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## 1.36.0
4+
5+
- **[Breaking]** Upgraded to TypeScript 6.0
6+
Thanks @RealColdFry for the following fixes:
7+
- Fixed many bugs with try/catch/finally
8+
- Also fixed some bugs with try/catch/finally in promises
9+
- Fixed a bug where collection iterators would not correctly update when the collection updated
10+
- No longer generate dead code after `break` statements
11+
- Fixed a bug where math.atan2 was incorrectly used instead of math.atan for Lua 5.4
12+
- Fixed some inconsistencies with number constants (Number.MAX_SAFE_INTEGER, Number.MIN_VALUE, etc)
13+
- Fixed a bug with the `>>>` operator for Lua 5.3
14+
- Fixed incorrect side effects for array destructors
15+
- Fixed broken code when generating requires for files with `.` in the file name (e.g. `foo.tests.ts`), now the periods will be translated to `_`
16+
- Fixed some incorrect handling of synthetic nodes
17+
- Fixed a bug where object spread could lead to incorrect code being generated
18+
- Fixed a bug with Object.defineProperty sharing values accross object instances
19+
320
## 1.34.0
421

522
- Added support for the Lua 5.5 target (it mostly does the same as the 5.4 target for now)

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: 335 additions & 398 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-to-lua",
3-
"version": "1.34.0",
3+
"version": "1.36.0",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",
@@ -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/utils/typescript/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export function hasExportEquals(sourceFile: ts.SourceFile): boolean {
1414
* Search up until finding a node satisfying the callback
1515
*/
1616
export function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined {
17-
let current = node;
17+
// Synthetic nodes (created by pre-transformers like usingTransformer) may have an unset .parent.
18+
// Fall back to ts.getOriginalNode so we can still walk the source-parsed parent chain.
19+
let current = ts.getOriginalNode(node);
1820
while (current.parent) {
1921
if (callback(current.parent)) {
2022
return current.parent;
2123
} else {
22-
current = current.parent;
24+
current = ts.getOriginalNode(current.parent);
2325
}
2426
}
2527
}

src/transformation/visitors/errors.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,44 @@ const transformAsyncTry: FunctionVisitor<ts.TryStatement> = (statement, context)
4040
let catchScope: Scope | undefined;
4141
const chainCalls: lua.Statement[] = [];
4242

43-
if (statement.finallyBlock) {
44-
const awaiterFinally = lua.createTableIndexExpression(awaiterIdentifier, lua.createStringLiteral("finally"));
45-
const finallyFunction = lua.createFunctionExpression(
46-
lua.createBlock(context.transformStatements(statement.finallyBlock.statements))
47-
);
48-
const finallyCall = lua.createCallExpression(
49-
awaiterFinally,
50-
[awaiterIdentifier, finallyFunction],
51-
statement.finallyBlock
52-
);
53-
chainCalls.push(lua.createExpressionStatement(finallyCall));
54-
}
55-
5643
if (statement.catchClause) {
44+
// ____try = ____try.catch(<catch function>)
5745
const [catchFunction, cScope] = transformCatchClause(context, statement.catchClause);
5846
catchScope = cScope;
5947
if (catchFunction.params) {
6048
catchFunction.params.unshift(lua.createAnonymousIdentifier());
6149
}
6250

51+
const catchBodyStatements = catchFunction.body ? catchFunction.body.statements : [];
52+
const asyncWrappedCatch = wrapInAsyncAwaiter(context, [...catchBodyStatements], false);
53+
catchFunction.body = lua.createBlock([lua.createReturnStatement([asyncWrappedCatch])]);
54+
6355
const awaiterCatch = lua.createTableIndexExpression(awaiterIdentifier, lua.createStringLiteral("catch"));
6456
const catchCall = lua.createCallExpression(awaiterCatch, [awaiterIdentifier, catchFunction]);
65-
const promiseAwait = transformLuaLibFunction(context, LuaLibFeature.Await, statement, catchCall);
66-
chainCalls.push(lua.createExpressionStatement(promiseAwait, statement));
67-
} else {
68-
const promiseAwait = transformLuaLibFunction(context, LuaLibFeature.Await, statement, awaiterIdentifier);
69-
chainCalls.push(lua.createExpressionStatement(promiseAwait, statement));
57+
chainCalls.push(lua.createAssignmentStatement(lua.cloneIdentifier(awaiterIdentifier), catchCall));
7058
}
7159

60+
if (statement.finallyBlock) {
61+
// ____try = ____try.finally(<finally function>)
62+
const finallyStatements = context.transformStatements(statement.finallyBlock.statements);
63+
const asyncWrappedFinally = wrapInAsyncAwaiter(context, finallyStatements, false);
64+
const finallyFunction = lua.createFunctionExpression(
65+
lua.createBlock([lua.createReturnStatement([asyncWrappedFinally])])
66+
);
67+
68+
const awaiterFinally = lua.createTableIndexExpression(awaiterIdentifier, lua.createStringLiteral("finally"));
69+
const finallyCall = lua.createCallExpression(
70+
awaiterFinally,
71+
[awaiterIdentifier, finallyFunction],
72+
statement.finallyBlock
73+
);
74+
chainCalls.push(lua.createAssignmentStatement(lua.cloneIdentifier(awaiterIdentifier), finallyCall));
75+
}
76+
77+
// __TS__Await(____try)
78+
const promiseAwait = transformLuaLibFunction(context, LuaLibFeature.Await, statement, awaiterIdentifier);
79+
chainCalls.push(lua.createExpressionStatement(promiseAwait, statement));
80+
7281
const hasReturn = tryScope.asyncTryHasReturn ?? catchScope?.asyncTryHasReturn;
7382
const hasBreak = tryScope.asyncTryHasBreak ?? catchScope?.asyncTryHasBreak;
7483
const hasContinue = tryScope.asyncTryHasContinue ?? catchScope?.asyncTryHasContinue;

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}'. ` +

0 commit comments

Comments
 (0)