typescript-to-lua 1.8.2 → 1.10.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/{ArrayEntries.lua → 5.0/ArrayEntries.lua} +0 -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/{ArrayIsArray.lua → 5.0/ArrayIsArray.lua} +0 -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/{ArraySort.lua → 5.0/ArraySort.lua} +0 -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/{Await.lua → 5.0/Await.lua} +0 -0
- package/dist/lualib/{Class.lua → 5.0/Class.lua} +0 -0
- package/dist/lualib/{ClassExtends.lua → 5.0/ClassExtends.lua} +0 -0
- package/dist/lualib/{CloneDescriptor.lua → 5.0/CloneDescriptor.lua} +0 -0
- package/dist/lualib/5.0/CountVarargs.lua +4 -0
- package/dist/lualib/5.0/Decorate.lua +36 -0
- package/dist/lualib/{DecorateParam.lua → 5.0/DecorateParam.lua} +0 -0
- package/dist/lualib/5.0/DelegatedYield.lua +34 -0
- package/dist/lualib/{Delete.lua → 5.0/Delete.lua} +0 -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/{InstanceOf.lua → 5.0/InstanceOf.lua} +0 -0
- package/dist/lualib/{InstanceOfObject.lua → 5.0/InstanceOfObject.lua} +0 -0
- package/dist/lualib/5.0/Iterator.lua +40 -0
- package/dist/lualib/5.0/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/{Map.lua → 5.0/Map.lua} +0 -0
- package/dist/lualib/5.0/Match.lua +13 -0
- package/dist/lualib/{MathAtan2.lua → 5.0/MathAtan2.lua} +0 -0
- package/dist/lualib/5.0/MathModf.lua +10 -0
- package/dist/lualib/{MathSign.lua → 5.0/MathSign.lua} +0 -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/{NumberIsNaN.lua → 5.0/NumberIsNaN.lua} +0 -0
- package/dist/lualib/5.0/NumberToString.lua +47 -0
- package/dist/lualib/5.0/ObjectAssign.lua +10 -0
- package/dist/lualib/{ObjectDefineProperty.lua → 5.0/ObjectDefineProperty.lua} +0 -0
- package/dist/lualib/{ObjectEntries.lua → 5.0/ObjectEntries.lua} +0 -0
- package/dist/lualib/{ObjectFromEntries.lua → 5.0/ObjectFromEntries.lua} +0 -0
- package/dist/lualib/{ObjectGetOwnPropertyDescriptor.lua → 5.0/ObjectGetOwnPropertyDescriptor.lua} +0 -0
- package/dist/lualib/{ObjectGetOwnPropertyDescriptors.lua → 5.0/ObjectGetOwnPropertyDescriptors.lua} +0 -0
- package/dist/lualib/{ObjectKeys.lua → 5.0/ObjectKeys.lua} +0 -0
- package/dist/lualib/{ObjectRest.lua → 5.0/ObjectRest.lua} +0 -0
- package/dist/lualib/{ObjectValues.lua → 5.0/ObjectValues.lua} +0 -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/{PromiseAll.lua → 5.0/PromiseAll.lua} +0 -0
- package/dist/lualib/{PromiseAllSettled.lua → 5.0/PromiseAllSettled.lua} +0 -0
- package/dist/lualib/5.0/PromiseAny.lua +41 -0
- package/dist/lualib/5.0/PromiseRace.lua +28 -0
- package/dist/lualib/{Set.lua → 5.0/Set.lua} +0 -0
- package/dist/lualib/{SetDescriptor.lua → 5.0/SetDescriptor.lua} +0 -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/{StringCharAt.lua → 5.0/StringCharAt.lua} +0 -0
- package/dist/lualib/{StringCharCodeAt.lua → 5.0/StringCharCodeAt.lua} +0 -0
- package/dist/lualib/5.0/StringEndsWith.lua +10 -0
- package/dist/lualib/{StringIncludes.lua → 5.0/StringIncludes.lua} +0 -0
- package/dist/lualib/5.0/StringPadEnd.lua +26 -0
- package/dist/lualib/5.0/StringPadStart.lua +26 -0
- package/dist/lualib/{StringReplace.lua → 5.0/StringReplace.lua} +0 -0
- package/dist/lualib/5.0/StringReplaceAll.lua +42 -0
- package/dist/lualib/{StringSlice.lua → 5.0/StringSlice.lua} +0 -0
- package/dist/lualib/5.0/StringSplit.lua +36 -0
- package/dist/lualib/5.0/StringStartsWith.lua +10 -0
- package/dist/lualib/{StringSubstr.lua → 5.0/StringSubstr.lua} +0 -0
- package/dist/lualib/{StringSubstring.lua → 5.0/StringSubstring.lua} +0 -0
- package/dist/lualib/{StringTrim.lua → 5.0/StringTrim.lua} +0 -0
- package/dist/lualib/{StringTrimEnd.lua → 5.0/StringTrimEnd.lua} +0 -0
- package/dist/lualib/{StringTrimStart.lua → 5.0/StringTrimStart.lua} +0 -0
- package/dist/lualib/{Symbol.lua → 5.0/Symbol.lua} +0 -0
- package/dist/lualib/{SymbolRegistry.lua → 5.0/SymbolRegistry.lua} +0 -0
- package/dist/lualib/{TypeOf.lua → 5.0/TypeOf.lua} +0 -0
- package/dist/lualib/5.0/Unpack.lua +1 -0
- package/dist/lualib/{WeakMap.lua → 5.0/WeakMap.lua} +0 -0
- package/dist/lualib/{WeakSet.lua → 5.0/WeakSet.lua} +0 -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/{ArrayConcat.lua → universal/ArrayConcat.lua} +0 -0
- package/dist/lualib/universal/ArrayEntries.lua +13 -0
- package/dist/lualib/{ArrayEvery.lua → universal/ArrayEvery.lua} +0 -0
- package/dist/lualib/{ArrayFilter.lua → universal/ArrayFilter.lua} +0 -0
- package/dist/lualib/{ArrayFind.lua → universal/ArrayFind.lua} +0 -0
- package/dist/lualib/{ArrayFindIndex.lua → universal/ArrayFindIndex.lua} +0 -0
- package/dist/lualib/{ArrayFlat.lua → universal/ArrayFlat.lua} +0 -0
- package/dist/lualib/{ArrayFlatMap.lua → universal/ArrayFlatMap.lua} +0 -0
- package/dist/lualib/{ArrayForEach.lua → universal/ArrayForEach.lua} +0 -0
- package/dist/lualib/{ArrayFrom.lua → universal/ArrayFrom.lua} +0 -0
- package/dist/lualib/{ArrayIncludes.lua → universal/ArrayIncludes.lua} +0 -0
- package/dist/lualib/{ArrayIndexOf.lua → universal/ArrayIndexOf.lua} +0 -0
- package/dist/lualib/universal/ArrayIsArray.lua +3 -0
- package/dist/lualib/{ArrayJoin.lua → universal/ArrayJoin.lua} +0 -0
- package/dist/lualib/{ArrayMap.lua → universal/ArrayMap.lua} +0 -0
- package/dist/lualib/{ArrayPush.lua → universal/ArrayPush.lua} +0 -0
- package/dist/lualib/{ArrayPushArray.lua → universal/ArrayPushArray.lua} +0 -0
- package/dist/lualib/{ArrayReduce.lua → universal/ArrayReduce.lua} +1 -1
- package/dist/lualib/{ArrayReduceRight.lua → universal/ArrayReduceRight.lua} +1 -1
- package/dist/lualib/{ArrayReverse.lua → universal/ArrayReverse.lua} +0 -0
- package/dist/lualib/{ArraySetLength.lua → universal/ArraySetLength.lua} +0 -0
- package/dist/lualib/{ArraySlice.lua → universal/ArraySlice.lua} +0 -0
- package/dist/lualib/{ArraySome.lua → universal/ArraySome.lua} +0 -0
- package/dist/lualib/universal/ArraySort.lua +11 -0
- package/dist/lualib/{ArraySplice.lua → universal/ArraySplice.lua} +1 -1
- package/dist/lualib/{ArrayToObject.lua → universal/ArrayToObject.lua} +0 -0
- package/dist/lualib/{ArrayUnshift.lua → universal/ArrayUnshift.lua} +0 -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/{Decorate.lua → universal/Decorate.lua} +0 -0
- package/dist/lualib/universal/DecorateParam.lua +3 -0
- package/dist/lualib/{DelegatedYield.lua → universal/DelegatedYield.lua} +0 -0
- package/dist/lualib/universal/Delete.lua +19 -0
- package/dist/lualib/{Error.lua → universal/Error.lua} +7 -2
- package/dist/lualib/{FunctionBind.lua → universal/FunctionBind.lua} +0 -0
- package/dist/lualib/{Generator.lua → universal/Generator.lua} +2 -9
- package/dist/lualib/universal/InstanceOf.lua +18 -0
- package/dist/lualib/universal/InstanceOfObject.lua +4 -0
- package/dist/lualib/{Iterator.lua → universal/Iterator.lua} +0 -0
- package/dist/lualib/{LuaIteratorSpread.lua → universal/LuaIteratorSpread.lua} +0 -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/{New.lua → universal/New.lua} +0 -0
- package/dist/lualib/{Number.lua → universal/Number.lua} +0 -0
- package/dist/lualib/{NumberIsFinite.lua → universal/NumberIsFinite.lua} +0 -0
- package/dist/lualib/universal/NumberIsNaN.lua +3 -0
- package/dist/lualib/{NumberToString.lua → universal/NumberToString.lua} +1 -1
- package/dist/lualib/{ObjectAssign.lua → universal/ObjectAssign.lua} +0 -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/{ParseFloat.lua → universal/ParseFloat.lua} +2 -2
- package/dist/lualib/{ParseInt.lua → universal/ParseInt.lua} +7 -7
- package/dist/lualib/{Promise.lua → universal/Promise.lua} +0 -0
- package/dist/lualib/universal/PromiseAll.lua +44 -0
- package/dist/lualib/universal/PromiseAllSettled.lua +48 -0
- package/dist/lualib/{PromiseAny.lua → universal/PromiseAny.lua} +0 -0
- package/dist/lualib/{PromiseRace.lua → universal/PromiseRace.lua} +0 -0
- package/dist/lualib/universal/Set.lua +130 -0
- package/dist/lualib/universal/SetDescriptor.lua +79 -0
- package/dist/lualib/{SourceMapTraceBack.lua → universal/SourceMapTraceBack.lua} +3 -1
- package/dist/lualib/{SparseArrayNew.lua → universal/SparseArrayNew.lua} +1 -1
- package/dist/lualib/{SparseArrayPush.lua → universal/SparseArrayPush.lua} +1 -1
- package/dist/lualib/{SparseArraySpread.lua → universal/SparseArraySpread.lua} +0 -0
- package/dist/lualib/{Spread.lua → universal/Spread.lua} +0 -0
- package/dist/lualib/{StringAccess.lua → universal/StringAccess.lua} +0 -0
- package/dist/lualib/universal/StringCharAt.lua +9 -0
- package/dist/lualib/universal/StringCharCodeAt.lua +13 -0
- package/dist/lualib/{StringEndsWith.lua → universal/StringEndsWith.lua} +0 -0
- package/dist/lualib/universal/StringIncludes.lua +9 -0
- package/dist/lualib/{StringPadEnd.lua → universal/StringPadEnd.lua} +0 -0
- package/dist/lualib/{StringPadStart.lua → universal/StringPadStart.lua} +0 -0
- package/dist/lualib/universal/StringReplace.lua +20 -0
- package/dist/lualib/{StringReplaceAll.lua → universal/StringReplaceAll.lua} +0 -0
- package/dist/lualib/universal/StringSlice.lua +15 -0
- package/dist/lualib/{StringSplit.lua → universal/StringSplit.lua} +0 -0
- package/dist/lualib/{StringStartsWith.lua → universal/StringStartsWith.lua} +0 -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/{Unpack.lua → universal/Unpack.lua} +0 -0
- package/dist/lualib/universal/WeakMap.lua +45 -0
- package/dist/lualib/universal/WeakSet.lua +41 -0
- package/dist/lualib/{lualib_bundle.lua → universal/lualib_bundle.lua} +53 -37
- package/dist/lualib/{lualib_module_info.json → universal/lualib_module_info.json} +49 -4
- 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 +5 -4
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/lua-ast.js +3 -1
- package/dist/transformation/utils/typescript/index.js +2 -2
- package/dist/transformation/visitors/access.js +11 -0
- 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/conditional.d.ts +1 -0
- package/dist/transformation/visitors/conditional.js +12 -1
- package/dist/transformation/visitors/errors.js +4 -2
- package/dist/transformation/visitors/function.js +2 -1
- package/dist/transformation/visitors/identifier.js +4 -1
- package/dist/transformation/visitors/language-extensions/operators.js +2 -1
- package/dist/transformation/visitors/literal.js +12 -4
- package/dist/transformation/visitors/loops/do-while.js +5 -0
- 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 +15 -6
- package/dist/transpilation/resolve.js +3 -3
- package/dist/transpilation/transpiler.js +3 -1
- package/package.json +18 -18
- package/language-extensions/index.d.ts +0 -676
|
@@ -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);
|
|
@@ -3,3 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
4
|
export declare const transformConditionalExpression: FunctionVisitor<ts.ConditionalExpression>;
|
|
5
5
|
export declare function transformIfStatement(statement: ts.IfStatement, context: TransformationContext): lua.IfStatement;
|
|
6
|
+
export declare function checkOnlyTruthyCondition(condition: ts.Expression, context: TransformationContext): void;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformIfStatement = exports.transformConditionalExpression = void 0;
|
|
3
|
+
exports.checkOnlyTruthyCondition = exports.transformIfStatement = exports.transformConditionalExpression = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
7
7
|
const scope_1 = require("../utils/scope");
|
|
8
8
|
const block_1 = require("./block");
|
|
9
9
|
const typescript_1 = require("../utils/typescript");
|
|
10
|
+
const diagnostics_1 = require("../utils/diagnostics");
|
|
10
11
|
function transformProtectedConditionalExpression(context, expression, condition, whenTrue, whenFalse) {
|
|
11
12
|
const tempVar = context.createTempNameForNode(expression.condition);
|
|
12
13
|
const trueStatements = whenTrue[0].concat(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), whenTrue[1], expression.whenTrue));
|
|
@@ -19,6 +20,8 @@ function transformProtectedConditionalExpression(context, expression, condition,
|
|
|
19
20
|
return lua.cloneIdentifier(tempVar);
|
|
20
21
|
}
|
|
21
22
|
const transformConditionalExpression = (expression, context) => {
|
|
23
|
+
// Check if we need to add diagnostic about Lua truthiness
|
|
24
|
+
checkOnlyTruthyCondition(expression.condition, context);
|
|
22
25
|
const condition = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.condition));
|
|
23
26
|
const whenTrue = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenTrue));
|
|
24
27
|
const whenFalse = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.whenFalse));
|
|
@@ -35,6 +38,8 @@ const transformConditionalExpression = (expression, context) => {
|
|
|
35
38
|
exports.transformConditionalExpression = transformConditionalExpression;
|
|
36
39
|
function transformIfStatement(statement, context) {
|
|
37
40
|
context.pushScope(scope_1.ScopeType.Conditional);
|
|
41
|
+
// Check if we need to add diagnostic about Lua truthiness
|
|
42
|
+
checkOnlyTruthyCondition(statement.expression, context);
|
|
38
43
|
const condition = context.transformExpression(statement.expression);
|
|
39
44
|
const statements = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, statement.thenStatement));
|
|
40
45
|
context.popScope();
|
|
@@ -70,4 +75,10 @@ function transformIfStatement(statement, context) {
|
|
|
70
75
|
return lua.createIfStatement(condition, ifBlock);
|
|
71
76
|
}
|
|
72
77
|
exports.transformIfStatement = transformIfStatement;
|
|
78
|
+
function checkOnlyTruthyCondition(condition, context) {
|
|
79
|
+
if (!(0, typescript_1.canBeFalsy)(context, context.checker.getTypeAtLocation(condition))) {
|
|
80
|
+
context.diagnostics.push((0, diagnostics_1.truthyOnlyConditionalValue)(condition));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.checkOnlyTruthyCondition = checkOnlyTruthyCondition;
|
|
73
84
|
//# sourceMappingURL=conditional.js.map
|
|
@@ -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
|
|
@@ -28,7 +28,10 @@ function transformNonValueIdentifier(context, identifier, symbol) {
|
|
|
28
28
|
: (0, language_extensions_1.getExtensionKindForNode)(context, identifier);
|
|
29
29
|
if (extensionKind) {
|
|
30
30
|
if (call_extension_1.callExtensions.has(extensionKind)) {
|
|
31
|
-
|
|
31
|
+
// Avoid putting duplicate diagnostic on the name of a variable declaration, due to the inferred type
|
|
32
|
+
if (!(ts.isVariableDeclaration(identifier.parent) && identifier.parent.name === identifier)) {
|
|
33
|
+
context.diagnostics.push((0, diagnostics_1.invalidCallExtensionUse)(identifier));
|
|
34
|
+
}
|
|
32
35
|
// fall through
|
|
33
36
|
}
|
|
34
37
|
else if ((0, identifier_1.isIdentifierExtensionValue)(symbol, extensionKind)) {
|
|
@@ -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
|
};
|
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformDoStatement = exports.transformWhileStatement = void 0;
|
|
4
4
|
const lua = require("../../../LuaAST");
|
|
5
5
|
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
6
|
+
const conditional_1 = require("../conditional");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
const transformWhileStatement = (statement, context) => {
|
|
9
|
+
// Check if we need to add diagnostic about Lua truthiness
|
|
10
|
+
(0, conditional_1.checkOnlyTruthyCondition)(statement.expression, context);
|
|
8
11
|
const body = (0, utils_1.transformLoopBody)(context, statement);
|
|
9
12
|
let [conditionPrecedingStatements, condition] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(statement.expression));
|
|
10
13
|
// If condition has preceding statements, ensure they are executed every iteration by using the form:
|
|
@@ -25,6 +28,8 @@ const transformWhileStatement = (statement, context) => {
|
|
|
25
28
|
};
|
|
26
29
|
exports.transformWhileStatement = transformWhileStatement;
|
|
27
30
|
const transformDoStatement = (statement, context) => {
|
|
31
|
+
// Check if we need to add diagnostic about Lua truthiness
|
|
32
|
+
(0, conditional_1.checkOnlyTruthyCondition)(statement.expression, context);
|
|
28
33
|
const body = lua.createDoStatement((0, utils_1.transformLoopBody)(context, statement));
|
|
29
34
|
let [conditionPrecedingStatements, condition] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, utils_1.invertCondition)(context.transformExpression(statement.expression)));
|
|
30
35
|
// If condition has preceding statements, ensure they are executed every iteration by using the form:
|
|
@@ -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 = {};
|
|
@@ -66,14 +72,16 @@ function printStackTraceBundleOverride(rootNode) {
|
|
|
66
72
|
}
|
|
67
73
|
exports.printStackTraceBundleOverride = printStackTraceBundleOverride;
|
|
68
74
|
function getBundleResult(program, files) {
|
|
75
|
+
var _a, _b, _c;
|
|
69
76
|
const diagnostics = [];
|
|
70
77
|
const options = program.getCompilerOptions();
|
|
71
78
|
const bundleFile = (0, utils_1.cast)(options.luaBundle, utils_1.isNonNull);
|
|
72
79
|
const entryModule = (0, utils_1.cast)(options.luaBundleEntry, utils_1.isNonNull);
|
|
73
80
|
// Resolve project settings relative to project file.
|
|
74
|
-
const resolvedEntryModule = path.resolve((0, transpiler_1.
|
|
81
|
+
const resolvedEntryModule = path.resolve((0, transpiler_1.getProjectRoot)(program), entryModule);
|
|
75
82
|
const outputPath = path.resolve((0, transpiler_1.getEmitOutDir)(program), bundleFile);
|
|
76
|
-
|
|
83
|
+
const entryModuleFilePath = (_b = (_a = program.getSourceFile(entryModule)) === null || _a === void 0 ? void 0 : _a.fileName) !== null && _b !== void 0 ? _b : (_c = program.getSourceFile(resolvedEntryModule)) === null || _c === void 0 ? void 0 : _c.fileName;
|
|
84
|
+
if (entryModuleFilePath === undefined) {
|
|
77
85
|
diagnostics.push((0, diagnostics_1.couldNotFindBundleEntryPoint)(entryModule));
|
|
78
86
|
}
|
|
79
87
|
// For each file: ["<module path>"] = function() <lua content> end,
|
|
@@ -81,14 +89,15 @@ function getBundleResult(program, files) {
|
|
|
81
89
|
// Create ____modules table containing all entries from moduleTableEntries
|
|
82
90
|
const moduleTable = createModuleTableNode(moduleTableEntries);
|
|
83
91
|
// return require("<entry module path>")
|
|
84
|
-
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`;
|
|
85
94
|
const footers = [];
|
|
86
95
|
if (options.sourceMapTraceback) {
|
|
87
96
|
// Generates SourceMapTraceback for the entire file
|
|
88
97
|
footers.push('local __TS__SourceMapTraceBack = require("lualib_bundle").__TS__SourceMapTraceBack\n');
|
|
89
98
|
footers.push(`${exports.sourceMapTracebackBundlePlaceholder}\n`);
|
|
90
99
|
}
|
|
91
|
-
const sourceChunks = [requireOverride, moduleTable, ...footers, entryPoint];
|
|
100
|
+
const sourceChunks = [requireOverride(options), moduleTable, ...footers, entryPoint];
|
|
92
101
|
if (!options.noHeader) {
|
|
93
102
|
sourceChunks.unshift(LuaPrinter_1.tstlHeader);
|
|
94
103
|
}
|
|
@@ -260,11 +260,11 @@ function isBuildModeLibrary(program) {
|
|
|
260
260
|
function findRequiredPaths(code) {
|
|
261
261
|
// Find all require("<path>") paths in a lua code string
|
|
262
262
|
const paths = [];
|
|
263
|
-
const pattern = /(^|\s|;|=|\()require\("(.+?)
|
|
263
|
+
const pattern = /(^|\s|;|=|\()require\s*\(?(["|'])(.+?)\2\)?/g;
|
|
264
264
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
265
265
|
let match;
|
|
266
266
|
while ((match = pattern.exec(code))) {
|
|
267
|
-
paths.push(match[
|
|
267
|
+
paths.push(match[3]);
|
|
268
268
|
}
|
|
269
269
|
return paths;
|
|
270
270
|
}
|
|
@@ -272,7 +272,7 @@ function replaceRequireInCode(file, originalRequire, newRequire) {
|
|
|
272
272
|
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
273
273
|
// Escape special characters to prevent the regex from breaking...
|
|
274
274
|
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
275
|
-
file.code = file.code.replace(new RegExp(`(^|\\s|;|=|\\()require\\("${escapedRequire}"\\)
|
|
275
|
+
file.code = file.code.replace(new RegExp(`(^|\\s|;|=|\\()require\\s*\\(?["|']${escapedRequire}["|']\\)?`), `$1require("${requirePath}")`);
|
|
276
276
|
}
|
|
277
277
|
function replaceRequireInSourceMap(file, originalRequire, newRequire) {
|
|
278
278
|
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
@@ -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",
|
|
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",
|
|
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
|
}
|