typescript-to-lua 1.4.1 → 1.4.4
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 +4 -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 +5 -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/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 +372 -389
- package/dist/lualib/lualib_module_info.json +13 -23
- package/dist/transformation/builtins/array.d.ts +1 -1
- package/dist/transformation/builtins/array.js +35 -2
- package/dist/transformation/builtins/promise.d.ts +1 -0
- package/dist/transformation/builtins/promise.js +2 -1
- package/dist/transformation/builtins/string.js +1 -1
- 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 +6 -2
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +9 -1
- package/dist/transformation/visitors/call.js +4 -0
- 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 +4 -2
- package/dist/transformation/visitors/function.js +4 -4
- package/dist/transformation/visitors/modules/import.d.ts +1 -0
- package/dist/transformation/visitors/modules/import.js +9 -1
- package/dist/transformation/visitors/spread.js +1 -7
- package/dist/transpilation/resolve.js +1 -0
- package/package.json +1 -1
- package/dist/lualib/ArrayShift.lua +0 -3
- package/dist/lualib/StringConcat.lua +0 -8
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"__TS__ArrayFrom"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": [
|
|
48
|
-
"ArrayPush",
|
|
49
48
|
"Iterator"
|
|
50
49
|
]
|
|
51
50
|
},
|
|
@@ -79,6 +78,11 @@
|
|
|
79
78
|
"__TS__ArrayPush"
|
|
80
79
|
]
|
|
81
80
|
},
|
|
81
|
+
"ArrayPushArray": {
|
|
82
|
+
"exports": [
|
|
83
|
+
"__TS__ArrayPushArray"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
82
86
|
"ArrayReduce": {
|
|
83
87
|
"exports": [
|
|
84
88
|
"__TS__ArrayReduce"
|
|
@@ -94,11 +98,6 @@
|
|
|
94
98
|
"__TS__ArrayReverse"
|
|
95
99
|
]
|
|
96
100
|
},
|
|
97
|
-
"ArrayShift": {
|
|
98
|
-
"exports": [
|
|
99
|
-
"__TS__ArrayShift"
|
|
100
|
-
]
|
|
101
|
-
},
|
|
102
101
|
"ArrayUnshift": {
|
|
103
102
|
"exports": [
|
|
104
103
|
"__TS__ArrayUnshift"
|
|
@@ -135,7 +134,7 @@
|
|
|
135
134
|
],
|
|
136
135
|
"dependencies": [
|
|
137
136
|
"ArrayIsArray",
|
|
138
|
-
"
|
|
137
|
+
"ArrayFlat"
|
|
139
138
|
]
|
|
140
139
|
},
|
|
141
140
|
"ArrayFlatMap": {
|
|
@@ -143,8 +142,7 @@
|
|
|
143
142
|
"__TS__ArrayFlatMap"
|
|
144
143
|
],
|
|
145
144
|
"dependencies": [
|
|
146
|
-
"ArrayIsArray"
|
|
147
|
-
"ArrayConcat"
|
|
145
|
+
"ArrayIsArray"
|
|
148
146
|
]
|
|
149
147
|
},
|
|
150
148
|
"ArraySetLength": {
|
|
@@ -233,7 +231,8 @@
|
|
|
233
231
|
"__TS__FunctionBind"
|
|
234
232
|
],
|
|
235
233
|
"dependencies": [
|
|
236
|
-
"Unpack"
|
|
234
|
+
"Unpack",
|
|
235
|
+
"ArrayUnshift"
|
|
237
236
|
]
|
|
238
237
|
},
|
|
239
238
|
"Generator": {
|
|
@@ -390,8 +389,7 @@
|
|
|
390
389
|
"New",
|
|
391
390
|
"InstanceOf",
|
|
392
391
|
"Class",
|
|
393
|
-
"FunctionBind"
|
|
394
|
-
"ArrayPush"
|
|
392
|
+
"FunctionBind"
|
|
395
393
|
]
|
|
396
394
|
},
|
|
397
395
|
"PromiseAll": {
|
|
@@ -423,7 +421,6 @@
|
|
|
423
421
|
"dependencies": [
|
|
424
422
|
"InstanceOf",
|
|
425
423
|
"Promise",
|
|
426
|
-
"ArrayPush",
|
|
427
424
|
"Iterator",
|
|
428
425
|
"New"
|
|
429
426
|
]
|
|
@@ -435,7 +432,6 @@
|
|
|
435
432
|
"dependencies": [
|
|
436
433
|
"InstanceOf",
|
|
437
434
|
"Promise",
|
|
438
|
-
"ArrayPush",
|
|
439
435
|
"Iterator",
|
|
440
436
|
"New"
|
|
441
437
|
]
|
|
@@ -521,11 +517,6 @@
|
|
|
521
517
|
"__TS__StringCharCodeAt"
|
|
522
518
|
]
|
|
523
519
|
},
|
|
524
|
-
"StringConcat": {
|
|
525
|
-
"exports": [
|
|
526
|
-
"__TS__StringConcat"
|
|
527
|
-
]
|
|
528
|
-
},
|
|
529
520
|
"StringEndsWith": {
|
|
530
521
|
"exports": [
|
|
531
522
|
"__TS__StringEndsWith"
|
|
@@ -554,6 +545,9 @@
|
|
|
554
545
|
"StringReplaceAll": {
|
|
555
546
|
"exports": [
|
|
556
547
|
"__TS__StringReplaceAll"
|
|
548
|
+
],
|
|
549
|
+
"dependencies": [
|
|
550
|
+
"StringSplit"
|
|
557
551
|
]
|
|
558
552
|
},
|
|
559
553
|
"StringSlice": {
|
|
@@ -564,10 +558,6 @@
|
|
|
564
558
|
"StringSplit": {
|
|
565
559
|
"exports": [
|
|
566
560
|
"__TS__StringSplit"
|
|
567
|
-
],
|
|
568
|
-
"dependencies": [
|
|
569
|
-
"StringAccess",
|
|
570
|
-
"StringSubstring"
|
|
571
561
|
]
|
|
572
562
|
},
|
|
573
563
|
"StringStartsWith": {
|
|
@@ -3,5 +3,5 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
import { PropertyCallExpression } from "../visitors/call";
|
|
5
5
|
export declare function transformArrayConstructorCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
|
|
6
|
-
export declare function transformArrayPrototypeCall(context: TransformationContext, node: PropertyCallExpression): lua.
|
|
6
|
+
export declare function transformArrayPrototypeCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
|
|
7
7
|
export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.UnaryExpression | undefined;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformArrayProperty = exports.transformArrayPrototypeCall = exports.transformArrayConstructorCall = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
4
5
|
const lua = require("../../LuaAST");
|
|
5
6
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
7
|
const lualib_1 = require("../utils/lualib");
|
|
7
8
|
const call_1 = require("../visitors/call");
|
|
8
9
|
const typescript_1 = require("../utils/typescript");
|
|
10
|
+
const expression_list_1 = require("../visitors/expression-list");
|
|
9
11
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
10
12
|
function transformArrayConstructorCall(context, node) {
|
|
11
13
|
const expression = node.expression;
|
|
@@ -24,6 +26,25 @@ function transformArrayConstructorCall(context, node) {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
exports.transformArrayConstructorCall = transformArrayConstructorCall;
|
|
29
|
+
/**
|
|
30
|
+
* Optimized single element Array.push
|
|
31
|
+
*
|
|
32
|
+
* array[#array+1] = el
|
|
33
|
+
* return (#array + 1)
|
|
34
|
+
*/
|
|
35
|
+
function transformSingleElementArrayPush(context, node, caller, param) {
|
|
36
|
+
const expressionIsUsed = !ts.isExpressionStatement((0, typescript_1.findFirstNonOuterParent)(node));
|
|
37
|
+
const arrayIdentifier = lua.isIdentifier(caller) ? caller : (0, expression_list_1.moveToPrecedingTemp)(context, caller);
|
|
38
|
+
// #array + 1
|
|
39
|
+
let lengthExpression = lua.createBinaryExpression(lua.createUnaryExpression(arrayIdentifier, lua.SyntaxKind.LengthOperator), lua.createNumericLiteral(1), lua.SyntaxKind.AdditionOperator);
|
|
40
|
+
if (expressionIsUsed) {
|
|
41
|
+
// store length in a temp
|
|
42
|
+
lengthExpression = (0, expression_list_1.moveToPrecedingTemp)(context, lengthExpression);
|
|
43
|
+
}
|
|
44
|
+
const pushStatement = lua.createAssignmentStatement(lua.createTableIndexExpression(arrayIdentifier, lengthExpression), param, node);
|
|
45
|
+
context.addPrecedingStatements(pushStatement);
|
|
46
|
+
return expressionIsUsed ? lengthExpression : lua.createNilLiteral();
|
|
47
|
+
}
|
|
27
48
|
function transformArrayPrototypeCall(context, node) {
|
|
28
49
|
const expression = node.expression;
|
|
29
50
|
const signature = context.checker.getResolvedSignature(node);
|
|
@@ -35,11 +56,20 @@ function transformArrayPrototypeCall(context, node) {
|
|
|
35
56
|
case "entries":
|
|
36
57
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayEntries, node, caller);
|
|
37
58
|
case "push":
|
|
59
|
+
if (node.arguments.length === 1) {
|
|
60
|
+
const param = params[0];
|
|
61
|
+
if ((0, lua_ast_1.isUnpackCall)(param)) {
|
|
62
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, param.params[0]);
|
|
63
|
+
}
|
|
64
|
+
if (!lua.isDotsLiteral(param)) {
|
|
65
|
+
return transformSingleElementArrayPush(context, node, caller, param);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
38
68
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPush, node, caller, ...params);
|
|
39
69
|
case "reverse":
|
|
40
70
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayReverse, node, caller);
|
|
41
71
|
case "shift":
|
|
42
|
-
return (
|
|
72
|
+
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("remove")), [caller, lua.createNumericLiteral(1)], node);
|
|
43
73
|
case "unshift":
|
|
44
74
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayUnshift, node, caller, ...params);
|
|
45
75
|
case "sort":
|
|
@@ -77,11 +107,14 @@ function transformArrayPrototypeCall(context, node) {
|
|
|
77
107
|
const elementType = context.checker.getElementTypeOfArrayType(callerType);
|
|
78
108
|
if (elementType && ((0, typescript_1.isStringType)(context, elementType) || (0, typescript_1.isNumberType)(context, elementType))) {
|
|
79
109
|
const defaultSeparatorLiteral = lua.createStringLiteral(",");
|
|
110
|
+
const param = params[0];
|
|
80
111
|
const parameters = [
|
|
81
112
|
caller,
|
|
82
113
|
node.arguments.length === 0
|
|
83
114
|
? defaultSeparatorLiteral
|
|
84
|
-
: lua.
|
|
115
|
+
: lua.isStringLiteral(param)
|
|
116
|
+
? param
|
|
117
|
+
: lua.createBinaryExpression(param, defaultSeparatorLiteral, lua.SyntaxKind.OrOperator),
|
|
85
118
|
];
|
|
86
119
|
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("concat")), parameters, node);
|
|
87
120
|
}
|
|
@@ -5,3 +5,4 @@ import { PropertyCallExpression } from "../visitors/call";
|
|
|
5
5
|
export declare function isPromiseClass(context: TransformationContext, node: ts.Identifier): boolean;
|
|
6
6
|
export declare function createPromiseIdentifier(original: ts.Node): lua.Identifier;
|
|
7
7
|
export declare function transformPromiseConstructorCall(context: TransformationContext, node: PropertyCallExpression): lua.Expression | undefined;
|
|
8
|
+
export declare function createStaticPromiseFunctionAccessor(functionName: string, node: ts.Node): lua.TableIndexExpression;
|
|
@@ -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");
|
|
@@ -43,4 +43,5 @@ exports.transformPromiseConstructorCall = transformPromiseConstructorCall;
|
|
|
43
43
|
function createStaticPromiseFunctionAccessor(functionName, node) {
|
|
44
44
|
return lua.createTableIndexExpression(lua.createIdentifier("__TS__Promise"), lua.createStringLiteral(functionName), node);
|
|
45
45
|
}
|
|
46
|
+
exports.createStaticPromiseFunctionAccessor = createStaticPromiseFunctionAccessor;
|
|
46
47
|
//# sourceMappingURL=promise.js.map
|
|
@@ -21,7 +21,7 @@ function transformStringPrototypeCall(context, node) {
|
|
|
21
21
|
case "replaceAll":
|
|
22
22
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringReplaceAll, node, caller, ...params);
|
|
23
23
|
case "concat":
|
|
24
|
-
return (
|
|
24
|
+
return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("concat")), [(0, lua_ast_1.wrapInTable)(caller, ...params)], node);
|
|
25
25
|
case "indexOf": {
|
|
26
26
|
const stringExpression = createStringCall("find", node, caller, params[0], params[1]
|
|
27
27
|
? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
|
|
@@ -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);
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -145,6 +146,9 @@ function transformElementCall(context, node) {
|
|
|
145
146
|
}
|
|
146
147
|
const transformCallExpression = (node, context) => {
|
|
147
148
|
var _a;
|
|
149
|
+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
150
|
+
return (0, import_1.transformImportExpression)(node, context);
|
|
151
|
+
}
|
|
148
152
|
if (ts.isOptionalChain(node)) {
|
|
149
153
|
return (0, optional_chaining_1.transformOptionalChain)(context, node);
|
|
150
154
|
}
|
|
@@ -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
|
|
@@ -14,8 +14,10 @@ const return_1 = require("./return");
|
|
|
14
14
|
const transformTryStatement = (statement, context) => {
|
|
15
15
|
var _a;
|
|
16
16
|
const [tryBlock, tryScope] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
|
|
17
|
-
if (context.options.luaTarget === __1.LuaTarget.Lua51 &&
|
|
18
|
-
|
|
17
|
+
if (context.options.luaTarget === __1.LuaTarget.Lua51 &&
|
|
18
|
+
(0, typescript_1.isInAsyncFunction)(statement) &&
|
|
19
|
+
!context.options.lua51AllowTryCatchInAsyncAwait) {
|
|
20
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTargetButOverrideAvailable)(statement, "try/catch inside async functions", __1.LuaTarget.Lua51, "lua51AllowTryCatchInAsyncAwait"));
|
|
19
21
|
return tryBlock.statements;
|
|
20
22
|
}
|
|
21
23
|
if (context.options.luaTarget === __1.LuaTarget.Lua51 && (0, typescript_1.isInGeneratorFunction)(statement)) {
|
|
@@ -46,7 +46,7 @@ function createCallableTable(functionExpression) {
|
|
|
46
46
|
// so we create a forwarding function to eat the extra argument
|
|
47
47
|
functionExpression = lua.createFunctionExpression(lua.createBlock([
|
|
48
48
|
lua.createReturnStatement([lua.createCallExpression(functionExpression, [lua.createDotsLiteral()])]),
|
|
49
|
-
]), [lua.createAnonymousIdentifier()], lua.createDotsLiteral(), lua.
|
|
49
|
+
]), [lua.createAnonymousIdentifier()], lua.createDotsLiteral(), lua.NodeFlags.Inline);
|
|
50
50
|
}
|
|
51
51
|
return lua.createCallExpression(lua.createIdentifier("setmetatable"), [
|
|
52
52
|
lua.createTableExpression(),
|
|
@@ -169,11 +169,11 @@ function transformFunctionToExpression(context, node) {
|
|
|
169
169
|
functionContext = (0, lua_ast_1.createSelfIdentifier)();
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
let flags = lua.
|
|
172
|
+
let flags = lua.NodeFlags.None;
|
|
173
173
|
if (!ts.isBlock(node.body))
|
|
174
|
-
flags |= lua.
|
|
174
|
+
flags |= lua.NodeFlags.Inline;
|
|
175
175
|
if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {
|
|
176
|
-
flags |= lua.
|
|
176
|
+
flags |= lua.NodeFlags.Declaration;
|
|
177
177
|
}
|
|
178
178
|
const [paramNames, dotsLiteral, spreadIdentifier] = transformParameters(context, node.parameters, functionContext);
|
|
179
179
|
const [transformedBody, functionScope] = transformFunctionBody(context, node.parameters, node.body, spreadIdentifier, node);
|
|
@@ -5,3 +5,4 @@ export declare function createModuleRequire(context: TransformationContext, modu
|
|
|
5
5
|
export declare const transformImportDeclaration: FunctionVisitor<ts.ImportDeclaration>;
|
|
6
6
|
export declare const transformExternalModuleReference: FunctionVisitor<ts.ExternalModuleReference>;
|
|
7
7
|
export declare const transformImportEqualsDeclaration: FunctionVisitor<ts.ImportEqualsDeclaration>;
|
|
8
|
+
export declare const transformImportExpression: FunctionVisitor<ts.CallExpression>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformImportEqualsDeclaration = exports.transformExternalModuleReference = exports.transformImportDeclaration = exports.createModuleRequire = void 0;
|
|
3
|
+
exports.transformImportExpression = exports.transformImportEqualsDeclaration = exports.transformExternalModuleReference = exports.transformImportDeclaration = exports.createModuleRequire = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const ts = require("typescript");
|
|
6
6
|
const lua = require("../../../LuaAST");
|
|
7
|
+
const promise_1 = require("../../builtins/promise");
|
|
7
8
|
const annotations_1 = require("../../utils/annotations");
|
|
8
9
|
const export_1 = require("../../utils/export");
|
|
9
10
|
const lua_ast_1 = require("../../utils/lua-ast");
|
|
11
|
+
const lualib_1 = require("../../utils/lualib");
|
|
10
12
|
const safe_names_1 = require("../../utils/safe-names");
|
|
11
13
|
const scope_1 = require("../../utils/scope");
|
|
12
14
|
const identifier_1 = require("../identifier");
|
|
@@ -113,4 +115,10 @@ const transformImportEqualsDeclaration = (node, context) => {
|
|
|
113
115
|
return (0, lua_ast_1.createHoistableVariableDeclarationStatement)(context, name, expression, node);
|
|
114
116
|
};
|
|
115
117
|
exports.transformImportEqualsDeclaration = transformImportEqualsDeclaration;
|
|
118
|
+
const transformImportExpression = (node, context) => {
|
|
119
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
120
|
+
const importPath = node.arguments.map(a => context.transformExpression(a));
|
|
121
|
+
return lua.createCallExpression((0, promise_1.createStaticPromiseFunctionAccessor)("resolve", node), importPath, node);
|
|
122
|
+
};
|
|
123
|
+
exports.transformImportExpression = transformImportExpression;
|
|
116
124
|
//# sourceMappingURL=import.js.map
|
|
@@ -11,15 +11,9 @@ const typescript_1 = require("../utils/typescript");
|
|
|
11
11
|
const multi_1 = require("./language-extensions/multi");
|
|
12
12
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
13
13
|
const vararg_1 = require("./language-extensions/vararg");
|
|
14
|
-
function skipOuterExpressionParents(node) {
|
|
15
|
-
while (ts.isOuterExpression(node)) {
|
|
16
|
-
node = node.parent;
|
|
17
|
-
}
|
|
18
|
-
return node;
|
|
19
|
-
}
|
|
20
14
|
function isOptimizedVarArgSpread(context, symbol, identifier) {
|
|
21
15
|
var _a;
|
|
22
|
-
if (!ts.isSpreadElement(
|
|
16
|
+
if (!ts.isSpreadElement((0, typescript_1.findFirstNonOuterParent)(identifier))) {
|
|
23
17
|
return false;
|
|
24
18
|
}
|
|
25
19
|
// Walk up, stopping at any scope types which could stop optimization
|
|
@@ -14,6 +14,7 @@ const resolver = resolve.ResolverFactory.createResolver({
|
|
|
14
14
|
enforceExtension: true,
|
|
15
15
|
fileSystem: { ...new resolve.CachedInputFileSystem(fs) },
|
|
16
16
|
useSyncFileSystemCalls: true,
|
|
17
|
+
symlinks: false, // Do not resolve symlinks to their original paths (that breaks node_modules detection)
|
|
17
18
|
});
|
|
18
19
|
class ResolutionContext {
|
|
19
20
|
constructor(program, options, emitHost) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|