typescript-to-lua 1.4.2 → 1.5.0
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/dist/CompilerOptions.d.ts +5 -1
- package/dist/LuaAST.d.ts +9 -7
- package/dist/LuaAST.js +19 -13
- package/dist/LuaLib.d.ts +1 -2
- package/dist/LuaLib.js +1 -2
- package/dist/LuaPrinter.js +1 -2
- package/dist/cli/parse.js +10 -0
- package/dist/lualib/ArrayConcat.lua +16 -12
- package/dist/lualib/ArrayEvery.lua +4 -8
- package/dist/lualib/ArrayFilter.lua +6 -8
- package/dist/lualib/ArrayFind.lua +4 -7
- package/dist/lualib/ArrayFindIndex.lua +4 -9
- package/dist/lualib/ArrayFlat.lua +17 -7
- package/dist/lualib/ArrayFlatMap.lua +11 -10
- package/dist/lualib/ArrayForEach.lua +3 -7
- package/dist/lualib/ArrayFrom.lua +2 -5
- package/dist/lualib/ArrayIncludes.lua +2 -2
- package/dist/lualib/ArrayIndexOf.lua +13 -21
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayJoin.lua +4 -7
- package/dist/lualib/ArrayMap.lua +5 -9
- package/dist/lualib/ArrayPush.lua +6 -4
- package/dist/lualib/ArrayPushArray.lua +8 -0
- package/dist/lualib/ArrayReduce.lua +8 -8
- package/dist/lualib/ArrayReduceRight.lua +8 -8
- package/dist/lualib/ArrayReverse.lua +7 -7
- package/dist/lualib/ArraySetLength.lua +3 -7
- package/dist/lualib/ArraySlice.lua +26 -19
- package/dist/lualib/ArraySome.lua +4 -8
- package/dist/lualib/ArraySort.lua +4 -4
- package/dist/lualib/ArraySplice.lua +47 -58
- package/dist/lualib/ArrayToObject.lua +3 -7
- package/dist/lualib/ArrayUnshift.lua +11 -8
- package/dist/lualib/Await.lua +21 -34
- package/dist/lualib/FunctionBind.lua +5 -11
- package/dist/lualib/ObjectAssign.lua +5 -7
- package/dist/lualib/ObjectEntries.lua +3 -1
- package/dist/lualib/ObjectKeys.lua +3 -1
- package/dist/lualib/ObjectValues.lua +3 -1
- package/dist/lualib/Promise.lua +8 -7
- package/dist/lualib/PromiseAny.lua +3 -3
- package/dist/lualib/PromiseRace.lua +1 -1
- package/dist/lualib/SourceMapTraceBack.lua +14 -1
- package/dist/lualib/Spread.lua +5 -7
- package/dist/lualib/StringReplace.lua +17 -14
- package/dist/lualib/StringReplaceAll.lua +36 -29
- package/dist/lualib/StringSplit.lua +32 -32
- package/dist/lualib/lualib_bundle.lua +393 -423
- package/dist/lualib/lualib_module_info.json +13 -23
- package/dist/transformation/builtins/array.d.ts +2 -3
- package/dist/transformation/builtins/array.js +43 -12
- package/dist/transformation/builtins/console.d.ts +2 -2
- package/dist/transformation/builtins/console.js +8 -9
- package/dist/transformation/builtins/function.d.ts +1 -2
- package/dist/transformation/builtins/function.js +5 -6
- package/dist/transformation/builtins/index.js +22 -23
- package/dist/transformation/builtins/math.d.ts +1 -2
- package/dist/transformation/builtins/math.js +3 -4
- package/dist/transformation/builtins/number.d.ts +3 -3
- package/dist/transformation/builtins/number.js +10 -12
- package/dist/transformation/builtins/object.d.ts +2 -3
- package/dist/transformation/builtins/object.js +16 -17
- package/dist/transformation/builtins/promise.d.ts +2 -2
- package/dist/transformation/builtins/promise.js +7 -7
- package/dist/transformation/builtins/string.d.ts +2 -3
- package/dist/transformation/builtins/string.js +8 -10
- package/dist/transformation/builtins/symbol.d.ts +2 -2
- package/dist/transformation/builtins/symbol.js +6 -7
- package/dist/transformation/utils/diagnostics.d.ts +7 -2
- package/dist/transformation/utils/diagnostics.js +4 -1
- package/dist/transformation/utils/lua-ast.d.ts +1 -0
- package/dist/transformation/utils/lua-ast.js +89 -3
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +9 -1
- package/dist/transformation/visitors/async-await.d.ts +1 -1
- package/dist/transformation/visitors/async-await.js +7 -14
- package/dist/transformation/visitors/call.d.ts +1 -3
- package/dist/transformation/visitors/call.js +26 -13
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/class/members/accessors.js +1 -1
- package/dist/transformation/visitors/class/members/constructor.js +1 -1
- package/dist/transformation/visitors/errors.js +52 -9
- package/dist/transformation/visitors/function.js +5 -5
- package/dist/transformation/visitors/modules/import.d.ts +1 -0
- package/dist/transformation/visitors/modules/import.js +9 -1
- package/dist/transformation/visitors/return.js +5 -4
- package/dist/transformation/visitors/spread.js +1 -7
- package/package.json +1 -1
- package/dist/lualib/ArrayShift.lua +0 -3
- package/dist/lualib/StringConcat.lua +0 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformPromiseConstructorCall = exports.createPromiseIdentifier = exports.isPromiseClass = void 0;
|
|
3
|
+
exports.createStaticPromiseFunctionAccessor = exports.transformPromiseConstructorCall = exports.createPromiseIdentifier = exports.isPromiseClass = void 0;
|
|
4
4
|
const lua = require("../../LuaAST");
|
|
5
5
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
6
|
const lualib_1 = require("../utils/lualib");
|
|
@@ -15,11 +15,10 @@ function createPromiseIdentifier(original) {
|
|
|
15
15
|
return lua.createIdentifier("__TS__Promise", original);
|
|
16
16
|
}
|
|
17
17
|
exports.createPromiseIdentifier = createPromiseIdentifier;
|
|
18
|
-
function transformPromiseConstructorCall(context, node) {
|
|
19
|
-
const expression = node.expression;
|
|
18
|
+
function transformPromiseConstructorCall(context, node, calledMethod) {
|
|
20
19
|
const signature = context.checker.getResolvedSignature(node);
|
|
21
20
|
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
22
|
-
const expressionName =
|
|
21
|
+
const expressionName = calledMethod.name.text;
|
|
23
22
|
switch (expressionName) {
|
|
24
23
|
case "all":
|
|
25
24
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.PromiseAll, node, ...params);
|
|
@@ -31,16 +30,17 @@ function transformPromiseConstructorCall(context, node) {
|
|
|
31
30
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.PromiseRace, node, ...params);
|
|
32
31
|
case "resolve":
|
|
33
32
|
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
34
|
-
return lua.createCallExpression(createStaticPromiseFunctionAccessor("resolve",
|
|
33
|
+
return lua.createCallExpression(createStaticPromiseFunctionAccessor("resolve", calledMethod), params, node);
|
|
35
34
|
case "reject":
|
|
36
35
|
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
37
|
-
return lua.createCallExpression(createStaticPromiseFunctionAccessor("reject",
|
|
36
|
+
return lua.createCallExpression(createStaticPromiseFunctionAccessor("reject", calledMethod), params, node);
|
|
38
37
|
default:
|
|
39
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(
|
|
38
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Promise", expressionName));
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
exports.transformPromiseConstructorCall = transformPromiseConstructorCall;
|
|
43
42
|
function createStaticPromiseFunctionAccessor(functionName, node) {
|
|
44
43
|
return lua.createTableIndexExpression(lua.createIdentifier("__TS__Promise"), lua.createStringLiteral(functionName), node);
|
|
45
44
|
}
|
|
45
|
+
exports.createStaticPromiseFunctionAccessor = createStaticPromiseFunctionAccessor;
|
|
46
46
|
//# sourceMappingURL=promise.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function transformStringConstructorCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
|
|
4
|
+
export declare function transformStringPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
|
+
export declare function transformStringConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
7
6
|
export declare function transformStringProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.UnaryExpression | undefined;
|
|
@@ -10,18 +10,17 @@ function createStringCall(methodName, tsOriginal, ...params) {
|
|
|
10
10
|
const stringIdentifier = lua.createIdentifier("string");
|
|
11
11
|
return lua.createCallExpression(lua.createTableIndexExpression(stringIdentifier, lua.createStringLiteral(methodName)), params, tsOriginal);
|
|
12
12
|
}
|
|
13
|
-
function transformStringPrototypeCall(context, node) {
|
|
14
|
-
const expression = node.expression;
|
|
13
|
+
function transformStringPrototypeCall(context, node, calledMethod) {
|
|
15
14
|
const signature = context.checker.getResolvedSignature(node);
|
|
16
|
-
const [caller, params] = (0, call_1.transformCallAndArguments)(context,
|
|
17
|
-
const expressionName =
|
|
15
|
+
const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
|
|
16
|
+
const expressionName = calledMethod.name.text;
|
|
18
17
|
switch (expressionName) {
|
|
19
18
|
case "replace":
|
|
20
19
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringReplace, node, caller, ...params);
|
|
21
20
|
case "replaceAll":
|
|
22
21
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringReplaceAll, node, caller, ...params);
|
|
23
22
|
case "concat":
|
|
24
|
-
return (
|
|
23
|
+
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("concat")), [(0, lua_ast_1.wrapInTable)(caller, ...params)], node);
|
|
25
24
|
case "indexOf": {
|
|
26
25
|
const stringExpression = createStringCall("find", node, caller, params[0], params[1]
|
|
27
26
|
? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
|
|
@@ -102,20 +101,19 @@ function transformStringPrototypeCall(context, node) {
|
|
|
102
101
|
case "padEnd":
|
|
103
102
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringPadEnd, node, caller, ...params);
|
|
104
103
|
default:
|
|
105
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(
|
|
104
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "string", expressionName));
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
exports.transformStringPrototypeCall = transformStringPrototypeCall;
|
|
109
|
-
function transformStringConstructorCall(context, node) {
|
|
110
|
-
const expression = node.expression;
|
|
108
|
+
function transformStringConstructorCall(context, node, calledMethod) {
|
|
111
109
|
const signature = context.checker.getResolvedSignature(node);
|
|
112
110
|
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
113
|
-
const expressionName =
|
|
111
|
+
const expressionName = calledMethod.name.text;
|
|
114
112
|
switch (expressionName) {
|
|
115
113
|
case "fromCharCode":
|
|
116
114
|
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("char")), params, node);
|
|
117
115
|
default:
|
|
118
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(
|
|
116
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "String", expressionName));
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
exports.transformStringConstructorCall = transformStringConstructorCall;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import ts = require("typescript");
|
|
1
2
|
import * as lua from "../../LuaAST";
|
|
2
3
|
import { TransformationContext } from "../context";
|
|
3
|
-
|
|
4
|
-
export declare function transformSymbolConstructorCall(context: TransformationContext, expression: PropertyCallExpression): lua.CallExpression | undefined;
|
|
4
|
+
export declare function transformSymbolConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined;
|
|
@@ -5,20 +5,19 @@ const lua = require("../../LuaAST");
|
|
|
5
5
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
6
|
const lualib_1 = require("../utils/lualib");
|
|
7
7
|
const call_1 = require("../visitors/call");
|
|
8
|
-
function transformSymbolConstructorCall(context,
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const methodName = method.name.text;
|
|
8
|
+
function transformSymbolConstructorCall(context, node, calledMethod) {
|
|
9
|
+
const signature = context.checker.getResolvedSignature(node);
|
|
10
|
+
const parameters = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
11
|
+
const methodName = calledMethod.name.text;
|
|
13
12
|
switch (methodName) {
|
|
14
13
|
case "for":
|
|
15
14
|
case "keyFor":
|
|
16
15
|
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.SymbolRegistry);
|
|
17
16
|
const upperMethodName = methodName[0].toUpperCase() + methodName.slice(1);
|
|
18
17
|
const functionIdentifier = lua.createIdentifier(`__TS__SymbolRegistry${upperMethodName}`);
|
|
19
|
-
return lua.createCallExpression(functionIdentifier, parameters,
|
|
18
|
+
return lua.createCallExpression(functionIdentifier, parameters, node);
|
|
20
19
|
default:
|
|
21
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(
|
|
20
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Symbol", methodName));
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
exports.transformSymbolConstructorCall = transformSymbolConstructorCall;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import { LuaTarget } from "../../CompilerOptions";
|
|
2
|
+
import { LuaTarget, TypeScriptToLuaOptions } from "../../CompilerOptions";
|
|
3
3
|
import { AnnotationKind } from "./annotations";
|
|
4
4
|
export declare const unsupportedNodeKind: ((node: ts.Node, kind: ts.SyntaxKind) => ts.Diagnostic) & {
|
|
5
5
|
code: number;
|
|
@@ -43,7 +43,11 @@ export declare const unsupportedAccessorInObjectLiteral: ((node: ts.Node, ...arg
|
|
|
43
43
|
export declare const unsupportedRightShiftOperator: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
44
44
|
code: number;
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
declare type NonUniversalTarget = Exclude<LuaTarget, LuaTarget.Universal>;
|
|
47
|
+
export declare const unsupportedForTarget: ((node: ts.Node, functionality: string, version: NonUniversalTarget) => ts.Diagnostic) & {
|
|
48
|
+
code: number;
|
|
49
|
+
};
|
|
50
|
+
export declare const unsupportedForTargetButOverrideAvailable: ((node: ts.Node, functionality: string, version: NonUniversalTarget, optionName: keyof TypeScriptToLuaOptions) => ts.Diagnostic) & {
|
|
47
51
|
code: number;
|
|
48
52
|
};
|
|
49
53
|
export declare const unsupportedProperty: ((node: ts.Node, parentName: string, property: string) => ts.Diagnostic) & {
|
|
@@ -97,3 +101,4 @@ export declare const unsupportedOptionalCompileMembersOnly: ((node: ts.Node, ...
|
|
|
97
101
|
export declare const undefinedInArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
98
102
|
code: number;
|
|
99
103
|
};
|
|
104
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = 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.invalidPairsIterableWithoutDestructuring = 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.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = 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");
|
|
@@ -41,6 +41,9 @@ exports.unsupportedAccessorInObjectLiteral = createErrorDiagnosticFactory("Acces
|
|
|
41
41
|
exports.unsupportedRightShiftOperator = createErrorDiagnosticFactory("Right shift operator is not supported for target Lua 5.3. Use `>>>` instead.");
|
|
42
42
|
const getLuaTargetName = (version) => (version === CompilerOptions_1.LuaTarget.LuaJIT ? "LuaJIT" : `Lua ${version}`);
|
|
43
43
|
exports.unsupportedForTarget = createErrorDiagnosticFactory((functionality, version) => `${functionality} is/are not supported for target ${getLuaTargetName(version)}.`);
|
|
44
|
+
exports.unsupportedForTargetButOverrideAvailable = createErrorDiagnosticFactory((functionality, version, optionName) => `As a precaution, ${functionality} is/are not supported for target ${getLuaTargetName(version)} due to language features/limitations. ` +
|
|
45
|
+
`However "--${optionName}" can be used to bypass this precaution. ` +
|
|
46
|
+
"See https://typescripttolua.github.io/docs/configuration for more information.");
|
|
44
47
|
exports.unsupportedProperty = createErrorDiagnosticFactory((parentName, property) => `${parentName}.${property} is unsupported.`);
|
|
45
48
|
exports.invalidAmbientIdentifierName = createErrorDiagnosticFactory((text) => `Invalid ambient identifier name '${text}'. Ambient identifiers must be valid lua identifiers.`);
|
|
46
49
|
exports.unsupportedVarDeclaration = createErrorDiagnosticFactory("`var` declarations are not supported. Use `let` or `const` instead.");
|
|
@@ -8,6 +8,7 @@ export declare function createExportsIdentifier(): lua.Identifier;
|
|
|
8
8
|
export declare function addToNumericExpression(expression: lua.Expression, change: number): lua.Expression;
|
|
9
9
|
export declare function getNumberLiteralValue(expression?: lua.Expression): number | undefined;
|
|
10
10
|
export declare function createUnpackCall(context: TransformationContext, expression: lua.Expression, tsOriginal?: ts.Node): lua.Expression;
|
|
11
|
+
export declare function isUnpackCall(node: lua.Node): boolean;
|
|
11
12
|
export declare function wrapInTable(...expressions: lua.Expression[]): lua.TableExpression;
|
|
12
13
|
export declare function wrapInToStringForConcat(expression: lua.Expression): lua.Expression;
|
|
13
14
|
export declare function createHoistableVariableDeclarationStatement(context: TransformationContext, identifier: lua.Identifier, initializer?: lua.Expression, tsOriginal?: ts.Node): lua.AssignmentStatement | lua.VariableDeclarationStatement;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNaN = exports.createLocalOrExportedOrGlobalDeclaration = exports.createHoistableVariableDeclarationStatement = exports.wrapInToStringForConcat = exports.wrapInTable = exports.createUnpackCall = exports.getNumberLiteralValue = exports.addToNumericExpression = exports.createExportsIdentifier = exports.createSelfIdentifier = exports.unwrapVisitorResult = void 0;
|
|
3
|
+
exports.createNaN = exports.createLocalOrExportedOrGlobalDeclaration = exports.createHoistableVariableDeclarationStatement = exports.wrapInToStringForConcat = exports.wrapInTable = exports.isUnpackCall = exports.createUnpackCall = exports.getNumberLiteralValue = exports.addToNumericExpression = exports.createExportsIdentifier = exports.createSelfIdentifier = exports.unwrapVisitorResult = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const lua = require("../../LuaAST");
|
|
@@ -62,9 +62,13 @@ function createUnpackCall(context, expression, tsOriginal) {
|
|
|
62
62
|
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 || context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT
|
|
63
63
|
? lua.createIdentifier("unpack")
|
|
64
64
|
: lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("unpack"));
|
|
65
|
-
return lua.createCallExpression(unpack, [expression], tsOriginal);
|
|
65
|
+
return lua.setNodeFlags(lua.createCallExpression(unpack, [expression], tsOriginal), lua.NodeFlags.TableUnpackCall);
|
|
66
66
|
}
|
|
67
67
|
exports.createUnpackCall = createUnpackCall;
|
|
68
|
+
function isUnpackCall(node) {
|
|
69
|
+
return lua.isCallExpression(node) && (node.flags & lua.NodeFlags.TableUnpackCall) !== 0;
|
|
70
|
+
}
|
|
71
|
+
exports.isUnpackCall = isUnpackCall;
|
|
68
72
|
function wrapInTable(...expressions) {
|
|
69
73
|
const fields = expressions.map(e => lua.createTableFieldExpression(e));
|
|
70
74
|
return lua.createTableExpression(fields);
|
|
@@ -100,6 +104,7 @@ function hasMultipleReferences(scope, identifiers) {
|
|
|
100
104
|
function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal, overrideExportScope) {
|
|
101
105
|
let declaration;
|
|
102
106
|
let assignment;
|
|
107
|
+
const noImplicitGlobalVariables = context.options.noImplicitGlobalVariables === true;
|
|
103
108
|
const isFunctionDeclaration = tsOriginal !== undefined && ts.isFunctionDeclaration(tsOriginal);
|
|
104
109
|
const identifiers = (0, utils_1.castArray)(lhs);
|
|
105
110
|
if (identifiers.length === 0) {
|
|
@@ -118,7 +123,7 @@ function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal,
|
|
|
118
123
|
else {
|
|
119
124
|
const scope = (0, scope_1.peekScope)(context);
|
|
120
125
|
const isTopLevelVariable = scope.type === scope_1.ScopeType.File;
|
|
121
|
-
if (context.isModule || !isTopLevelVariable) {
|
|
126
|
+
if (context.isModule || !isTopLevelVariable || noImplicitGlobalVariables) {
|
|
122
127
|
const isLuaFunctionExpression = rhs && !Array.isArray(rhs) && lua.isFunctionExpression(rhs);
|
|
123
128
|
const isSafeRecursiveFunctionDeclaration = isFunctionDeclaration && isLuaFunctionExpression;
|
|
124
129
|
if (!isSafeRecursiveFunctionDeclaration && hasMultipleReferences(scope, lhs)) {
|
|
@@ -159,6 +164,7 @@ function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal,
|
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
166
|
}
|
|
167
|
+
setJSDocComments(context, tsOriginal, declaration, assignment);
|
|
162
168
|
if (declaration && assignment) {
|
|
163
169
|
return [declaration, assignment];
|
|
164
170
|
}
|
|
@@ -173,6 +179,86 @@ function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal,
|
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
181
|
exports.createLocalOrExportedOrGlobalDeclaration = createLocalOrExportedOrGlobalDeclaration;
|
|
182
|
+
/**
|
|
183
|
+
* Apply JSDoc comments to the newly-created Lua statement, if present.
|
|
184
|
+
* https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
|
|
185
|
+
*/
|
|
186
|
+
function setJSDocComments(context, tsOriginal, declaration, assignment) {
|
|
187
|
+
// Respect the vanilla TypeScript option of "removeComments":
|
|
188
|
+
// https://www.typescriptlang.org/tsconfig#removeComments
|
|
189
|
+
if (context.options.removeComments) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const docCommentArray = getJSDocCommentFromTSNode(context, tsOriginal);
|
|
193
|
+
if (docCommentArray === undefined) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (declaration && assignment) {
|
|
197
|
+
declaration.leadingComments = docCommentArray;
|
|
198
|
+
}
|
|
199
|
+
else if (declaration) {
|
|
200
|
+
declaration.leadingComments = docCommentArray;
|
|
201
|
+
}
|
|
202
|
+
else if (assignment) {
|
|
203
|
+
assignment.leadingComments = docCommentArray;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function getJSDocCommentFromTSNode(context, tsOriginal) {
|
|
207
|
+
if (tsOriginal === undefined) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
// The "name" property is only on a subset of node types; we want to be permissive and get the
|
|
211
|
+
// comments from as many nodes as possible.
|
|
212
|
+
const node = tsOriginal;
|
|
213
|
+
if (node.name === undefined) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const symbol = context.checker.getSymbolAtLocation(node.name);
|
|
217
|
+
if (symbol === undefined) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
// The TypeScript compiler separates JSDoc comments into the "documentation comment" and the
|
|
221
|
+
// "tags". The former is conventionally at the top of the comment, and the bottom is
|
|
222
|
+
// conventionally at the bottom. We need to get both from the TypeScript API and then combine
|
|
223
|
+
// them into one block of text.
|
|
224
|
+
const docCommentArray = symbol.getDocumentationComment(context.checker);
|
|
225
|
+
const docCommentText = ts.displayPartsToString(docCommentArray).trim();
|
|
226
|
+
const jsDocTagInfoArray = symbol.getJsDocTags(context.checker);
|
|
227
|
+
const jsDocTagsTextLines = jsDocTagInfoArray.map(jsDocTagInfo => {
|
|
228
|
+
let text = "@" + jsDocTagInfo.name;
|
|
229
|
+
if (jsDocTagInfo.text !== undefined) {
|
|
230
|
+
const tagDescriptionTextArray = jsDocTagInfo.text
|
|
231
|
+
.filter(symbolDisplayPart => symbolDisplayPart.text.trim() !== "")
|
|
232
|
+
.map(symbolDisplayPart => symbolDisplayPart.text.trim());
|
|
233
|
+
const tagDescriptionText = tagDescriptionTextArray.join(" ");
|
|
234
|
+
text += " " + tagDescriptionText;
|
|
235
|
+
}
|
|
236
|
+
return text;
|
|
237
|
+
});
|
|
238
|
+
const jsDocTagsText = jsDocTagsTextLines.join("\n");
|
|
239
|
+
const combined = (docCommentText + "\n\n" + jsDocTagsText).trim();
|
|
240
|
+
if (combined === "") {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
// By default, TSTL will display comments immediately next to the "--" characters. We can make
|
|
244
|
+
// the comments look better if we separate them by a space (similar to what Prettier does in
|
|
245
|
+
// JavaScript/TypeScript).
|
|
246
|
+
const linesWithoutSpace = combined.split("\n");
|
|
247
|
+
const lines = linesWithoutSpace.map(line => ` ${line}`);
|
|
248
|
+
// We want to JSDoc comments to map on to LDoc comments:
|
|
249
|
+
// https://stevedonovan.github.io/ldoc/manual/doc.md.html
|
|
250
|
+
// LDoc comments require that the first line starts with three hyphens.
|
|
251
|
+
// Thus, need to add a hyphen to the first line.
|
|
252
|
+
const firstLine = lines[0];
|
|
253
|
+
if (firstLine.startsWith(" @")) {
|
|
254
|
+
lines.unshift("-");
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
lines.shift();
|
|
258
|
+
lines.unshift("-" + firstLine);
|
|
259
|
+
}
|
|
260
|
+
return lines;
|
|
261
|
+
}
|
|
176
262
|
const createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal);
|
|
177
263
|
exports.createNaN = createNaN;
|
|
178
264
|
//# sourceMappingURL=lua-ast.js.map
|
|
@@ -7,6 +7,7 @@ export declare function hasExportEquals(sourceFile: ts.SourceFile): boolean;
|
|
|
7
7
|
* Search up until finding a node satisfying the callback
|
|
8
8
|
*/
|
|
9
9
|
export declare function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined;
|
|
10
|
+
export declare function findFirstNonOuterParent(node: ts.Node): ts.Node;
|
|
10
11
|
export declare function getFirstDeclarationInFile(symbol: ts.Symbol, sourceFile: ts.SourceFile): ts.Declaration | undefined;
|
|
11
12
|
export declare function isStandardLibraryType(context: TransformationContext, type: ts.Type, name: string | undefined): boolean;
|
|
12
13
|
export declare function hasStandardLibrarySignature(context: TransformationContext, callExpression: ts.CallExpression): boolean;
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.isConstIdentifier = exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.getFirstDeclarationInFile = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
|
|
17
|
+
exports.isConstIdentifier = exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.getFirstDeclarationInFile = exports.findFirstNonOuterParent = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
|
|
18
18
|
const ts = require("typescript");
|
|
19
19
|
__exportStar(require("./nodes"), exports);
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
@@ -38,6 +38,14 @@ function findFirstNodeAbove(node, callback) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.findFirstNodeAbove = findFirstNodeAbove;
|
|
41
|
+
function findFirstNonOuterParent(node) {
|
|
42
|
+
let current = ts.getOriginalNode(node).parent;
|
|
43
|
+
while (ts.isOuterExpression(current)) {
|
|
44
|
+
current = ts.getOriginalNode(current).parent;
|
|
45
|
+
}
|
|
46
|
+
return current;
|
|
47
|
+
}
|
|
48
|
+
exports.findFirstNonOuterParent = findFirstNonOuterParent;
|
|
41
49
|
function getFirstDeclarationInFile(symbol, sourceFile) {
|
|
42
50
|
var _a, _b;
|
|
43
51
|
const originalSourceFile = (_a = ts.getParseTreeNode(sourceFile)) !== null && _a !== void 0 ? _a : sourceFile;
|
|
@@ -3,4 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
4
|
export declare const transformAwaitExpression: FunctionVisitor<ts.AwaitExpression>;
|
|
5
5
|
export declare function isAsyncFunction(declaration: ts.FunctionLikeDeclaration): boolean;
|
|
6
|
-
export declare function wrapInAsyncAwaiter(context: TransformationContext, statements: lua.Statement[]): lua.
|
|
6
|
+
export declare function wrapInAsyncAwaiter(context: TransformationContext, statements: lua.Statement[], includeResolveParameter?: boolean): lua.CallExpression;
|
|
@@ -7,16 +7,12 @@ const diagnostics_1 = require("../utils/diagnostics");
|
|
|
7
7
|
const lualib_1 = require("../utils/lualib");
|
|
8
8
|
const typescript_1 = require("../utils/typescript");
|
|
9
9
|
const transformAwaitExpression = (node, context) => {
|
|
10
|
-
var _a;
|
|
11
10
|
// Check if await is inside an async function, it is not allowed at top level or in non-async functions
|
|
12
|
-
|
|
13
|
-
if (containingFunction === undefined ||
|
|
14
|
-
!((_a = containingFunction.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword))) {
|
|
11
|
+
if (!(0, typescript_1.isInAsyncFunction)(node)) {
|
|
15
12
|
context.diagnostics.push((0, diagnostics_1.awaitMustBeInAsyncFunction)(node));
|
|
16
13
|
}
|
|
17
14
|
const expression = context.transformExpression(node.expression);
|
|
18
|
-
|
|
19
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Await, node, catchIdentifier, expression);
|
|
15
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Await, node, expression);
|
|
20
16
|
};
|
|
21
17
|
exports.transformAwaitExpression = transformAwaitExpression;
|
|
22
18
|
function isAsyncFunction(declaration) {
|
|
@@ -24,15 +20,12 @@ function isAsyncFunction(declaration) {
|
|
|
24
20
|
return (_b = (_a = declaration.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) !== null && _b !== void 0 ? _b : false;
|
|
25
21
|
}
|
|
26
22
|
exports.isAsyncFunction = isAsyncFunction;
|
|
27
|
-
function wrapInAsyncAwaiter(context, statements) {
|
|
23
|
+
function wrapInAsyncAwaiter(context, statements, includeResolveParameter = true) {
|
|
28
24
|
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Await);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]),
|
|
34
|
-
]),
|
|
35
|
-
];
|
|
25
|
+
const parameters = includeResolveParameter ? [lua.createIdentifier("____awaiter_resolve")] : [];
|
|
26
|
+
return lua.createCallExpression(lua.createIdentifier("__TS__AsyncAwaiter"), [
|
|
27
|
+
lua.createFunctionExpression(lua.createBlock(statements), parameters),
|
|
28
|
+
]);
|
|
36
29
|
}
|
|
37
30
|
exports.wrapInAsyncAwaiter = wrapInAsyncAwaiter;
|
|
38
31
|
//# sourceMappingURL=async-await.js.map
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
|
-
export declare type PropertyCallExpression = ts.CallExpression & {
|
|
5
|
-
expression: ts.PropertyAccessExpression;
|
|
6
|
-
};
|
|
7
4
|
export declare function validateArguments(context: TransformationContext, params: readonly ts.Expression[], signature?: ts.Signature): void;
|
|
8
5
|
export declare function transformArguments(context: TransformationContext, params: readonly ts.Expression[], signature?: ts.Signature, callContext?: ts.Expression): lua.Expression[];
|
|
9
6
|
export declare function transformCallAndArguments(context: TransformationContext, callExpression: ts.Expression, params: readonly ts.Expression[], signature?: ts.Signature, callContext?: ts.Expression): [lua.Expression, lua.Expression[]];
|
|
10
7
|
export declare function transformContextualCallExpression(context: TransformationContext, node: ts.CallExpression | ts.TaggedTemplateExpression, args: ts.Expression[] | ts.NodeArray<ts.Expression>, signature?: ts.Signature): lua.Expression;
|
|
11
8
|
export declare const transformCallExpression: FunctionVisitor<ts.CallExpression>;
|
|
9
|
+
export declare function getCalledExpression(node: ts.CallExpression): ts.Expression;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformCallExpression = exports.transformContextualCallExpression = exports.transformCallAndArguments = exports.transformArguments = exports.validateArguments = void 0;
|
|
3
|
+
exports.getCalledExpression = exports.transformCallExpression = exports.transformContextualCallExpression = exports.transformCallAndArguments = exports.transformArguments = exports.validateArguments = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const builtins_1 = require("../builtins");
|
|
@@ -17,6 +17,7 @@ const expression_list_1 = require("./expression-list");
|
|
|
17
17
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
18
18
|
const optional_chaining_1 = require("./optional-chaining");
|
|
19
19
|
const language_extensions_1 = require("./language-extensions");
|
|
20
|
+
const import_1 = require("./modules/import");
|
|
20
21
|
function validateArguments(context, params, signature) {
|
|
21
22
|
if (!signature || signature.parameters.length < params.length) {
|
|
22
23
|
return;
|
|
@@ -81,7 +82,7 @@ function transformContextualCallExpression(context, node, args, signature) {
|
|
|
81
82
|
if (ts.isOptionalChain(node)) {
|
|
82
83
|
return (0, optional_chaining_1.transformOptionalChain)(context, node);
|
|
83
84
|
}
|
|
84
|
-
const left = ts.isCallExpression(node) ? node
|
|
85
|
+
const left = ts.isCallExpression(node) ? getCalledExpression(node) : node.tag;
|
|
85
86
|
let [argPrecedingStatements, transformedArguments] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => transformArguments(context, args, signature));
|
|
86
87
|
if (ts.isPropertyAccessExpression(left) &&
|
|
87
88
|
ts.isIdentifier(left.name) &&
|
|
@@ -112,9 +113,9 @@ function transformContextualCallExpression(context, node, args, signature) {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
exports.transformContextualCallExpression = transformContextualCallExpression;
|
|
115
|
-
function transformPropertyCall(context, node) {
|
|
116
|
+
function transformPropertyCall(context, node, calledMethod) {
|
|
116
117
|
const signature = context.checker.getResolvedSignature(node);
|
|
117
|
-
if (
|
|
118
|
+
if (calledMethod.expression.kind === ts.SyntaxKind.SuperKeyword) {
|
|
118
119
|
// Super calls take the format of super.call(self,...)
|
|
119
120
|
const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
|
|
120
121
|
return lua.createCallExpression(context.transformExpression(node.expression), parameters);
|
|
@@ -145,11 +146,15 @@ function transformElementCall(context, node) {
|
|
|
145
146
|
}
|
|
146
147
|
const transformCallExpression = (node, context) => {
|
|
147
148
|
var _a;
|
|
149
|
+
const calledExpression = getCalledExpression(node);
|
|
150
|
+
if (calledExpression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
151
|
+
return (0, import_1.transformImportExpression)(node, context);
|
|
152
|
+
}
|
|
148
153
|
if (ts.isOptionalChain(node)) {
|
|
149
154
|
return (0, optional_chaining_1.transformOptionalChain)(context, node);
|
|
150
155
|
}
|
|
151
|
-
const optionalContinuation = ts.isIdentifier(
|
|
152
|
-
? (0, optional_chaining_1.getOptionalContinuationData)(
|
|
156
|
+
const optionalContinuation = ts.isIdentifier(calledExpression)
|
|
157
|
+
? (0, optional_chaining_1.getOptionalContinuationData)(calledExpression)
|
|
153
158
|
: undefined;
|
|
154
159
|
const wrapResultInTable = (0, multi_1.isMultiReturnCall)(context, node) && (0, multi_1.shouldMultiReturnCallBeWrapped)(context, node);
|
|
155
160
|
if ((0, annotations_1.isTupleReturnCall)(context, node)) {
|
|
@@ -160,22 +165,22 @@ const transformCallExpression = (node, context) => {
|
|
|
160
165
|
// unsupportedOptionalCall diagnostic already present
|
|
161
166
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinOrExtensionResult) : builtinOrExtensionResult;
|
|
162
167
|
}
|
|
163
|
-
if (ts.isPropertyAccessExpression(
|
|
164
|
-
const ownerType = context.checker.getTypeAtLocation(
|
|
168
|
+
if (ts.isPropertyAccessExpression(calledExpression)) {
|
|
169
|
+
const ownerType = context.checker.getTypeAtLocation(calledExpression.expression);
|
|
165
170
|
const annotations = (0, annotations_1.getTypeAnnotations)(ownerType);
|
|
166
171
|
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
167
172
|
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
168
173
|
}
|
|
169
|
-
const result = transformPropertyCall(context, node);
|
|
174
|
+
const result = transformPropertyCall(context, node, calledExpression);
|
|
170
175
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
|
|
171
176
|
}
|
|
172
|
-
if (ts.isElementAccessExpression(
|
|
177
|
+
if (ts.isElementAccessExpression(calledExpression)) {
|
|
173
178
|
const result = transformElementCall(context, node);
|
|
174
179
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
|
|
175
180
|
}
|
|
176
181
|
const signature = context.checker.getResolvedSignature(node);
|
|
177
182
|
// Handle super calls properly
|
|
178
|
-
if (
|
|
183
|
+
if (calledExpression.kind === ts.SyntaxKind.SuperKeyword) {
|
|
179
184
|
const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
|
|
180
185
|
return lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), parameters);
|
|
181
186
|
}
|
|
@@ -184,13 +189,13 @@ const transformCallExpression = (node, context) => {
|
|
|
184
189
|
let parameters;
|
|
185
190
|
const isContextualCall = !signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void;
|
|
186
191
|
if (!isContextualCall) {
|
|
187
|
-
[callPath, parameters] = transformCallAndArguments(context,
|
|
192
|
+
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature);
|
|
188
193
|
}
|
|
189
194
|
else {
|
|
190
195
|
// if is optionalContinuation, context will be handled by transformOptionalChain.
|
|
191
196
|
const useGlobalContext = !context.isStrict && optionalContinuation === undefined;
|
|
192
197
|
const callContext = useGlobalContext ? ts.factory.createIdentifier("_G") : ts.factory.createNull();
|
|
193
|
-
[callPath, parameters] = transformCallAndArguments(context,
|
|
198
|
+
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature, callContext);
|
|
194
199
|
}
|
|
195
200
|
const callExpression = lua.createCallExpression(callPath, parameters, node);
|
|
196
201
|
if (optionalContinuation && isContextualCall) {
|
|
@@ -199,4 +204,12 @@ const transformCallExpression = (node, context) => {
|
|
|
199
204
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(callExpression) : callExpression;
|
|
200
205
|
};
|
|
201
206
|
exports.transformCallExpression = transformCallExpression;
|
|
207
|
+
function getCalledExpression(node) {
|
|
208
|
+
function unwrapExpression(expression) {
|
|
209
|
+
expression = ts.skipOuterExpressions(expression);
|
|
210
|
+
return ts.isNonNullExpression(expression) ? unwrapExpression(expression.expression) : expression;
|
|
211
|
+
}
|
|
212
|
+
return unwrapExpression(node.expression);
|
|
213
|
+
}
|
|
214
|
+
exports.getCalledExpression = getCalledExpression;
|
|
202
215
|
//# sourceMappingURL=call.js.map
|
|
@@ -96,7 +96,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
96
96
|
const constructorBody = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
|
|
97
97
|
const superCall = lua.createExpressionStatement(lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), [(0, lua_ast_1.createSelfIdentifier)(), lua.createDotsLiteral()]));
|
|
98
98
|
constructorBody.unshift(superCall);
|
|
99
|
-
const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [(0, lua_ast_1.createSelfIdentifier)()], lua.createDotsLiteral(), lua.
|
|
99
|
+
const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [(0, lua_ast_1.createSelfIdentifier)()], lua.createDotsLiteral(), lua.NodeFlags.Declaration);
|
|
100
100
|
result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
|
|
101
101
|
}
|
|
102
102
|
// Transform accessors
|
|
@@ -11,7 +11,7 @@ const constructor_1 = require("./constructor");
|
|
|
11
11
|
function transformAccessor(context, node) {
|
|
12
12
|
const [params, dot, restParam] = (0, function_1.transformParameters)(context, node.parameters, (0, lua_ast_1.createSelfIdentifier)());
|
|
13
13
|
const body = node.body ? (0, function_1.transformFunctionBody)(context, node.parameters, node.body, restParam)[0] : [];
|
|
14
|
-
return lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.
|
|
14
|
+
return lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.NodeFlags.Declaration);
|
|
15
15
|
}
|
|
16
16
|
function transformAccessorDeclarations(context, { firstAccessor, getAccessor, setAccessor }, className) {
|
|
17
17
|
const propertyName = (0, literal_1.transformPropertyName)(context, firstAccessor.name);
|
|
@@ -59,7 +59,7 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
59
59
|
const block = lua.createBlock(bodyWithFieldInitializers);
|
|
60
60
|
const constructorWasGenerated = statement.pos === -1;
|
|
61
61
|
(0, scope_1.popScope)(context);
|
|
62
|
-
return lua.createAssignmentStatement(createConstructorName(className), lua.createFunctionExpression(block, params, dotsLiteral, lua.
|
|
62
|
+
return lua.createAssignmentStatement(createConstructorName(className), lua.createFunctionExpression(block, params, dotsLiteral, lua.NodeFlags.Declaration), constructorWasGenerated ? classDeclaration : statement);
|
|
63
63
|
}
|
|
64
64
|
exports.transformConstructorDeclaration = transformConstructorDeclaration;
|
|
65
65
|
//# sourceMappingURL=constructor.js.map
|