From ecad13ff527b59ab27b43c32ee0222b5ab218d43 Mon Sep 17 00:00:00 2001 From: HanaTaka2137 <96463311+XiYang6666@users.noreply.github.com> Date: Sat, 12 Jul 2025 21:36:26 +0800 Subject: [PATCH 1/5] fix: resolve #1647 (#1648) * fix: resolve #1647 * test: add test --- src/transformation/utils/function-context.ts | 3 ++- .../__snapshots__/noSelfAnnotation.spec.ts.snap | 5 +++++ test/unit/functions/noSelfAnnotation.spec.ts | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/transformation/utils/function-context.ts b/src/transformation/utils/function-context.ts index 5b2c0cb4e..d61ffb5bf 100644 --- a/src/transformation/utils/function-context.ts +++ b/src/transformation/utils/function-context.ts @@ -124,7 +124,8 @@ function computeDeclarationContextType(context: TransformationContext, signature ts.isConstructSignatureDeclaration(signatureDeclaration) || ts.isConstructorDeclaration(signatureDeclaration) || (signatureDeclaration.parent && ts.isPropertyDeclaration(signatureDeclaration.parent)) || - (signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent)) + (signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent)) || + (signatureDeclaration.parent && ts.isIndexSignatureDeclaration(signatureDeclaration.parent)) ) { // Class/interface methods only respect @noSelf on their parent const scopeDeclaration = findFirstNodeAbove( diff --git a/test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap b/test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap index f4e5fdd6d..64eb65457 100644 --- a/test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap +++ b/test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap @@ -13,3 +13,8 @@ exports[`@noSelf on parent class declaration removes context argument 1`] = `"ho exports[`@noSelf on parent interface declaration removes context argument 1`] = `"holder.myMethod()"`; exports[`@noSelf on parent namespace declaration removes context argument 1`] = `"MyNamespace.myMethod()"`; + +exports[`@noSelf on static class methods with string key access 1`] = ` +"TestClass.myMethod() +TestClass.myKey()" +`; diff --git a/test/unit/functions/noSelfAnnotation.spec.ts b/test/unit/functions/noSelfAnnotation.spec.ts index b25742a11..f8418fabd 100644 --- a/test/unit/functions/noSelfAnnotation.spec.ts +++ b/test/unit/functions/noSelfAnnotation.spec.ts @@ -52,6 +52,19 @@ test("@noSelf on parent namespace declaration removes context argument", () => { `.expectLuaToMatchSnapshot(); }); +test("@noSelf on static class methods with string key access", () => { + util.testModule` + /** @noSelf */ + declare class TestClass { + static [key: string]: () => void; + static myMethod(): void; + } + + TestClass.myMethod(); + TestClass.myKey(); + `.expectLuaToMatchSnapshot(); +}); + // additional coverage for https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1292 test("explicit this parameter respected over @noSelf", () => { util.testModule` From bd799f436180426f1529184c99a6e43ab17fef93 Mon Sep 17 00:00:00 2001 From: Perry van Wesel Date: Sat, 12 Jul 2025 16:42:52 +0200 Subject: [PATCH 2/5] fix issue with unicode classnames and static initializer blocks (#1649) --- src/transformation/visitors/class/index.ts | 4 ++-- test/unit/__snapshots__/identifiers.spec.ts.snap | 15 +++++++++++++++ test/unit/identifiers.spec.ts | 11 +++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/transformation/visitors/class/index.ts b/src/transformation/visitors/class/index.ts index d4633995e..b01617171 100644 --- a/src/transformation/visitors/class/index.ts +++ b/src/transformation/visitors/class/index.ts @@ -202,7 +202,7 @@ function transformClassLikeDeclaration( const iif = lua.createFunctionExpression(lua.createBlock(bodyStatements), [ lua.createIdentifier("self"), ]); - const iife = lua.createCallExpression(iif, [className]); + const iife = lua.createCallExpression(iif, [localClassName]); result.push(lua.createExpressionStatement(iife, member)); } } @@ -217,7 +217,7 @@ function transformClassLikeDeclaration( if (shouldBeExported(classDeclaration)) { const exportExpression = hasDefaultExportModifier(classDeclaration) ? createDefaultExportExpression(classDeclaration) - : createExportedIdentifier(context, className); + : createExportedIdentifier(context, localClassName); const classAssignment = lua.createAssignmentStatement(exportExpression, localClassName); result.push(classAssignment); diff --git a/test/unit/__snapshots__/identifiers.spec.ts.snap b/test/unit/__snapshots__/identifiers.spec.ts.snap index 4a8ddc751..b90b10398 100644 --- a/test/unit/__snapshots__/identifiers.spec.ts.snap +++ b/test/unit/__snapshots__/identifiers.spec.ts.snap @@ -427,3 +427,18 @@ function ____exports.__main(self) end return ____exports" `; + +exports[`unicode static initialization block (#1645) 1`] = ` +"local ____lualib = require("lualib_bundle") +local __TS__Class = ____lualib.__TS__Class +local ____exports = {} +____exports.default = __TS__Class() +local _____81EA_5B9A_4E49_5F02_80FD = ____exports.default +_____81EA_5B9A_4E49_5F02_80FD.name = "自定义异能" +function _____81EA_5B9A_4E49_5F02_80FD.prototype.____constructor(self) +end; +(function(self) + local a = 1 +end)(_____81EA_5B9A_4E49_5F02_80FD) +return ____exports" +`; diff --git a/test/unit/identifiers.spec.ts b/test/unit/identifiers.spec.ts index 4ef550c4e..4156e83ff 100644 --- a/test/unit/identifiers.spec.ts +++ b/test/unit/identifiers.spec.ts @@ -317,6 +317,17 @@ test("unicode export default class", () => { .expectToEqual({ result: "你好" }); }); +// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1645 +test("unicode static initialization block (#1645)", () => { + util.testModule` + export default class 自定义异能 { + static { + let a = 1; + } + } + `.expectLuaToMatchSnapshot(); +}); + describe("lua keyword as identifier doesn't interfere with lua's value", () => { test("variable (nil)", () => { util.testFunction` From d541c9b44a05c59ad63481f5cffa77a1e685e8a7 Mon Sep 17 00:00:00 2001 From: Perryvw Date: Sat, 12 Jul 2025 21:59:07 +0200 Subject: [PATCH 3/5] 1.31.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b2fdb24d8..af8f3323b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typescript-to-lua", - "version": "1.31.2", + "version": "1.31.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "typescript-to-lua", - "version": "1.31.2", + "version": "1.31.3", "license": "MIT", "dependencies": { "@typescript-to-lua/language-extensions": "1.19.0", diff --git a/package.json b/package.json index 3a1e7efe8..0a97056e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-to-lua", - "version": "1.31.2", + "version": "1.31.3", "description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", "homepage": "https://typescripttolua.github.io/", From 102a00a8b0989b9037f20b95b1d274bd6362f2a1 Mon Sep 17 00:00:00 2001 From: aabajyan <62068860+aabajyan@users.noreply.github.com> Date: Thu, 17 Jul 2025 22:39:26 +0400 Subject: [PATCH 4/5] fix: only parse arguments from first line of tag comment (#1650) --- src/transformation/utils/annotations.ts | 3 ++- .../__snapshots__/transformation.spec.ts.snap | 2 ++ .../transformation/customNameWithExtraComment.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/translation/transformation/customNameWithExtraComment.ts diff --git a/src/transformation/utils/annotations.ts b/src/transformation/utils/annotations.ts index 91ef6d531..b66704c97 100644 --- a/src/transformation/utils/annotations.ts +++ b/src/transformation/utils/annotations.ts @@ -105,7 +105,8 @@ export function getFileAnnotations(sourceFile: ts.SourceFile): AnnotationsMap { function getTagArgsFromComment(tag: ts.JSDocTag): string[] { if (tag.comment) { if (typeof tag.comment === "string") { - return tag.comment.split(" "); + const firstLine = tag.comment.split("\n")[0]; + return firstLine.trim().split(" "); } else { return tag.comment.map(part => part.text); } diff --git a/test/translation/__snapshots__/transformation.spec.ts.snap b/test/translation/__snapshots__/transformation.spec.ts.snap index 6753c66b1..e9fccb4ae 100644 --- a/test/translation/__snapshots__/transformation.spec.ts.snap +++ b/test/translation/__snapshots__/transformation.spec.ts.snap @@ -36,6 +36,8 @@ escapedCharsInTemplateString = "\\\\ \\0 \\b \\t \\n \\v \\f \\" ' \`" nonEmptyTemplateString = ("Level 0: \\n\\t " .. ("Level 1: \\n\\t\\t " .. ("Level 3: \\n\\t\\t\\t " .. "Last level \\n --") .. " \\n --") .. " \\n --") .. " \\n --"" `; +exports[`Transformation (customNameWithExtraComment) 1`] = `"TestNamespace.pass()"`; + exports[`Transformation (customNameWithNoSelf) 1`] = `"TestNamespace.pass()"`; exports[`Transformation (exportStatement) 1`] = ` diff --git a/test/translation/transformation/customNameWithExtraComment.ts b/test/translation/transformation/customNameWithExtraComment.ts new file mode 100644 index 000000000..459512ded --- /dev/null +++ b/test/translation/transformation/customNameWithExtraComment.ts @@ -0,0 +1,10 @@ +/** @noSelf */ +declare namespace TestNamespace { + /** + * @customName pass + * The first word should not be included. + **/ + function fail(): void; +} + +TestNamespace.fail(); From 8a43f43337eca0eadaca9849f89ff36605ca6e02 Mon Sep 17 00:00:00 2001 From: Perryvw Date: Thu, 17 Jul 2025 20:46:55 +0200 Subject: [PATCH 5/5] 1.31.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index af8f3323b..cdb77ea17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typescript-to-lua", - "version": "1.31.3", + "version": "1.31.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "typescript-to-lua", - "version": "1.31.3", + "version": "1.31.4", "license": "MIT", "dependencies": { "@typescript-to-lua/language-extensions": "1.19.0", diff --git a/package.json b/package.json index 0a97056e1..683c7e538 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-to-lua", - "version": "1.31.3", + "version": "1.31.4", "description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!", "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua", "homepage": "https://typescripttolua.github.io/",