typescript-to-lua 1.9.0 → 1.10.0-beta.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 +1 -0
- package/dist/CompilerOptions.js +1 -0
- package/dist/LuaAST.d.ts +43 -37
- package/dist/LuaAST.js +48 -38
- package/dist/LuaLib.d.ts +12 -6
- package/dist/LuaLib.js +31 -21
- package/dist/LuaPrinter.d.ts +1 -0
- package/dist/LuaPrinter.js +10 -4
- package/dist/lualib/5.0/ArrayConcat.lua +22 -0
- package/dist/lualib/5.0/ArrayEntries.lua +13 -0
- package/dist/lualib/5.0/ArrayEvery.lua +8 -0
- package/dist/lualib/5.0/ArrayFilter.lua +11 -0
- package/dist/lualib/5.0/ArrayFind.lua +9 -0
- package/dist/lualib/5.0/ArrayFindIndex.lua +8 -0
- package/dist/lualib/5.0/ArrayFlat.lua +27 -0
- package/dist/lualib/5.0/ArrayFlatMap.lua +17 -0
- package/dist/lualib/5.0/ArrayForEach.lua +5 -0
- package/dist/lualib/5.0/ArrayFrom.lua +29 -0
- package/dist/lualib/5.0/ArrayIncludes.lua +19 -0
- package/dist/lualib/5.0/ArrayIndexOf.lua +24 -0
- package/dist/lualib/5.0/ArrayIsArray.lua +3 -0
- package/dist/lualib/5.0/ArrayJoin.lua +10 -0
- package/dist/lualib/5.0/ArrayMap.lua +7 -0
- package/dist/lualib/5.0/ArrayPush.lua +9 -0
- package/dist/lualib/5.0/ArrayPushArray.lua +8 -0
- package/dist/lualib/5.0/ArrayReduce.lua +23 -0
- package/dist/lualib/5.0/ArrayReduceRight.lua +23 -0
- package/dist/lualib/5.0/ArrayReverse.lua +12 -0
- package/dist/lualib/5.0/ArraySetLength.lua +12 -0
- package/dist/lualib/5.0/ArraySlice.lua +43 -0
- package/dist/lualib/5.0/ArraySome.lua +8 -0
- package/dist/lualib/5.0/ArraySort.lua +11 -0
- package/dist/lualib/5.0/ArraySplice.lua +77 -0
- package/dist/lualib/5.0/ArrayToObject.lua +7 -0
- package/dist/lualib/5.0/ArrayUnshift.lua +14 -0
- package/dist/lualib/5.0/Await.lua +54 -0
- package/dist/lualib/5.0/Class.lua +6 -0
- package/dist/lualib/5.0/ClassExtends.lua +24 -0
- package/dist/lualib/5.0/CloneDescriptor.lua +28 -0
- package/dist/lualib/5.0/CountVarargs.lua +4 -0
- package/dist/lualib/5.0/Decorate.lua +36 -0
- package/dist/lualib/5.0/DecorateParam.lua +3 -0
- package/dist/lualib/5.0/DelegatedYield.lua +34 -0
- package/dist/lualib/5.0/Delete.lua +19 -0
- package/dist/lualib/5.0/Error.lua +85 -0
- package/dist/lualib/5.0/FunctionBind.lua +11 -0
- package/dist/lualib/5.0/Generator.lua +34 -0
- package/dist/lualib/5.0/InstanceOf.lua +18 -0
- package/dist/lualib/5.0/InstanceOfObject.lua +4 -0
- package/dist/lualib/5.0/Iterator.lua +40 -0
- package/dist/lualib/5.0/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/5.0/Map.lua +140 -0
- package/dist/lualib/5.0/Match.lua +13 -0
- package/dist/lualib/5.0/MathAtan2.lua +1 -0
- package/dist/lualib/5.0/MathModf.lua +10 -0
- package/dist/lualib/5.0/MathSign.lua +8 -0
- package/dist/lualib/5.0/Modulo50.lua +3 -0
- package/dist/lualib/5.0/New.lua +5 -0
- package/dist/lualib/5.0/Number.lua +26 -0
- package/dist/lualib/5.0/NumberIsFinite.lua +3 -0
- package/dist/lualib/5.0/NumberIsNaN.lua +3 -0
- package/dist/lualib/5.0/NumberToString.lua +47 -0
- package/dist/lualib/5.0/ObjectAssign.lua +10 -0
- package/dist/lualib/5.0/ObjectDefineProperty.lua +59 -0
- package/dist/lualib/5.0/ObjectEntries.lua +9 -0
- package/dist/lualib/5.0/ObjectFromEntries.lua +20 -0
- package/dist/lualib/5.0/ObjectGetOwnPropertyDescriptor.lua +10 -0
- package/dist/lualib/5.0/ObjectGetOwnPropertyDescriptors.lua +7 -0
- package/dist/lualib/5.0/ObjectKeys.lua +9 -0
- package/dist/lualib/5.0/ObjectRest.lua +9 -0
- package/dist/lualib/5.0/ObjectValues.lua +9 -0
- package/dist/lualib/5.0/ParseFloat.lua +18 -0
- package/dist/lualib/5.0/ParseInt.lua +49 -0
- package/dist/lualib/5.0/Promise.lua +176 -0
- package/dist/lualib/5.0/PromiseAll.lua +44 -0
- package/dist/lualib/5.0/PromiseAllSettled.lua +48 -0
- package/dist/lualib/5.0/PromiseAny.lua +41 -0
- package/dist/lualib/5.0/PromiseRace.lua +28 -0
- package/dist/lualib/5.0/Set.lua +130 -0
- package/dist/lualib/5.0/SetDescriptor.lua +79 -0
- package/dist/lualib/5.0/SourceMapTraceBack.lua +56 -0
- package/dist/lualib/5.0/SparseArrayNew.lua +5 -0
- package/dist/lualib/5.0/SparseArrayPush.lua +9 -0
- package/dist/lualib/5.0/SparseArraySpread.lua +3 -0
- package/dist/lualib/5.0/Spread.lua +15 -0
- package/dist/lualib/5.0/StringAccess.lua +5 -0
- package/dist/lualib/5.0/StringCharAt.lua +9 -0
- package/dist/lualib/5.0/StringCharCodeAt.lua +13 -0
- package/dist/lualib/5.0/StringEndsWith.lua +10 -0
- package/dist/lualib/5.0/StringIncludes.lua +9 -0
- package/dist/lualib/5.0/StringPadEnd.lua +26 -0
- package/dist/lualib/5.0/StringPadStart.lua +26 -0
- package/dist/lualib/5.0/StringReplace.lua +20 -0
- package/dist/lualib/5.0/StringReplaceAll.lua +42 -0
- package/dist/lualib/5.0/StringSlice.lua +15 -0
- package/dist/lualib/5.0/StringSplit.lua +36 -0
- package/dist/lualib/5.0/StringStartsWith.lua +10 -0
- package/dist/lualib/5.0/StringSubstr.lua +15 -0
- package/dist/lualib/5.0/StringSubstring.lua +17 -0
- package/dist/lualib/5.0/StringTrim.lua +4 -0
- package/dist/lualib/5.0/StringTrimEnd.lua +4 -0
- package/dist/lualib/5.0/StringTrimStart.lua +4 -0
- package/dist/lualib/5.0/Symbol.lua +15 -0
- package/dist/lualib/5.0/SymbolRegistry.lua +17 -0
- package/dist/lualib/5.0/TypeOf.lua +10 -0
- package/dist/lualib/5.0/Unpack.lua +1 -0
- package/dist/lualib/5.0/WeakMap.lua +45 -0
- package/dist/lualib/5.0/WeakSet.lua +41 -0
- package/dist/lualib/5.0/lualib_bundle.lua +2574 -0
- package/dist/lualib/5.0/lualib_module_info.json +672 -0
- package/dist/lualib/universal/ArrayConcat.lua +22 -0
- package/dist/lualib/universal/ArrayEntries.lua +13 -0
- package/dist/lualib/universal/ArrayEvery.lua +8 -0
- package/dist/lualib/universal/ArrayFilter.lua +11 -0
- package/dist/lualib/universal/ArrayFind.lua +9 -0
- package/dist/lualib/universal/ArrayFindIndex.lua +8 -0
- package/dist/lualib/universal/ArrayFlat.lua +27 -0
- package/dist/lualib/universal/ArrayFlatMap.lua +17 -0
- package/dist/lualib/universal/ArrayForEach.lua +5 -0
- package/dist/lualib/universal/ArrayFrom.lua +29 -0
- package/dist/lualib/universal/ArrayIncludes.lua +19 -0
- package/dist/lualib/universal/ArrayIndexOf.lua +24 -0
- package/dist/lualib/universal/ArrayIsArray.lua +3 -0
- package/dist/lualib/universal/ArrayJoin.lua +10 -0
- package/dist/lualib/universal/ArrayMap.lua +7 -0
- package/dist/lualib/universal/ArrayPush.lua +9 -0
- package/dist/lualib/universal/ArrayPushArray.lua +8 -0
- package/dist/lualib/universal/ArrayReduce.lua +23 -0
- package/dist/lualib/universal/ArrayReduceRight.lua +23 -0
- package/dist/lualib/universal/ArrayReverse.lua +12 -0
- package/dist/lualib/universal/ArraySetLength.lua +12 -0
- package/dist/lualib/universal/ArraySlice.lua +43 -0
- package/dist/lualib/universal/ArraySome.lua +8 -0
- package/dist/lualib/universal/ArraySort.lua +11 -0
- package/dist/lualib/universal/ArraySplice.lua +77 -0
- package/dist/lualib/universal/ArrayToObject.lua +7 -0
- package/dist/lualib/universal/ArrayUnshift.lua +14 -0
- package/dist/lualib/universal/Await.lua +54 -0
- package/dist/lualib/universal/Class.lua +6 -0
- package/dist/lualib/universal/ClassExtends.lua +24 -0
- package/dist/lualib/universal/CloneDescriptor.lua +28 -0
- package/dist/lualib/universal/CountVarargs.lua +3 -0
- package/dist/lualib/universal/Decorate.lua +36 -0
- package/dist/lualib/universal/DecorateParam.lua +3 -0
- package/dist/lualib/universal/DelegatedYield.lua +34 -0
- package/dist/lualib/universal/Delete.lua +19 -0
- package/dist/lualib/universal/Error.lua +82 -0
- package/dist/lualib/universal/FunctionBind.lua +11 -0
- package/dist/lualib/universal/Generator.lua +31 -0
- package/dist/lualib/universal/InstanceOf.lua +18 -0
- package/dist/lualib/universal/InstanceOfObject.lua +4 -0
- package/dist/lualib/universal/Iterator.lua +40 -0
- package/dist/lualib/universal/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/universal/Map.lua +140 -0
- package/dist/lualib/universal/Match.lua +1 -0
- package/dist/lualib/universal/MathAtan2.lua +1 -0
- package/dist/lualib/universal/MathModf.lua +1 -0
- package/dist/lualib/universal/MathSign.lua +8 -0
- package/dist/lualib/universal/Modulo50.lua +3 -0
- package/dist/lualib/universal/New.lua +5 -0
- package/dist/lualib/universal/Number.lua +26 -0
- package/dist/lualib/universal/NumberIsFinite.lua +3 -0
- package/dist/lualib/universal/NumberIsNaN.lua +3 -0
- package/dist/lualib/universal/NumberToString.lua +44 -0
- package/dist/lualib/universal/ObjectAssign.lua +10 -0
- package/dist/lualib/universal/ObjectDefineProperty.lua +59 -0
- package/dist/lualib/universal/ObjectEntries.lua +9 -0
- package/dist/lualib/universal/ObjectFromEntries.lua +20 -0
- package/dist/lualib/universal/ObjectGetOwnPropertyDescriptor.lua +10 -0
- package/dist/lualib/universal/ObjectGetOwnPropertyDescriptors.lua +7 -0
- package/dist/lualib/universal/ObjectKeys.lua +9 -0
- package/dist/lualib/universal/ObjectRest.lua +9 -0
- package/dist/lualib/universal/ObjectValues.lua +9 -0
- package/dist/lualib/universal/ParseFloat.lua +18 -0
- package/dist/lualib/universal/ParseInt.lua +43 -0
- package/dist/lualib/universal/Promise.lua +176 -0
- package/dist/lualib/universal/PromiseAll.lua +44 -0
- package/dist/lualib/universal/PromiseAllSettled.lua +48 -0
- package/dist/lualib/universal/PromiseAny.lua +41 -0
- package/dist/lualib/universal/PromiseRace.lua +28 -0
- package/dist/lualib/universal/Set.lua +130 -0
- package/dist/lualib/universal/SetDescriptor.lua +79 -0
- package/dist/lualib/universal/SourceMapTraceBack.lua +56 -0
- package/dist/lualib/universal/SparseArrayNew.lua +5 -0
- package/dist/lualib/universal/SparseArrayPush.lua +9 -0
- package/dist/lualib/universal/SparseArraySpread.lua +8 -0
- package/dist/lualib/universal/Spread.lua +15 -0
- package/dist/lualib/universal/StringAccess.lua +5 -0
- package/dist/lualib/universal/StringCharAt.lua +9 -0
- package/dist/lualib/universal/StringCharCodeAt.lua +13 -0
- package/dist/lualib/universal/StringEndsWith.lua +6 -0
- package/dist/lualib/universal/StringIncludes.lua +9 -0
- package/dist/lualib/universal/StringPadEnd.lua +26 -0
- package/dist/lualib/universal/StringPadStart.lua +26 -0
- package/dist/lualib/universal/StringReplace.lua +20 -0
- package/dist/lualib/universal/StringReplaceAll.lua +42 -0
- package/dist/lualib/universal/StringSlice.lua +15 -0
- package/dist/lualib/universal/StringSplit.lua +36 -0
- package/dist/lualib/universal/StringStartsWith.lua +6 -0
- package/dist/lualib/universal/StringSubstr.lua +15 -0
- package/dist/lualib/universal/StringSubstring.lua +17 -0
- package/dist/lualib/universal/StringTrim.lua +4 -0
- package/dist/lualib/universal/StringTrimEnd.lua +4 -0
- package/dist/lualib/universal/StringTrimStart.lua +4 -0
- package/dist/lualib/universal/Symbol.lua +15 -0
- package/dist/lualib/universal/SymbolRegistry.lua +17 -0
- package/dist/lualib/universal/TypeOf.lua +10 -0
- package/dist/lualib/universal/Unpack.lua +1 -0
- package/dist/lualib/universal/WeakMap.lua +45 -0
- package/dist/lualib/universal/WeakSet.lua +41 -0
- package/dist/lualib/universal/lualib_bundle.lua +2534 -0
- package/dist/lualib/universal/lualib_module_info.json +671 -0
- package/dist/lualib/universal/universal/CountVarargs.lua +3 -0
- package/dist/lualib/universal/universal/Match.lua +1 -0
- package/dist/lualib/universal/universal/MathModf.lua +1 -0
- package/dist/lualib/universal/universal/SparseArraySpread.lua +8 -0
- package/dist/lualib/universal/universal/Unpack.lua +1 -0
- package/dist/lualib-build/plugin.js +12 -2
- package/dist/transformation/builtins/array.d.ts +1 -1
- package/dist/transformation/builtins/array.js +12 -2
- package/dist/transformation/builtins/function.js +4 -2
- package/dist/transformation/builtins/index.js +11 -3
- package/dist/transformation/builtins/string.d.ts +1 -1
- package/dist/transformation/builtins/string.js +8 -1
- package/dist/transformation/utils/diagnostics.d.ts +2 -4
- package/dist/transformation/utils/lua-ast.js +3 -1
- package/dist/transformation/utils/typescript/index.js +2 -2
- package/dist/transformation/visitors/binary-expression/bit.js +4 -2
- package/dist/transformation/visitors/binary-expression/index.js +4 -0
- package/dist/transformation/visitors/break-continue.js +4 -2
- package/dist/transformation/visitors/class/index.js +9 -4
- package/dist/transformation/visitors/class/members/fields.js +6 -2
- package/dist/transformation/visitors/class/members/method.js +4 -2
- package/dist/transformation/visitors/errors.js +4 -2
- package/dist/transformation/visitors/function.js +2 -1
- package/dist/transformation/visitors/language-extensions/operators.js +2 -1
- package/dist/transformation/visitors/literal.js +12 -4
- package/dist/transformation/visitors/modules/export.js +1 -1
- package/dist/transformation/visitors/spread.js +4 -1
- package/dist/transformation/visitors/typescript.js +1 -0
- package/dist/transpilation/bundle.js +11 -4
- package/dist/transpilation/transpiler.js +3 -1
- package/package.json +18 -18
- package/language-extensions/index.d.ts +0 -676
|
@@ -3,4 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformArrayConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
5
|
export declare function transformArrayPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
6
|
-
export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.
|
|
6
|
+
export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformArrayProperty = exports.transformArrayPrototypeCall = exports.transformArrayConstructorCall = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
5
6
|
const lua = require("../../LuaAST");
|
|
6
7
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
7
8
|
const lualib_1 = require("../utils/lualib");
|
|
@@ -25,6 +26,15 @@ function transformArrayConstructorCall(context, node, calledMethod) {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
exports.transformArrayConstructorCall = transformArrayConstructorCall;
|
|
29
|
+
function createTableLengthExpression(context, expression, node) {
|
|
30
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
31
|
+
const tableGetn = lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("getn"));
|
|
32
|
+
return lua.createCallExpression(tableGetn, [expression], node);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return lua.createUnaryExpression(expression, lua.SyntaxKind.LengthOperator, node);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
28
38
|
/**
|
|
29
39
|
* Optimized single element Array.push
|
|
30
40
|
*
|
|
@@ -35,7 +45,7 @@ function transformSingleElementArrayPush(context, node, caller, param) {
|
|
|
35
45
|
const expressionIsUsed = !ts.isExpressionStatement((0, typescript_1.findFirstNonOuterParent)(node));
|
|
36
46
|
const arrayIdentifier = lua.isIdentifier(caller) ? caller : (0, expression_list_1.moveToPrecedingTemp)(context, caller);
|
|
37
47
|
// #array + 1
|
|
38
|
-
let lengthExpression = lua.createBinaryExpression(
|
|
48
|
+
let lengthExpression = lua.createBinaryExpression(createTableLengthExpression(context, arrayIdentifier), lua.createNumericLiteral(1), lua.SyntaxKind.AdditionOperator);
|
|
39
49
|
if (expressionIsUsed) {
|
|
40
50
|
// store length in a temp
|
|
41
51
|
lengthExpression = (0, expression_list_1.moveToPrecedingTemp)(context, lengthExpression);
|
|
@@ -131,7 +141,7 @@ function transformArrayProperty(context, node) {
|
|
|
131
141
|
switch (node.name.text) {
|
|
132
142
|
case "length":
|
|
133
143
|
const expression = context.transformExpression(node.expression);
|
|
134
|
-
return
|
|
144
|
+
return createTableLengthExpression(context, expression, node);
|
|
135
145
|
default:
|
|
136
146
|
return undefined;
|
|
137
147
|
}
|
|
@@ -32,8 +32,10 @@ exports.transformFunctionPrototypeCall = transformFunctionPrototypeCall;
|
|
|
32
32
|
function transformFunctionProperty(context, node) {
|
|
33
33
|
switch (node.name.text) {
|
|
34
34
|
case "length":
|
|
35
|
-
if (context.luaTarget === CompilerOptions_1.LuaTarget.
|
|
36
|
-
context.
|
|
35
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
36
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
37
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Universal) {
|
|
38
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "function.length", context.luaTarget));
|
|
37
39
|
}
|
|
38
40
|
// debug.getinfo(fn)
|
|
39
41
|
const getInfoCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("debug"), lua.createStringLiteral("getinfo")), [context.transformExpression(node.expression)]);
|
|
@@ -19,6 +19,7 @@ const promise_1 = require("./promise");
|
|
|
19
19
|
const string_1 = require("./string");
|
|
20
20
|
const symbol_1 = require("./symbol");
|
|
21
21
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
22
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
22
23
|
function transformBuiltinPropertyAccessExpression(context, node) {
|
|
23
24
|
const ownerType = context.checker.getTypeAtLocation(node.expression);
|
|
24
25
|
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
|
|
@@ -130,9 +131,16 @@ function transformBuiltinIdentifierExpression(context, node, symbol) {
|
|
|
130
131
|
case "NaN":
|
|
131
132
|
return (0, lua_ast_1.createNaN)(node);
|
|
132
133
|
case "Infinity":
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
135
|
+
const one = lua.createNumericLiteral(1);
|
|
136
|
+
const zero = lua.createNumericLiteral(0);
|
|
137
|
+
return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const math = lua.createIdentifier("math");
|
|
141
|
+
const huge = lua.createStringLiteral("huge");
|
|
142
|
+
return lua.createTableIndexExpression(math, huge, node);
|
|
143
|
+
}
|
|
136
144
|
case "globalThis":
|
|
137
145
|
return lua.createIdentifier("_G", node, (0, symbols_1.getIdentifierSymbolId)(context, node, symbol), "globalThis");
|
|
138
146
|
}
|
|
@@ -3,4 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformStringPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
5
|
export declare function transformStringConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
6
|
-
export declare function transformStringProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.
|
|
6
|
+
export declare function transformStringProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformStringProperty = exports.transformStringConstructorCall = exports.transformStringPrototypeCall = void 0;
|
|
4
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
4
5
|
const lua = require("../../LuaAST");
|
|
5
6
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
@@ -123,7 +124,13 @@ function transformStringProperty(context, node) {
|
|
|
123
124
|
switch (node.name.text) {
|
|
124
125
|
case "length":
|
|
125
126
|
const expression = context.transformExpression(node.expression);
|
|
126
|
-
|
|
127
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
128
|
+
const stringLen = lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("len"));
|
|
129
|
+
return lua.createCallExpression(stringLen, [expression], node);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return lua.createUnaryExpression(expression, lua.SyntaxKind.LengthOperator, node);
|
|
133
|
+
}
|
|
127
134
|
default:
|
|
128
135
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "string", node.name.text));
|
|
129
136
|
}
|
|
@@ -43,11 +43,10 @@ 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
|
-
declare
|
|
47
|
-
export declare const unsupportedForTarget: ((node: ts.Node, functionality: string, version: NonUniversalTarget) => ts.Diagnostic) & {
|
|
46
|
+
export declare const unsupportedForTarget: ((node: ts.Node, functionality: string, version: LuaTarget) => ts.Diagnostic) & {
|
|
48
47
|
code: number;
|
|
49
48
|
};
|
|
50
|
-
export declare const unsupportedForTargetButOverrideAvailable: ((node: ts.Node, functionality: string, version:
|
|
49
|
+
export declare const unsupportedForTargetButOverrideAvailable: ((node: ts.Node, functionality: string, version: LuaTarget, optionName: keyof TypeScriptToLuaOptions) => ts.Diagnostic) & {
|
|
51
50
|
code: number;
|
|
52
51
|
};
|
|
53
52
|
export declare const unsupportedProperty: ((node: ts.Node, parentName: string, property: string) => ts.Diagnostic) & {
|
|
@@ -101,4 +100,3 @@ export declare const unsupportedOptionalCompileMembersOnly: ((node: ts.Node, ...
|
|
|
101
100
|
export declare const undefinedInArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
102
101
|
code: number;
|
|
103
102
|
};
|
|
104
|
-
export {};
|
|
@@ -59,7 +59,9 @@ function createUnpackCall(context, expression, tsOriginal) {
|
|
|
59
59
|
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal) {
|
|
60
60
|
return (0, lualib_1.transformLuaLibFunction)(context, LuaLib_1.LuaLibFeature.Unpack, tsOriginal, expression);
|
|
61
61
|
}
|
|
62
|
-
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.
|
|
62
|
+
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
63
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
64
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT
|
|
63
65
|
? lua.createIdentifier("unpack")
|
|
64
66
|
: lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("unpack"));
|
|
65
67
|
return lua.setNodeFlags(lua.createCallExpression(unpack, [expression], tsOriginal), lua.NodeFlags.TableUnpackCall);
|
|
@@ -97,7 +97,7 @@ function isExpressionWithEvaluationEffect(node) {
|
|
|
97
97
|
exports.isExpressionWithEvaluationEffect = isExpressionWithEvaluationEffect;
|
|
98
98
|
function getFunctionTypeForCall(context, node) {
|
|
99
99
|
const signature = context.checker.getResolvedSignature(node);
|
|
100
|
-
if (!signature ||
|
|
100
|
+
if (!(signature === null || signature === void 0 ? void 0 : signature.declaration)) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
const typeDeclaration = findFirstNodeAbove(signature.declaration, ts.isTypeAliasDeclaration);
|
|
@@ -116,7 +116,7 @@ function isConstIdentifier(context, node) {
|
|
|
116
116
|
return false;
|
|
117
117
|
}
|
|
118
118
|
const symbol = context.checker.getSymbolAtLocation(identifier);
|
|
119
|
-
if (!symbol ||
|
|
119
|
+
if (!(symbol === null || symbol === void 0 ? void 0 : symbol.declarations)) {
|
|
120
120
|
return false;
|
|
121
121
|
}
|
|
122
122
|
return symbol.declarations.some(d => ts.isVariableDeclarationList(d.parent) && (d.parent.flags & ts.NodeFlags.Const) !== 0);
|
|
@@ -39,8 +39,9 @@ function transformBitOperatorToLuaOperator(context, node, operator) {
|
|
|
39
39
|
function transformBinaryBitOperation(context, node, left, right, operator) {
|
|
40
40
|
switch (context.luaTarget) {
|
|
41
41
|
case CompilerOptions_1.LuaTarget.Universal:
|
|
42
|
+
case CompilerOptions_1.LuaTarget.Lua50:
|
|
42
43
|
case CompilerOptions_1.LuaTarget.Lua51:
|
|
43
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations",
|
|
44
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
|
|
44
45
|
case CompilerOptions_1.LuaTarget.LuaJIT:
|
|
45
46
|
return transformBinaryBitLibOperation(node, left, right, operator, "bit");
|
|
46
47
|
case CompilerOptions_1.LuaTarget.Lua52:
|
|
@@ -65,8 +66,9 @@ function transformUnaryBitLibOperation(node, expression, operator, lib) {
|
|
|
65
66
|
function transformUnaryBitOperation(context, node, expression, operator) {
|
|
66
67
|
switch (context.luaTarget) {
|
|
67
68
|
case CompilerOptions_1.LuaTarget.Universal:
|
|
69
|
+
case CompilerOptions_1.LuaTarget.Lua50:
|
|
68
70
|
case CompilerOptions_1.LuaTarget.Lua51:
|
|
69
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations",
|
|
71
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
|
|
70
72
|
case CompilerOptions_1.LuaTarget.LuaJIT:
|
|
71
73
|
return transformUnaryBitLibOperation(node, expression, operator, "bit");
|
|
72
74
|
case CompilerOptions_1.LuaTarget.Lua52:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformBinaryExpressionStatement = exports.transformBinaryExpression = exports.transformBinaryOperation = exports.createShortCircuitBinaryExpressionPrecedingStatements = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const CompilerOptions_1 = require("../../../CompilerOptions");
|
|
5
6
|
const lua = require("../../../LuaAST");
|
|
6
7
|
const lua_ast_1 = require("../../utils/lua-ast");
|
|
7
8
|
const lualib_1 = require("../../utils/lualib");
|
|
@@ -42,6 +43,9 @@ function transformBinaryOperationWithNoPrecedingStatements(context, left, right,
|
|
|
42
43
|
(0, utils_1.assert)(ts.isBinaryExpression(node));
|
|
43
44
|
return transformNullishCoalescingOperationNoPrecedingStatements(context, node, left, right);
|
|
44
45
|
}
|
|
46
|
+
if (operator === ts.SyntaxKind.PercentToken && context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
47
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Modulo50, node, left, right);
|
|
48
|
+
}
|
|
45
49
|
let luaOperator = simpleOperatorsToLua[operator];
|
|
46
50
|
// Check if we need to use string concat operator
|
|
47
51
|
if (operator === ts.SyntaxKind.PlusToken && ts.isBinaryExpression(node)) {
|
|
@@ -12,8 +12,10 @@ const transformBreakStatement = (breakStatement, context) => {
|
|
|
12
12
|
exports.transformBreakStatement = transformBreakStatement;
|
|
13
13
|
const transformContinueStatement = (statement, context) => {
|
|
14
14
|
var _a;
|
|
15
|
-
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal ||
|
|
16
|
-
context.
|
|
15
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal ||
|
|
16
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
17
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51) {
|
|
18
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "Continue statement", context.luaTarget));
|
|
17
19
|
}
|
|
18
20
|
const scope = (0, scope_1.findScope)(context, scope_1.ScopeType.Loop);
|
|
19
21
|
if (scope) {
|
|
@@ -14,6 +14,7 @@ const fields_1 = require("./members/fields");
|
|
|
14
14
|
const method_1 = require("./members/method");
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
16
|
const setup_1 = require("./setup");
|
|
17
|
+
const CompilerOptions_1 = require("../../../CompilerOptions");
|
|
17
18
|
const transformClassDeclaration = (declaration, context) => {
|
|
18
19
|
// If declaration is a default export, transform to export variable assignment instead
|
|
19
20
|
if ((0, export_1.hasDefaultExportModifier)(declaration)) {
|
|
@@ -34,6 +35,7 @@ function transformClassAsExpression(expression, context) {
|
|
|
34
35
|
}
|
|
35
36
|
exports.transformClassAsExpression = transformClassAsExpression;
|
|
36
37
|
function transformClassLikeDeclaration(classDeclaration, context, nameOverride) {
|
|
38
|
+
var _a, _b;
|
|
37
39
|
let className;
|
|
38
40
|
if (nameOverride !== undefined) {
|
|
39
41
|
className = nameOverride;
|
|
@@ -79,10 +81,13 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
79
81
|
else if (instanceFields.length > 0) {
|
|
80
82
|
// Generate a constructor if none was defined in a class with instance fields that need initialization
|
|
81
83
|
// localClassName.prototype.____constructor = function(self, ...)
|
|
82
|
-
// baseClassName.prototype.____constructor(self, ...)
|
|
84
|
+
// baseClassName.prototype.____constructor(self, ...) // or unpack(arg) for Lua 5.0
|
|
83
85
|
// ...
|
|
84
86
|
const constructorBody = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
|
|
85
|
-
const
|
|
87
|
+
const argsExpression = context.luaTarget === CompilerOptions_1.LuaTarget.Lua50
|
|
88
|
+
? lua.createCallExpression(lua.createIdentifier("unpack"), [lua.createArgLiteral()])
|
|
89
|
+
: lua.createDotsLiteral();
|
|
90
|
+
const superCall = lua.createExpressionStatement(lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), [(0, lua_ast_1.createSelfIdentifier)(), argsExpression]));
|
|
86
91
|
constructorBody.unshift(superCall);
|
|
87
92
|
const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [(0, lua_ast_1.createSelfIdentifier)()], lua.createDotsLiteral(), lua.NodeFlags.Declaration);
|
|
88
93
|
result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
|
|
@@ -129,8 +134,8 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
129
134
|
}
|
|
130
135
|
result.push(...decorationStatements);
|
|
131
136
|
// Decorate the class
|
|
132
|
-
if (classDeclaration.
|
|
133
|
-
const decoratingExpression = (0, decorators_1.createDecoratingExpression)(context, classDeclaration.kind, classDeclaration.
|
|
137
|
+
if (ts.canHaveDecorators(classDeclaration) && ts.getDecorators(classDeclaration)) {
|
|
138
|
+
const decoratingExpression = (0, decorators_1.createDecoratingExpression)(context, classDeclaration.kind, (_b = (_a = ts.getDecorators(classDeclaration)) === null || _a === void 0 ? void 0 : _a.map(d => (0, decorators_1.transformDecoratorExpression)(context, d))) !== null && _b !== void 0 ? _b : [], localClassName);
|
|
134
139
|
const decoratingStatement = lua.createAssignmentStatement(localClassName, decoratingExpression);
|
|
135
140
|
result.push(decoratingStatement);
|
|
136
141
|
if ((0, export_1.hasExportModifier)(classDeclaration)) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformStaticPropertyDeclaration = exports.transformClassInstanceFields = exports.createPropertyDecoratingExpression = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
4
5
|
const lua = require("../../../../LuaAST");
|
|
5
6
|
const lua_ast_1 = require("../../../utils/lua-ast");
|
|
6
7
|
const preceding_statements_1 = require("../../../utils/preceding-statements");
|
|
@@ -8,11 +9,14 @@ const literal_1 = require("../../literal");
|
|
|
8
9
|
const decorators_1 = require("../decorators");
|
|
9
10
|
const method_1 = require("./method");
|
|
10
11
|
function createPropertyDecoratingExpression(context, node, className) {
|
|
11
|
-
if (!node
|
|
12
|
+
if (!ts.canHaveDecorators(node))
|
|
13
|
+
return;
|
|
14
|
+
const decorators = ts.getDecorators(node);
|
|
15
|
+
if (!decorators)
|
|
12
16
|
return;
|
|
13
17
|
const propertyName = (0, literal_1.transformPropertyName)(context, node.name);
|
|
14
18
|
const propertyOwnerTable = (0, method_1.transformMemberExpressionOwnerName)(node, className);
|
|
15
|
-
return (0, decorators_1.createDecoratingExpression)(context, node.kind,
|
|
19
|
+
return (0, decorators_1.createDecoratingExpression)(context, node.kind, decorators.map(d => (0, decorators_1.transformDecoratorExpression)(context, d)), propertyOwnerTable, propertyName);
|
|
16
20
|
}
|
|
17
21
|
exports.createPropertyDecoratingExpression = createPropertyDecoratingExpression;
|
|
18
22
|
function transformClassInstanceFields(context, instanceFields) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMethodDecoratingExpression = exports.transformMethodDeclaration = exports.transformMethodName = exports.transformMemberExpressionOwnerName = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
4
5
|
const lua = require("../../../../LuaAST");
|
|
5
6
|
const function_1 = require("../../function");
|
|
6
7
|
const literal_1 = require("../../literal");
|
|
@@ -38,10 +39,11 @@ function createMethodDecoratingExpression(context, node, className) {
|
|
|
38
39
|
const parameterDecorators = node.parameters
|
|
39
40
|
.flatMap((parameter, index) => {
|
|
40
41
|
var _a;
|
|
41
|
-
return (_a =
|
|
42
|
+
return (_a = ts
|
|
43
|
+
.getDecorators(parameter)) === null || _a === void 0 ? void 0 : _a.map(decorator => (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), (0, decorators_1.transformDecoratorExpression)(context, decorator)));
|
|
42
44
|
})
|
|
43
45
|
.filter(utils_2.isNonNull);
|
|
44
|
-
const methodDecorators = (_b = (_a = node
|
|
46
|
+
const methodDecorators = (_b = (_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.map(d => (0, decorators_1.transformDecoratorExpression)(context, d))) !== null && _b !== void 0 ? _b : [];
|
|
45
47
|
if (methodDecorators.length > 0 || parameterDecorators.length > 0) {
|
|
46
48
|
const decorateMethod = (0, decorators_1.createDecoratingExpression)(context, node.kind, [...methodDecorators, ...parameterDecorators], methodTable, methodName);
|
|
47
49
|
return lua.createExpressionStatement(decorateMethod);
|
|
@@ -15,7 +15,8 @@ const multi_1 = require("./language-extensions/multi");
|
|
|
15
15
|
const return_1 = require("./return");
|
|
16
16
|
const transformAsyncTry = (statement, context) => {
|
|
17
17
|
const [tryBlock] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
|
|
18
|
-
if (context.options.luaTarget === __1.LuaTarget.
|
|
18
|
+
if ((context.options.luaTarget === __1.LuaTarget.Lua50 || context.options.luaTarget === __1.LuaTarget.Lua51) &&
|
|
19
|
+
!context.options.lua51AllowTryCatchInAsyncAwait) {
|
|
19
20
|
context.diagnostics.push((0, diagnostics_1.unsupportedForTargetButOverrideAvailable)(statement, "try/catch inside async functions", __1.LuaTarget.Lua51, "lua51AllowTryCatchInAsyncAwait"));
|
|
20
21
|
return tryBlock.statements;
|
|
21
22
|
}
|
|
@@ -57,7 +58,8 @@ const transformTryStatement = (statement, context) => {
|
|
|
57
58
|
return transformAsyncTry(statement, context);
|
|
58
59
|
}
|
|
59
60
|
const [tryBlock, tryScope] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
|
|
60
|
-
if (context.options.luaTarget === __1.LuaTarget.
|
|
61
|
+
if ((context.options.luaTarget === __1.LuaTarget.Lua50 || context.options.luaTarget === __1.LuaTarget.Lua51) &&
|
|
62
|
+
(0, typescript_1.isInGeneratorFunction)(statement)) {
|
|
61
63
|
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "try/catch inside generator functions", __1.LuaTarget.Lua51));
|
|
62
64
|
return tryBlock.statements;
|
|
63
65
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformYieldExpression = exports.transformFunctionDeclaration = exports.transformFunctionLikeDeclaration = exports.transformFunctionToExpression = exports.transformParameters = exports.transformFunctionBody = exports.transformFunctionBodyHeader = exports.transformFunctionBodyContent = exports.isFunctionTypeWithProperties = exports.createCallableTable = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
5
6
|
const lua = require("../../LuaAST");
|
|
6
7
|
const utils_1 = require("../../utils");
|
|
7
8
|
const export_1 = require("../utils/export");
|
|
@@ -99,7 +100,7 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
99
100
|
}
|
|
100
101
|
// Push spread operator here
|
|
101
102
|
if (spreadIdentifier && isRestParameterReferenced(spreadIdentifier, bodyScope)) {
|
|
102
|
-
const spreadTable = (0, lua_ast_1.wrapInTable)(lua.createDotsLiteral());
|
|
103
|
+
const spreadTable = context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ? lua.createArgLiteral() : (0, lua_ast_1.wrapInTable)(lua.createDotsLiteral());
|
|
103
104
|
headerStatements.push(lua.createVariableDeclarationStatement(spreadIdentifier, spreadTable));
|
|
104
105
|
}
|
|
105
106
|
// Binding pattern statements need to be after spread table is declared
|
|
@@ -101,7 +101,8 @@ function transformUnaryOperator(context, node, kind) {
|
|
|
101
101
|
return lua.createUnaryExpression(context.transformExpression(arg), luaOperator);
|
|
102
102
|
}
|
|
103
103
|
function checkHasLua53(context, node, kind) {
|
|
104
|
-
const isBefore53 = context.luaTarget === CompilerOptions_1.LuaTarget.
|
|
104
|
+
const isBefore53 = context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
105
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
105
106
|
context.luaTarget === CompilerOptions_1.LuaTarget.Lua52 ||
|
|
106
107
|
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT ||
|
|
107
108
|
context.luaTarget === CompilerOptions_1.LuaTarget.Universal;
|
|
@@ -11,6 +11,7 @@ const typescript_1 = require("../utils/typescript");
|
|
|
11
11
|
const function_1 = require("./function");
|
|
12
12
|
const expression_list_1 = require("./expression-list");
|
|
13
13
|
const identifier_1 = require("./identifier");
|
|
14
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
14
15
|
// TODO: Move to object-literal.ts?
|
|
15
16
|
function transformPropertyName(context, node) {
|
|
16
17
|
if (ts.isComputedPropertyName(node)) {
|
|
@@ -31,11 +32,18 @@ function createShorthandIdentifier(context, valueSymbol, propertyIdentifier) {
|
|
|
31
32
|
return (0, identifier_1.transformIdentifierWithSymbol)(context, propertyIdentifier, valueSymbol);
|
|
32
33
|
}
|
|
33
34
|
exports.createShorthandIdentifier = createShorthandIdentifier;
|
|
34
|
-
const transformNumericLiteralExpression = expression => {
|
|
35
|
+
const transformNumericLiteralExpression = (expression, context) => {
|
|
35
36
|
if (expression.text === "Infinity") {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
38
|
+
const one = lua.createNumericLiteral(1);
|
|
39
|
+
const zero = lua.createNumericLiteral(0);
|
|
40
|
+
return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const math = lua.createIdentifier("math");
|
|
44
|
+
const huge = lua.createStringLiteral("huge");
|
|
45
|
+
return lua.createTableIndexExpression(math, huge, expression);
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
return lua.createNumericLiteral(Number(expression.text), expression);
|
|
41
49
|
};
|
|
@@ -80,7 +80,7 @@ function transformExportSpecifier(context, node) {
|
|
|
80
80
|
function transformExportSpecifiersFrom(context, statement, moduleSpecifier, exportSpecifiers) {
|
|
81
81
|
// First transpile as import clause
|
|
82
82
|
const importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(exportSpecifiers.map(s => ts.factory.createImportSpecifier(statement.isTypeOnly, s.propertyName, s.name))));
|
|
83
|
-
const importDeclaration = ts.factory.createImportDeclaration(statement.
|
|
83
|
+
const importDeclaration = ts.factory.createImportDeclaration(statement.modifiers, importClause, moduleSpecifier);
|
|
84
84
|
// Wrap in block to prevent imports from hoisting out of `do` statement
|
|
85
85
|
const [block] = (0, block_1.transformScopeBlock)(context, ts.factory.createBlock([importDeclaration]), scope_1.ScopeType.Block);
|
|
86
86
|
const result = block.statements;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformSpreadElement = exports.isOptimizedVarArgSpread = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
5
6
|
const lua = require("../../LuaAST");
|
|
6
7
|
const language_extensions_1 = require("../utils/language-extensions");
|
|
7
8
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
@@ -54,7 +55,9 @@ const transformSpreadElement = (node, context) => {
|
|
|
54
55
|
if (ts.isIdentifier(tsInnerExpression)) {
|
|
55
56
|
const symbol = context.checker.getSymbolAtLocation(tsInnerExpression);
|
|
56
57
|
if (symbol && isOptimizedVarArgSpread(context, symbol, tsInnerExpression)) {
|
|
57
|
-
return
|
|
58
|
+
return context.luaTarget === CompilerOptions_1.LuaTarget.Lua50
|
|
59
|
+
? (0, lua_ast_1.createUnpackCall)(context, lua.createArgLiteral(), node)
|
|
60
|
+
: lua.createDotsLiteral(node);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
const innerExpression = context.transformExpression(node.expression);
|
|
@@ -13,6 +13,7 @@ exports.typescriptVisitors = {
|
|
|
13
13
|
[ts.SyntaxKind.TypeAliasDeclaration]: () => undefined,
|
|
14
14
|
[ts.SyntaxKind.InterfaceDeclaration]: () => undefined,
|
|
15
15
|
[ts.SyntaxKind.NonNullExpression]: (node, context) => context.transformExpression(node.expression),
|
|
16
|
+
[ts.SyntaxKind.ExpressionWithTypeArguments]: (node, context) => context.transformExpression(node.expression),
|
|
16
17
|
[ts.SyntaxKind.AsExpression]: transformAssertionExpression,
|
|
17
18
|
[ts.SyntaxKind.TypeAssertionExpression]: transformAssertionExpression,
|
|
18
19
|
[ts.SyntaxKind.NotEmittedStatement]: () => undefined,
|
|
@@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getBundleResult = exports.printStackTraceBundleOverride = exports.sourceMapTracebackBundlePlaceholder = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const source_map_1 = require("source-map");
|
|
6
|
+
const CompilerOptions_1 = require("../CompilerOptions");
|
|
6
7
|
const LuaPrinter_1 = require("../LuaPrinter");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
8
9
|
const diagnostics_1 = require("./diagnostics");
|
|
9
10
|
const transpiler_1 = require("./transpiler");
|
|
10
11
|
const createModulePath = (pathToResolve, program) => (0, LuaPrinter_1.escapeString)((0, utils_1.formatPathToLuaPath)((0, utils_1.trimExtension)((0, transpiler_1.getEmitPathRelativeToOutDir)(pathToResolve, program))));
|
|
11
12
|
// Override `require` to read from ____modules table.
|
|
12
|
-
|
|
13
|
+
function requireOverride(options) {
|
|
14
|
+
const runModule = options.luaTarget === CompilerOptions_1.LuaTarget.Lua50
|
|
15
|
+
? "(table.getn(arg) > 0) and module(unpack(arg)) or module(file)"
|
|
16
|
+
: '(select("#", ...) > 0) and module(...) or module(file)';
|
|
17
|
+
return `
|
|
13
18
|
local ____modules = {}
|
|
14
19
|
local ____moduleCache = {}
|
|
15
20
|
local ____originalRequire = require
|
|
@@ -19,7 +24,7 @@ local function require(file, ...)
|
|
|
19
24
|
end
|
|
20
25
|
if ____modules[file] then
|
|
21
26
|
local module = ____modules[file]
|
|
22
|
-
____moduleCache[file] = { value =
|
|
27
|
+
____moduleCache[file] = { value = ${runModule} }
|
|
23
28
|
return ____moduleCache[file].value
|
|
24
29
|
else
|
|
25
30
|
if ____originalRequire then
|
|
@@ -30,6 +35,7 @@ local function require(file, ...)
|
|
|
30
35
|
end
|
|
31
36
|
end
|
|
32
37
|
`;
|
|
38
|
+
}
|
|
33
39
|
exports.sourceMapTracebackBundlePlaceholder = "{#SourceMapTracebackBundle}";
|
|
34
40
|
function printStackTraceBundleOverride(rootNode) {
|
|
35
41
|
const map = {};
|
|
@@ -83,14 +89,15 @@ function getBundleResult(program, files) {
|
|
|
83
89
|
// Create ____modules table containing all entries from moduleTableEntries
|
|
84
90
|
const moduleTable = createModuleTableNode(moduleTableEntries);
|
|
85
91
|
// return require("<entry module path>")
|
|
86
|
-
const
|
|
92
|
+
const args = options.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ? "unpack(arg == nil and {} or arg)" : "...";
|
|
93
|
+
const entryPoint = `return require(${createModulePath(entryModuleFilePath !== null && entryModuleFilePath !== void 0 ? entryModuleFilePath : entryModule, program)}, ${args})\n`;
|
|
87
94
|
const footers = [];
|
|
88
95
|
if (options.sourceMapTraceback) {
|
|
89
96
|
// Generates SourceMapTraceback for the entire file
|
|
90
97
|
footers.push('local __TS__SourceMapTraceBack = require("lualib_bundle").__TS__SourceMapTraceBack\n');
|
|
91
98
|
footers.push(`${exports.sourceMapTracebackBundlePlaceholder}\n`);
|
|
92
99
|
}
|
|
93
|
-
const sourceChunks = [requireOverride, moduleTable, ...footers, entryPoint];
|
|
100
|
+
const sourceChunks = [requireOverride(options), moduleTable, ...footers, entryPoint];
|
|
94
101
|
if (!options.noHeader) {
|
|
95
102
|
sourceChunks.unshift(LuaPrinter_1.tstlHeader);
|
|
96
103
|
}
|
|
@@ -61,6 +61,7 @@ class Transpiler {
|
|
|
61
61
|
return diagnostics;
|
|
62
62
|
}
|
|
63
63
|
getEmitPlan(program, diagnostics, files) {
|
|
64
|
+
var _a;
|
|
64
65
|
performance.startSection("getEmitPlan");
|
|
65
66
|
const options = program.getCompilerOptions();
|
|
66
67
|
if (options.tstlVerbose) {
|
|
@@ -78,7 +79,8 @@ class Transpiler {
|
|
|
78
79
|
}
|
|
79
80
|
// Add lualib bundle to source dir 'virtually', will be moved to correct output dir in emitPlan
|
|
80
81
|
const fileName = (0, utils_1.normalizeSlashes)(path.resolve(getSourceDir(program), "lualib_bundle.lua"));
|
|
81
|
-
|
|
82
|
+
const luaTarget = (_a = options.luaTarget) !== null && _a !== void 0 ? _a : CompilerOptions_1.LuaTarget.Universal;
|
|
83
|
+
resolutionResult.resolvedFiles.unshift({ fileName, code: (0, LuaLib_1.getLuaLibBundle)(luaTarget, this.emitHost) });
|
|
82
84
|
}
|
|
83
85
|
let emitPlan;
|
|
84
86
|
if ((0, CompilerOptions_1.isBundleEnabled)(options)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0-beta.0",
|
|
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/",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
"dist/**/*.js",
|
|
19
19
|
"dist/**/*.lua",
|
|
20
20
|
"dist/**/*.ts",
|
|
21
|
-
"dist/lualib
|
|
22
|
-
"language-extensions/**/*.ts"
|
|
21
|
+
"dist/lualib/**/*.json"
|
|
23
22
|
],
|
|
24
23
|
"main": "dist/index.js",
|
|
25
24
|
"types": "dist/index.d.ts",
|
|
26
25
|
"scripts": {
|
|
27
26
|
"build": "tsc && npm run build-lualib",
|
|
28
|
-
"build-lualib": "node dist/tstl.js -p src/lualib/tsconfig.json",
|
|
27
|
+
"build-lualib": "node dist/tstl.js -p src/lualib/tsconfig.json && node dist/tstl.js -p src/lualib/tsconfig.lua50.json",
|
|
29
28
|
"pretest": "npm run lint && npm run check:language-extensions && npm run build-lualib",
|
|
30
29
|
"test": "jest",
|
|
31
30
|
"lint": "npm run lint:eslint && npm run lint:prettier",
|
|
32
31
|
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
|
|
33
32
|
"lint:eslint": "eslint . --ext .js,.ts",
|
|
34
33
|
"fix:prettier": "prettier --write .",
|
|
35
|
-
"check:language-extensions": "tsc language-extensions/index.d.ts",
|
|
34
|
+
"check:language-extensions": "tsc --strict language-extensions/index.d.ts",
|
|
36
35
|
"preversion": "npm run build && npm test",
|
|
37
36
|
"postversion": "git push && git push --tags"
|
|
38
37
|
},
|
|
@@ -40,12 +39,13 @@
|
|
|
40
39
|
"tstl": "dist/tstl.js"
|
|
41
40
|
},
|
|
42
41
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
42
|
+
"node": ">=16.10.0"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"typescript": "~4.
|
|
45
|
+
"typescript": "~4.8.2"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
48
|
+
"@typescript-to-lua/language-extensions": "1.0.0",
|
|
49
49
|
"enhanced-resolve": "^5.8.2",
|
|
50
50
|
"resolve": "^1.15.1",
|
|
51
51
|
"source-map": "^0.7.3"
|
|
@@ -56,20 +56,20 @@
|
|
|
56
56
|
"@types/jest": "^27.5.2",
|
|
57
57
|
"@types/node": "^13.7.7",
|
|
58
58
|
"@types/resolve": "1.14.0",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"eslint": "^8.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
60
|
+
"@typescript-eslint/parser": "^5.36.1",
|
|
61
|
+
"eslint": "^8.23.0",
|
|
62
62
|
"eslint-plugin-import": "^2.26.0",
|
|
63
|
-
"eslint-plugin-jest": "^26.
|
|
63
|
+
"eslint-plugin-jest": "^26.8.7",
|
|
64
64
|
"fs-extra": "^8.1.0",
|
|
65
65
|
"javascript-stringify": "^2.0.1",
|
|
66
|
-
"jest": "^
|
|
67
|
-
"jest-circus": "^
|
|
68
|
-
"lua-types": "^2.
|
|
69
|
-
"lua-wasm-bindings": "^0.
|
|
66
|
+
"jest": "^28.1.3",
|
|
67
|
+
"jest-circus": "^29.0.1",
|
|
68
|
+
"lua-types": "^2.13.0-beta.0",
|
|
69
|
+
"lua-wasm-bindings": "^0.3.1",
|
|
70
70
|
"prettier": "^2.3.2",
|
|
71
|
-
"ts-jest": "^
|
|
72
|
-
"ts-node": "^10.
|
|
73
|
-
"typescript": "~4.
|
|
71
|
+
"ts-jest": "^28.0.8",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"typescript": "~4.8.2"
|
|
74
74
|
}
|
|
75
75
|
}
|