Skip to content

Commit ecad13f

Browse files
authored
fix: resolve #1647 (#1648)
* fix: resolve #1647 * test: add test
1 parent 7fed67b commit ecad13f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/transformation/utils/function-context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ function computeDeclarationContextType(context: TransformationContext, signature
124124
ts.isConstructSignatureDeclaration(signatureDeclaration) ||
125125
ts.isConstructorDeclaration(signatureDeclaration) ||
126126
(signatureDeclaration.parent && ts.isPropertyDeclaration(signatureDeclaration.parent)) ||
127-
(signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent))
127+
(signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent)) ||
128+
(signatureDeclaration.parent && ts.isIndexSignatureDeclaration(signatureDeclaration.parent))
128129
) {
129130
// Class/interface methods only respect @noSelf on their parent
130131
const scopeDeclaration = findFirstNodeAbove(

test/unit/functions/__snapshots__/noSelfAnnotation.spec.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ exports[`@noSelf on parent class declaration removes context argument 1`] = `"ho
1313
exports[`@noSelf on parent interface declaration removes context argument 1`] = `"holder.myMethod()"`;
1414

1515
exports[`@noSelf on parent namespace declaration removes context argument 1`] = `"MyNamespace.myMethod()"`;
16+
17+
exports[`@noSelf on static class methods with string key access 1`] = `
18+
"TestClass.myMethod()
19+
TestClass.myKey()"
20+
`;

test/unit/functions/noSelfAnnotation.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ test("@noSelf on parent namespace declaration removes context argument", () => {
5252
`.expectLuaToMatchSnapshot();
5353
});
5454

55+
test("@noSelf on static class methods with string key access", () => {
56+
util.testModule`
57+
/** @noSelf */
58+
declare class TestClass {
59+
static [key: string]: () => void;
60+
static myMethod(): void;
61+
}
62+
63+
TestClass.myMethod();
64+
TestClass.myKey();
65+
`.expectLuaToMatchSnapshot();
66+
});
67+
5568
// additional coverage for https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1292
5669
test("explicit this parameter respected over @noSelf", () => {
5770
util.testModule`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy