typescript-to-lua 0.42.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -1
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +7 -0
- package/dist/LuaLib.js +32 -1
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/Await.lua +59 -0
- package/dist/lualib/OptionalMethodCall.lua +3 -1
- package/dist/lualib/Promise.lua +172 -0
- package/dist/lualib/PromiseAll.lua +44 -0
- package/dist/lualib/PromiseAllSettled.lua +48 -0
- package/dist/lualib/PromiseAny.lua +41 -0
- package/dist/lualib/PromiseRace.lua +28 -0
- package/dist/lualib/SourceMapTraceBack.lua +20 -10
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/lualib_bundle.lua +503 -62
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +35 -32
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.d.ts +7 -0
- package/dist/transformation/builtins/promise.js +46 -0
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -4
- package/dist/transformation/utils/annotations.js +2 -39
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +6 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +19 -13
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +16 -16
- package/dist/transformation/visitors/async-await.d.ts +6 -0
- package/dist/transformation/visitors/async-await.js +38 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +21 -21
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.js +38 -33
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +41 -34
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +13 -13
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -31
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +33 -21
- package/dist/transformation/visitors/identifier.js +25 -19
- package/dist/transformation/visitors/index.js +4 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +5 -7
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -14
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +41 -49
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +16 -11
- package/dist/transformation/visitors/switch.js +132 -30
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +28 -28
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +28 -15
- package/dist/transpilation/transformers.d.ts +1 -0
- package/dist/transpilation/transformers.js +61 -25
- package/dist/transpilation/transpile.js +7 -7
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -13,35 +13,37 @@ function createStringCall(methodName, tsOriginal, ...params) {
|
|
|
13
13
|
function transformStringPrototypeCall(context, node) {
|
|
14
14
|
const expression = node.expression;
|
|
15
15
|
const signature = context.checker.getResolvedSignature(node);
|
|
16
|
-
const params = call_1.transformArguments(context, node.arguments, signature);
|
|
16
|
+
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
17
17
|
const caller = context.transformExpression(expression.expression);
|
|
18
18
|
const expressionName = expression.name.text;
|
|
19
19
|
switch (expressionName) {
|
|
20
20
|
case "replace":
|
|
21
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringReplace, node, caller, ...params);
|
|
21
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringReplace, node, caller, ...params);
|
|
22
|
+
case "replaceAll":
|
|
23
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringReplaceAll, node, caller, ...params);
|
|
22
24
|
case "concat":
|
|
23
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringConcat, node, caller, ...params);
|
|
25
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringConcat, node, caller, ...params);
|
|
24
26
|
case "indexOf": {
|
|
25
27
|
const stringExpression = createStringCall("find", node, caller, params[0], params[1]
|
|
26
28
|
? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
|
|
27
|
-
lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("max")), [lua_ast_1.addToNumericExpression(params[1], 1), lua.createNumericLiteral(1)])
|
|
29
|
+
lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("max")), [(0, lua_ast_1.addToNumericExpression)(params[1], 1), lua.createNumericLiteral(1)])
|
|
28
30
|
: lua.createNilLiteral(), lua.createBooleanLiteral(true));
|
|
29
31
|
return lua.createBinaryExpression(lua.createBinaryExpression(stringExpression, lua.createNumericLiteral(0), lua.SyntaxKind.OrOperator), lua.createNumericLiteral(1), lua.SyntaxKind.SubtractionOperator, node);
|
|
30
32
|
}
|
|
31
33
|
case "substr":
|
|
32
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringSubstr, node, caller, ...params);
|
|
34
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringSubstr, node, caller, ...params);
|
|
33
35
|
case "substring":
|
|
34
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringSubstring, node, caller, ...params);
|
|
36
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringSubstring, node, caller, ...params);
|
|
35
37
|
case "slice": {
|
|
36
|
-
const literalArg1 = lua_ast_1.getNumberLiteralValue(params[0]);
|
|
38
|
+
const literalArg1 = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
|
|
37
39
|
if (params[0] && literalArg1 !== undefined) {
|
|
38
40
|
let stringSubArgs = [
|
|
39
|
-
lua_ast_1.addToNumericExpression(params[0], literalArg1 < 0 ? 0 : 1),
|
|
41
|
+
(0, lua_ast_1.addToNumericExpression)(params[0], literalArg1 < 0 ? 0 : 1),
|
|
40
42
|
];
|
|
41
43
|
if (params[1]) {
|
|
42
|
-
const literalArg2 = lua_ast_1.getNumberLiteralValue(params[1]);
|
|
44
|
+
const literalArg2 = (0, lua_ast_1.getNumberLiteralValue)(params[1]);
|
|
43
45
|
if (literalArg2 !== undefined) {
|
|
44
|
-
stringSubArgs.push(lua_ast_1.addToNumericExpression(params[1], literalArg2 < 0 ? -1 : 0));
|
|
46
|
+
stringSubArgs.push((0, lua_ast_1.addToNumericExpression)(params[1], literalArg2 < 0 ? -1 : 0));
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
49
|
stringSubArgs = undefined;
|
|
@@ -52,69 +54,69 @@ function transformStringPrototypeCall(context, node) {
|
|
|
52
54
|
return createStringCall("sub", node, caller, ...stringSubArgs);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringSlice, node, caller, ...params);
|
|
57
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringSlice, node, caller, ...params);
|
|
56
58
|
}
|
|
57
59
|
case "toLowerCase":
|
|
58
60
|
return createStringCall("lower", node, caller);
|
|
59
61
|
case "toUpperCase":
|
|
60
62
|
return createStringCall("upper", node, caller);
|
|
61
63
|
case "trim":
|
|
62
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringTrim, node, caller);
|
|
64
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringTrim, node, caller);
|
|
63
65
|
case "trimEnd":
|
|
64
66
|
case "trimRight":
|
|
65
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringTrimEnd, node, caller);
|
|
67
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringTrimEnd, node, caller);
|
|
66
68
|
case "trimStart":
|
|
67
69
|
case "trimLeft":
|
|
68
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringTrimStart, node, caller);
|
|
70
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringTrimStart, node, caller);
|
|
69
71
|
case "split":
|
|
70
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringSplit, node, caller, ...params);
|
|
72
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringSplit, node, caller, ...params);
|
|
71
73
|
case "charAt": {
|
|
72
|
-
const literalValue = lua_ast_1.getNumberLiteralValue(params[0]);
|
|
74
|
+
const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
|
|
73
75
|
// Inline string.sub call if we know that parameter is pure and isn't negative
|
|
74
76
|
if (literalValue !== undefined && literalValue >= 0) {
|
|
75
|
-
const firstParamPlusOne = lua_ast_1.addToNumericExpression(params[0], 1);
|
|
77
|
+
const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)(params[0], 1);
|
|
76
78
|
return createStringCall("sub", node, caller, firstParamPlusOne, firstParamPlusOne);
|
|
77
79
|
}
|
|
78
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringCharAt, node, caller, ...params);
|
|
80
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharAt, node, caller, ...params);
|
|
79
81
|
}
|
|
80
82
|
case "charCodeAt": {
|
|
81
|
-
const literalValue = lua_ast_1.getNumberLiteralValue(params[0]);
|
|
83
|
+
const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
|
|
82
84
|
// Inline string.sub call if we know that parameter is pure and isn't negative
|
|
83
85
|
if (literalValue !== undefined && literalValue >= 0) {
|
|
84
|
-
return lua.createBinaryExpression(createStringCall("byte", node, caller, lua_ast_1.addToNumericExpression(params[0], 1)), lua_ast_1.createNaN(), lua.SyntaxKind.OrOperator);
|
|
86
|
+
return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)(params[0], 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator);
|
|
85
87
|
}
|
|
86
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringCharCodeAt, node, caller, ...params);
|
|
88
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharCodeAt, node, caller, ...params);
|
|
87
89
|
}
|
|
88
90
|
case "startsWith":
|
|
89
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringStartsWith, node, caller, ...params);
|
|
91
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringStartsWith, node, caller, ...params);
|
|
90
92
|
case "endsWith":
|
|
91
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringEndsWith, node, caller, ...params);
|
|
93
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringEndsWith, node, caller, ...params);
|
|
92
94
|
case "includes":
|
|
93
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringIncludes, node, caller, ...params);
|
|
95
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringIncludes, node, caller, ...params);
|
|
94
96
|
case "repeat":
|
|
95
97
|
const math = lua.createIdentifier("math");
|
|
96
98
|
const floor = lua.createStringLiteral("floor");
|
|
97
99
|
const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [params[0]]);
|
|
98
100
|
return createStringCall("rep", node, caller, parameter);
|
|
99
101
|
case "padStart":
|
|
100
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringPadStart, node, caller, ...params);
|
|
102
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringPadStart, node, caller, ...params);
|
|
101
103
|
case "padEnd":
|
|
102
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringPadEnd, node, caller, ...params);
|
|
104
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringPadEnd, node, caller, ...params);
|
|
103
105
|
default:
|
|
104
|
-
context.diagnostics.push(diagnostics_1.unsupportedProperty(expression.name, "string", expressionName));
|
|
106
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "string", expressionName));
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
exports.transformStringPrototypeCall = transformStringPrototypeCall;
|
|
108
110
|
function transformStringConstructorCall(context, node) {
|
|
109
111
|
const expression = node.expression;
|
|
110
112
|
const signature = context.checker.getResolvedSignature(node);
|
|
111
|
-
const params = call_1.transformArguments(context, node.arguments, signature);
|
|
113
|
+
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
112
114
|
const expressionName = expression.name.text;
|
|
113
115
|
switch (expressionName) {
|
|
114
116
|
case "fromCharCode":
|
|
115
117
|
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("char")), params, node);
|
|
116
118
|
default:
|
|
117
|
-
context.diagnostics.push(diagnostics_1.unsupportedProperty(expression.name, "String", expressionName));
|
|
119
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "String", expressionName));
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
exports.transformStringConstructorCall = transformStringConstructorCall;
|
|
@@ -124,7 +126,7 @@ function transformStringProperty(context, node) {
|
|
|
124
126
|
const expression = context.transformExpression(node.expression);
|
|
125
127
|
return lua.createUnaryExpression(expression, lua.SyntaxKind.LengthOperator, node);
|
|
126
128
|
default:
|
|
127
|
-
context.diagnostics.push(diagnostics_1.unsupportedProperty(node.name, "string", node.name.text));
|
|
129
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "string", node.name.text));
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
exports.transformStringProperty = transformStringProperty;
|
|
@@ -8,17 +8,17 @@ const call_1 = require("../visitors/call");
|
|
|
8
8
|
function transformSymbolConstructorCall(context, expression) {
|
|
9
9
|
const method = expression.expression;
|
|
10
10
|
const signature = context.checker.getResolvedSignature(expression);
|
|
11
|
-
const parameters = call_1.transformArguments(context, expression.arguments, signature);
|
|
11
|
+
const parameters = (0, call_1.transformArguments)(context, expression.arguments, signature);
|
|
12
12
|
const methodName = method.name.text;
|
|
13
13
|
switch (methodName) {
|
|
14
14
|
case "for":
|
|
15
15
|
case "keyFor":
|
|
16
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.SymbolRegistry);
|
|
16
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.SymbolRegistry);
|
|
17
17
|
const upperMethodName = methodName[0].toUpperCase() + methodName.slice(1);
|
|
18
18
|
const functionIdentifier = lua.createIdentifier(`__TS__SymbolRegistry${upperMethodName}`);
|
|
19
19
|
return lua.createCallExpression(functionIdentifier, parameters, expression);
|
|
20
20
|
default:
|
|
21
|
-
context.diagnostics.push(diagnostics_1.unsupportedProperty(method.name, "Symbol", methodName));
|
|
21
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(method.name, "Symbol", methodName));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.transformSymbolConstructorCall = transformSymbolConstructorCall;
|
|
@@ -35,13 +35,13 @@ class TransformationContext {
|
|
|
35
35
|
}
|
|
36
36
|
const nodeVisitors = this.visitorMap.get(node.kind);
|
|
37
37
|
if (!nodeVisitors || nodeVisitors.length === 0) {
|
|
38
|
-
this.diagnostics.push(diagnostics_1.unsupportedNodeKind(node, node.kind));
|
|
38
|
+
this.diagnostics.push((0, diagnostics_1.unsupportedNodeKind)(node, node.kind));
|
|
39
39
|
return isExpression ? [lua.createNilLiteral()] : [];
|
|
40
40
|
}
|
|
41
41
|
const previousNodeVisitors = this.currentNodeVisitors;
|
|
42
42
|
this.currentNodeVisitors = [...nodeVisitors];
|
|
43
43
|
const visitor = this.currentNodeVisitors.pop();
|
|
44
|
-
const result = lua_ast_1.unwrapVisitorResult(visitor.transform(node, this));
|
|
44
|
+
const result = (0, lua_ast_1.unwrapVisitorResult)(visitor.transform(node, this));
|
|
45
45
|
this.currentNodeVisitors = previousNodeVisitors;
|
|
46
46
|
return result;
|
|
47
47
|
}
|
|
@@ -50,7 +50,7 @@ class TransformationContext {
|
|
|
50
50
|
throw new Error(`There is no super transform for ${ts.SyntaxKind[node.kind]} visitor`);
|
|
51
51
|
}
|
|
52
52
|
const visitor = this.currentNodeVisitors.pop();
|
|
53
|
-
return lua_ast_1.unwrapVisitorResult(visitor.transform(node, this));
|
|
53
|
+
return (0, lua_ast_1.unwrapVisitorResult)(visitor.transform(node, this));
|
|
54
54
|
}
|
|
55
55
|
transformExpression(node) {
|
|
56
56
|
const [result] = this.transformNode(node, true);
|
|
@@ -67,10 +67,10 @@ class TransformationContext {
|
|
|
67
67
|
return result;
|
|
68
68
|
}
|
|
69
69
|
transformStatements(node) {
|
|
70
|
-
return utils_1.castArray(node).flatMap(n => this.transformNode(n));
|
|
70
|
+
return (0, utils_1.castArray)(node).flatMap(n => this.transformNode(n));
|
|
71
71
|
}
|
|
72
72
|
superTransformStatements(node) {
|
|
73
|
-
return utils_1.castArray(node).flatMap(n => this.superTransformNode(n));
|
|
73
|
+
return (0, utils_1.castArray)(node).flatMap(n => this.superTransformNode(n));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
exports.TransformationContext = TransformationContext;
|
|
@@ -12,7 +12,7 @@ function createVisitorMap(customVisitors) {
|
|
|
12
12
|
if (!visitor)
|
|
13
13
|
continue;
|
|
14
14
|
const syntaxKind = Number(syntaxKindKey);
|
|
15
|
-
const nodeVisitors = utils_1.getOrUpdate(visitorMap, syntaxKind, () => []);
|
|
15
|
+
const nodeVisitors = (0, utils_1.getOrUpdate)(visitorMap, syntaxKind, () => []);
|
|
16
16
|
const objectVisitor = typeof visitor === "function" ? { transform: visitor, priority } : visitor;
|
|
17
17
|
nodeVisitors.push(objectVisitor);
|
|
18
18
|
}
|
|
@@ -14,9 +14,7 @@ export declare enum AnnotationKind {
|
|
|
14
14
|
NoSelf = "noSelf",
|
|
15
15
|
NoSelfInFile = "noSelfInFile",
|
|
16
16
|
Vararg = "vararg",
|
|
17
|
-
ForRange = "forRange"
|
|
18
|
-
Jsx = "jsx",
|
|
19
|
-
JsxFrag = "jsxFrag"
|
|
17
|
+
ForRange = "forRange"
|
|
20
18
|
}
|
|
21
19
|
export interface Annotation {
|
|
22
20
|
kind: AnnotationKind;
|
|
@@ -29,7 +27,6 @@ export declare function getNodeAnnotations(node: ts.Node): AnnotationsMap;
|
|
|
29
27
|
export declare function getFileAnnotations(sourceFile: ts.SourceFile): AnnotationsMap;
|
|
30
28
|
export declare function getSignatureAnnotations(context: TransformationContext, signature: ts.Signature): AnnotationsMap;
|
|
31
29
|
export declare function isTupleReturnCall(context: TransformationContext, node: ts.Node): boolean;
|
|
32
|
-
export declare function isInTupleReturnFunction(context: TransformationContext, node: ts.Node): boolean;
|
|
33
30
|
export declare function isLuaIteratorType(context: TransformationContext, node: ts.Node): boolean;
|
|
34
31
|
export declare function isVarargType(context: TransformationContext, node: ts.Node): boolean;
|
|
35
32
|
export declare function isForRangeType(context: TransformationContext, node: ts.Node): boolean;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTagArgsFromComment = exports.isForRangeType = exports.isVarargType = exports.isLuaIteratorType = exports.
|
|
3
|
+
exports.getTagArgsFromComment = exports.isForRangeType = exports.isVarargType = exports.isLuaIteratorType = exports.isTupleReturnCall = exports.getSignatureAnnotations = exports.getFileAnnotations = exports.getNodeAnnotations = exports.getTypeAnnotations = exports.getSymbolAnnotations = exports.AnnotationKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
-
const diagnostics_1 = require("./diagnostics");
|
|
6
|
-
const typescript_1 = require("./typescript");
|
|
7
5
|
var AnnotationKind;
|
|
8
6
|
(function (AnnotationKind) {
|
|
9
7
|
AnnotationKind["Extension"] = "extension";
|
|
@@ -20,8 +18,6 @@ var AnnotationKind;
|
|
|
20
18
|
AnnotationKind["NoSelfInFile"] = "noSelfInFile";
|
|
21
19
|
AnnotationKind["Vararg"] = "vararg";
|
|
22
20
|
AnnotationKind["ForRange"] = "forRange";
|
|
23
|
-
AnnotationKind["Jsx"] = "jsx";
|
|
24
|
-
AnnotationKind["JsxFrag"] = "jsxFrag";
|
|
25
21
|
})(AnnotationKind = exports.AnnotationKind || (exports.AnnotationKind = {}));
|
|
26
22
|
function createAnnotation(name, args) {
|
|
27
23
|
const kind = Object.values(AnnotationKind).find(k => k.toLowerCase() === name.toLowerCase());
|
|
@@ -104,7 +100,6 @@ function isTupleReturnCall(context, node) {
|
|
|
104
100
|
const signature = context.checker.getResolvedSignature(node);
|
|
105
101
|
if (signature) {
|
|
106
102
|
if (getSignatureAnnotations(context, signature).has(AnnotationKind.TupleReturn)) {
|
|
107
|
-
context.diagnostics.push(diagnostics_1.annotationDeprecated(node, AnnotationKind.TupleReturn));
|
|
108
103
|
return true;
|
|
109
104
|
}
|
|
110
105
|
// Only check function type for directive if it is declared as an interface or type alias
|
|
@@ -117,41 +112,9 @@ function isTupleReturnCall(context, node) {
|
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
114
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
120
|
-
|
|
121
|
-
if (result) {
|
|
122
|
-
context.diagnostics.push(diagnostics_1.annotationDeprecated(node, AnnotationKind.TupleReturn));
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
115
|
+
return getTypeAnnotations(type).has(AnnotationKind.TupleReturn);
|
|
125
116
|
}
|
|
126
117
|
exports.isTupleReturnCall = isTupleReturnCall;
|
|
127
|
-
function isInTupleReturnFunction(context, node) {
|
|
128
|
-
const declaration = typescript_1.findFirstNodeAbove(node, ts.isFunctionLike);
|
|
129
|
-
if (!declaration) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
let functionType;
|
|
133
|
-
if (ts.isFunctionExpression(declaration) || ts.isArrowFunction(declaration)) {
|
|
134
|
-
functionType = typescript_1.inferAssignedType(context, declaration);
|
|
135
|
-
}
|
|
136
|
-
else if (ts.isMethodDeclaration(declaration) && ts.isObjectLiteralExpression(declaration.parent)) {
|
|
137
|
-
// Manually lookup type for object literal properties declared with method syntax
|
|
138
|
-
const interfaceType = typescript_1.inferAssignedType(context, declaration.parent);
|
|
139
|
-
const propertySymbol = interfaceType.getProperty(declaration.name.getText());
|
|
140
|
-
if (propertySymbol) {
|
|
141
|
-
functionType = context.checker.getTypeOfSymbolAtLocation(propertySymbol, declaration);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (functionType === undefined) {
|
|
145
|
-
functionType = context.checker.getTypeAtLocation(declaration);
|
|
146
|
-
}
|
|
147
|
-
// Check all overloads for directive
|
|
148
|
-
const signatures = functionType.getCallSignatures();
|
|
149
|
-
if (signatures === null || signatures === void 0 ? void 0 : signatures.some(s => getSignatureAnnotations(context, s).has(AnnotationKind.TupleReturn))) {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
return getTypeAnnotations(functionType).has(AnnotationKind.TupleReturn);
|
|
153
|
-
}
|
|
154
|
-
exports.isInTupleReturnFunction = isInTupleReturnFunction;
|
|
155
118
|
function isLuaIteratorType(context, node) {
|
|
156
119
|
const type = context.checker.getTypeAtLocation(node);
|
|
157
120
|
return getTypeAnnotations(type).has(AnnotationKind.LuaIterator);
|
|
@@ -16,7 +16,7 @@ function validateAssignment(context, node, fromType, toType, toName) {
|
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
// Use cache to avoid repeating check for same types (protects against infinite loop in recursive types)
|
|
19
|
-
const fromTypeCache = utils_1.getOrUpdate(typeValidationCache, fromType, () => new Set());
|
|
19
|
+
const fromTypeCache = (0, utils_1.getOrUpdate)(typeValidationCache, fromType, () => new Set());
|
|
20
20
|
if (fromTypeCache.has(toType))
|
|
21
21
|
return;
|
|
22
22
|
fromTypeCache.add(toType);
|
|
@@ -40,7 +40,8 @@ function validateAssignment(context, node, fromType, toType, toName) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
if ((toType.flags & ts.TypeFlags.Object) !== 0 &&
|
|
43
|
-
(
|
|
43
|
+
(ts.isTypeLiteralNode(toTypeNode) ||
|
|
44
|
+
(toType.objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0) &&
|
|
44
45
|
toType.symbol &&
|
|
45
46
|
toType.symbol.members &&
|
|
46
47
|
fromType.symbol &&
|
|
@@ -61,15 +62,15 @@ function validateAssignment(context, node, fromType, toType, toName) {
|
|
|
61
62
|
}
|
|
62
63
|
exports.validateAssignment = validateAssignment;
|
|
63
64
|
function validateFunctionAssignment(context, node, fromType, toType, toName) {
|
|
64
|
-
const fromContext = function_context_1.getFunctionContextType(context, fromType);
|
|
65
|
-
const toContext = function_context_1.getFunctionContextType(context, toType);
|
|
65
|
+
const fromContext = (0, function_context_1.getFunctionContextType)(context, fromType);
|
|
66
|
+
const toContext = (0, function_context_1.getFunctionContextType)(context, toType);
|
|
66
67
|
if (fromContext === function_context_1.ContextType.Mixed || toContext === function_context_1.ContextType.Mixed) {
|
|
67
|
-
context.diagnostics.push(diagnostics_1.unsupportedOverloadAssignment(node, toName));
|
|
68
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedOverloadAssignment)(node, toName));
|
|
68
69
|
}
|
|
69
70
|
else if (fromContext !== toContext && fromContext !== function_context_1.ContextType.None && toContext !== function_context_1.ContextType.None) {
|
|
70
71
|
context.diagnostics.push(toContext === function_context_1.ContextType.Void
|
|
71
|
-
? diagnostics_1.unsupportedNoSelfFunctionConversion(node, toName)
|
|
72
|
-
: diagnostics_1.unsupportedSelfFunctionConversion(node, toName));
|
|
72
|
+
? (0, diagnostics_1.unsupportedNoSelfFunctionConversion)(node, toName)
|
|
73
|
+
: (0, diagnostics_1.unsupportedSelfFunctionConversion)(node, toName));
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
//# sourceMappingURL=assignment-validation.js.map
|
|
@@ -88,3 +88,6 @@ export declare const annotationDeprecated: ((node: ts.Node, kind: AnnotationKind
|
|
|
88
88
|
export declare const notAllowedOptionalAssignment: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
89
89
|
code: number;
|
|
90
90
|
};
|
|
91
|
+
export declare const awaitMustBeInAsyncFunction: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
92
|
+
code: number;
|
|
93
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableSetExpression = exports.invalidTableDeleteExpression = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
3
|
+
exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableSetExpression = exports.invalidTableDeleteExpression = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
-
const createDiagnosticFactory = (category, message) => utils_1.createSerialDiagnosticFactory((node, ...args) => ({
|
|
8
|
-
file: node.getSourceFile(),
|
|
9
|
-
start: node.getStart(),
|
|
10
|
-
length: node.getWidth(),
|
|
7
|
+
const createDiagnosticFactory = (category, message) => (0, utils_1.createSerialDiagnosticFactory)((node, ...args) => ({
|
|
8
|
+
file: ts.getOriginalNode(node).getSourceFile(),
|
|
9
|
+
start: ts.getOriginalNode(node).getStart(),
|
|
10
|
+
length: ts.getOriginalNode(node).getWidth(),
|
|
11
11
|
messageText: typeof message === "string" ? message : message(...args),
|
|
12
12
|
category,
|
|
13
13
|
}));
|
|
@@ -57,4 +57,5 @@ exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' h
|
|
|
57
57
|
exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
|
|
58
58
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
59
59
|
exports.notAllowedOptionalAssignment = createErrorDiagnosticFactory("The left-hand side of an assignment expression may not be an optional property access.");
|
|
60
|
+
exports.awaitMustBeInAsyncFunction = createErrorDiagnosticFactory("Await can only be used inside async functions.");
|
|
60
61
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -2,8 +2,8 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function hasDefaultExportModifier(node: ts.Node): boolean;
|
|
5
|
-
export declare
|
|
6
|
-
export declare const createDefaultExportStringLiteral: (original
|
|
5
|
+
export declare function hasExportModifier(node: ts.Node): boolean;
|
|
6
|
+
export declare const createDefaultExportStringLiteral: (original?: ts.Node | undefined) => lua.StringLiteral;
|
|
7
7
|
export declare function getExportedSymbolDeclaration(symbol: ts.Symbol): ts.Declaration | undefined;
|
|
8
8
|
export declare function getSymbolFromIdentifier(context: TransformationContext, identifier: lua.Identifier): ts.Symbol | undefined;
|
|
9
9
|
export declare function getIdentifierExportScope(context: TransformationContext, identifier: lua.Identifier): ts.SourceFile | ts.ModuleDeclaration | undefined;
|
|
@@ -14,3 +14,4 @@ export declare function isSymbolExported(context: TransformationContext, symbol:
|
|
|
14
14
|
export declare function isSymbolExportedFromScope(context: TransformationContext, symbol: ts.Symbol, scope: ts.SourceFile | ts.ModuleDeclaration): boolean;
|
|
15
15
|
export declare function addExportToIdentifier(context: TransformationContext, identifier: lua.Identifier): lua.AssignmentLeftHandSideExpression;
|
|
16
16
|
export declare function createExportedIdentifier(context: TransformationContext, identifier: lua.Identifier, exportScope?: ts.SourceFile | ts.ModuleDeclaration): lua.AssignmentLeftHandSideExpression;
|
|
17
|
+
export declare function createDefaultExportExpression(node: ts.Node): lua.AssignmentLeftHandSideExpression;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createExportedIdentifier = exports.addExportToIdentifier = exports.isSymbolExportedFromScope = exports.isSymbolExported = exports.getDependenciesOfSymbol = exports.getExportedSymbolsFromScope = exports.getSymbolExportScope = exports.getIdentifierExportScope = exports.getSymbolFromIdentifier = exports.getExportedSymbolDeclaration = exports.createDefaultExportStringLiteral = exports.
|
|
3
|
+
exports.createDefaultExportExpression = exports.createExportedIdentifier = exports.addExportToIdentifier = exports.isSymbolExportedFromScope = exports.isSymbolExported = exports.getDependenciesOfSymbol = exports.getExportedSymbolsFromScope = exports.getSymbolExportScope = exports.getIdentifierExportScope = exports.getSymbolFromIdentifier = exports.getExportedSymbolDeclaration = exports.createDefaultExportStringLiteral = exports.hasExportModifier = exports.hasDefaultExportModifier = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const namespace_1 = require("../visitors/namespace");
|
|
@@ -12,8 +12,11 @@ function hasDefaultExportModifier(node) {
|
|
|
12
12
|
return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
13
13
|
}
|
|
14
14
|
exports.hasDefaultExportModifier = hasDefaultExportModifier;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function hasExportModifier(node) {
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
18
|
+
}
|
|
19
|
+
exports.hasExportModifier = hasExportModifier;
|
|
17
20
|
const createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
|
|
18
21
|
exports.createDefaultExportStringLiteral = createDefaultExportStringLiteral;
|
|
19
22
|
function getExportedSymbolDeclaration(symbol) {
|
|
@@ -25,7 +28,7 @@ function getExportedSymbolDeclaration(symbol) {
|
|
|
25
28
|
exports.getExportedSymbolDeclaration = getExportedSymbolDeclaration;
|
|
26
29
|
function getSymbolFromIdentifier(context, identifier) {
|
|
27
30
|
if (identifier.symbolId !== undefined) {
|
|
28
|
-
const symbolInfo = symbols_1.getSymbolInfo(context, identifier.symbolId);
|
|
31
|
+
const symbolInfo = (0, symbols_1.getSymbolInfo)(context, identifier.symbolId);
|
|
29
32
|
if (symbolInfo !== undefined) {
|
|
30
33
|
return symbolInfo.symbol;
|
|
31
34
|
}
|
|
@@ -48,7 +51,7 @@ function getSymbolExportScope(context, symbol) {
|
|
|
48
51
|
if (!exportedDeclaration) {
|
|
49
52
|
return undefined;
|
|
50
53
|
}
|
|
51
|
-
const scope = typescript_1.findFirstNodeAbove(exportedDeclaration, (n) => ts.isSourceFile(n) || ts.isModuleDeclaration(n));
|
|
54
|
+
const scope = (0, typescript_1.findFirstNodeAbove)(exportedDeclaration, (n) => ts.isSourceFile(n) || ts.isModuleDeclaration(n));
|
|
52
55
|
if (!scope) {
|
|
53
56
|
return undefined;
|
|
54
57
|
}
|
|
@@ -98,9 +101,13 @@ function createExportedIdentifier(context, identifier, exportScope) {
|
|
|
98
101
|
return identifier;
|
|
99
102
|
}
|
|
100
103
|
const exportTable = exportScope && ts.isModuleDeclaration(exportScope)
|
|
101
|
-
? namespace_1.createModuleLocalNameIdentifier(context, exportScope)
|
|
102
|
-
: lua_ast_1.createExportsIdentifier();
|
|
104
|
+
? (0, namespace_1.createModuleLocalNameIdentifier)(context, exportScope)
|
|
105
|
+
: (0, lua_ast_1.createExportsIdentifier)();
|
|
103
106
|
return lua.createTableIndexExpression(exportTable, lua.createStringLiteral(identifier.text));
|
|
104
107
|
}
|
|
105
108
|
exports.createExportedIdentifier = createExportedIdentifier;
|
|
109
|
+
function createDefaultExportExpression(node) {
|
|
110
|
+
return lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, exports.createDefaultExportStringLiteral)(node), node);
|
|
111
|
+
}
|
|
112
|
+
exports.createDefaultExportExpression = createDefaultExportExpression;
|
|
106
113
|
//# sourceMappingURL=export.js.map
|
|
@@ -12,14 +12,14 @@ var ContextType;
|
|
|
12
12
|
ContextType[ContextType["Mixed"] = 3] = "Mixed";
|
|
13
13
|
})(ContextType = exports.ContextType || (exports.ContextType = {}));
|
|
14
14
|
function hasNoSelfAncestor(declaration) {
|
|
15
|
-
const scopeDeclaration = typescript_1.findFirstNodeAbove(declaration, (node) => ts.isSourceFile(node) || ts.isModuleDeclaration(node));
|
|
15
|
+
const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(declaration, (node) => ts.isSourceFile(node) || ts.isModuleDeclaration(node));
|
|
16
16
|
if (!scopeDeclaration) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
else if (ts.isSourceFile(scopeDeclaration)) {
|
|
20
|
-
return annotations_1.getFileAnnotations(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelfInFile);
|
|
20
|
+
return (0, annotations_1.getFileAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelfInFile);
|
|
21
21
|
}
|
|
22
|
-
else if (annotations_1.getNodeAnnotations(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
22
|
+
else if ((0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
@@ -38,7 +38,7 @@ function getDeclarationContextType({ program }, signatureDeclaration) {
|
|
|
38
38
|
: ContextType.NonVoid;
|
|
39
39
|
}
|
|
40
40
|
// noSelf declaration on function signature
|
|
41
|
-
if (annotations_1.getNodeAnnotations(signatureDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
41
|
+
if ((0, annotations_1.getNodeAnnotations)(signatureDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
42
42
|
return ContextType.Void;
|
|
43
43
|
}
|
|
44
44
|
if (ts.isMethodSignature(signatureDeclaration) ||
|
|
@@ -48,11 +48,11 @@ function getDeclarationContextType({ program }, signatureDeclaration) {
|
|
|
48
48
|
(signatureDeclaration.parent && ts.isPropertyDeclaration(signatureDeclaration.parent)) ||
|
|
49
49
|
(signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent))) {
|
|
50
50
|
// Class/interface methods only respect @noSelf on their parent
|
|
51
|
-
const scopeDeclaration = typescript_1.findFirstNodeAbove(signatureDeclaration, (n) => ts.isClassDeclaration(n) || ts.isClassExpression(n) || ts.isInterfaceDeclaration(n));
|
|
51
|
+
const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(signatureDeclaration, (n) => ts.isClassDeclaration(n) || ts.isClassExpression(n) || ts.isInterfaceDeclaration(n));
|
|
52
52
|
if (scopeDeclaration === undefined) {
|
|
53
53
|
return ContextType.NonVoid;
|
|
54
54
|
}
|
|
55
|
-
if (annotations_1.getNodeAnnotations(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
55
|
+
if ((0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
56
56
|
return ContextType.Void;
|
|
57
57
|
}
|
|
58
58
|
return ContextType.NonVoid;
|
|
@@ -89,15 +89,21 @@ function reduceContextTypes(contexts) {
|
|
|
89
89
|
function getSignatureDeclarations(context, signatures) {
|
|
90
90
|
return signatures.flatMap(signature => {
|
|
91
91
|
const signatureDeclaration = signature.getDeclaration();
|
|
92
|
-
|
|
92
|
+
let inferredType;
|
|
93
|
+
if (ts.isMethodDeclaration(signatureDeclaration) &&
|
|
94
|
+
ts.isObjectLiteralExpression(signatureDeclaration.parent) &&
|
|
95
|
+
!getExplicitThisParameter(signatureDeclaration)) {
|
|
96
|
+
inferredType = context.checker.getContextualTypeForObjectLiteralElement(signatureDeclaration);
|
|
97
|
+
}
|
|
98
|
+
else if ((ts.isFunctionExpression(signatureDeclaration) || ts.isArrowFunction(signatureDeclaration)) &&
|
|
93
99
|
!getExplicitThisParameter(signatureDeclaration)) {
|
|
94
100
|
// Infer type of function expressions/arrow functions
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
inferredType = (0, typescript_1.inferAssignedType)(context, signatureDeclaration);
|
|
102
|
+
}
|
|
103
|
+
if (inferredType) {
|
|
104
|
+
const inferredSignatures = (0, typescript_1.getAllCallSignatures)(inferredType);
|
|
105
|
+
if (inferredSignatures.length > 0) {
|
|
106
|
+
return inferredSignatures.map(s => s.getDeclaration());
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
return signatureDeclaration;
|