X Tutup
Skip to content

Commit 8487f7a

Browse files
authored
Allow @noself on any function declaration (#858)
* Allow @noself on any function declaration * PR comments * Fixed snapshots
1 parent 08aa778 commit 8487f7a

File tree

5 files changed

+277
-0
lines changed

5 files changed

+277
-0
lines changed

src/transformation/utils/function-context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export function getDeclarationContextType(
4646
: ContextType.NonVoid;
4747
}
4848

49+
// noSelf declaration on function signature
50+
if (getNodeAnnotations(signatureDeclaration).has(AnnotationKind.NoSelf)) {
51+
return ContextType.Void;
52+
}
53+
4954
if (
5055
ts.isMethodSignature(signatureDeclaration) ||
5156
ts.isMethodDeclaration(signatureDeclaration) ||
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`@noSelf on declared function removes context argument 1`] = `"myFunction()"`;
4+
5+
exports[`@noSelf on method inside class declaration removes context argument 1`] = `"holder.myMethod()"`;
6+
7+
exports[`@noSelf on method inside interface declaration removes context argument 1`] = `"holder.myMethod()"`;
8+
9+
exports[`@noSelf on method inside namespace declaration removes context argument 1`] = `"MyNamespace.myMethod()"`;
10+
11+
exports[`@noSelf on parent class declaration removes context argument 1`] = `"holder.myMethod()"`;
12+
13+
exports[`@noSelf on parent interface declaration removes context argument 1`] = `"holder.myMethod()"`;
14+
15+
exports[`@noSelf on parent namespace declaration removes context argument 1`] = `"MyNamespace.myMethod()"`;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as util from "../../util";
2+
3+
const methodHolders = ["class", "interface"];
4+
5+
test("@noSelf on declared function removes context argument", () => {
6+
util.testModule`
7+
/** @noSelf */
8+
declare function myFunction(): void;
9+
myFunction();
10+
`.expectLuaToMatchSnapshot();
11+
});
12+
13+
test.each(methodHolders)("@noSelf on method inside %s declaration removes context argument", holderType => {
14+
util.testModule`
15+
declare ${holderType} MethodHolder {
16+
/** @noSelf */
17+
myMethod(): void;
18+
}
19+
declare const holder: MethodHolder;
20+
holder.myMethod();
21+
`.expectLuaToMatchSnapshot();
22+
});
23+
24+
test.each(methodHolders)("@noSelf on parent %s declaration removes context argument", holderType => {
25+
util.testModule`
26+
/** @noSelf */
27+
declare ${holderType} MethodHolder {
28+
myMethod(): void;
29+
}
30+
declare const holder: MethodHolder;
31+
holder.myMethod();
32+
`.expectLuaToMatchSnapshot();
33+
});
34+
35+
test("@noSelf on method inside namespace declaration removes context argument", () => {
36+
util.testModule`
37+
declare namespace MyNamespace {
38+
/** @noSelf */
39+
export function myMethod(): void;
40+
}
41+
MyNamespace.myMethod();
42+
`.expectLuaToMatchSnapshot();
43+
});
44+
45+
test("@noSelf on parent namespace declaration removes context argument", () => {
46+
util.testModule`
47+
/** @noSelf */
48+
declare namespace MyNamespace {
49+
export function myMethod(): void;
50+
}
51+
MyNamespace.myMethod();
52+
`.expectLuaToMatchSnapshot();
53+
});

0 commit comments

Comments
 (0)
X Tutup