typescript-to-lua 1.8.1 → 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 +28 -10
- 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/multi.js +3 -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/return.js +12 -7
- 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/transpiler.js +3 -1
- package/package.json +18 -18
- package/language-extensions/index.d.ts +0 -676
|
@@ -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;
|
|
@@ -12,28 +12,33 @@ const diagnostics_1 = require("../utils/diagnostics");
|
|
|
12
12
|
const typescript_1 = require("../utils/typescript");
|
|
13
13
|
function transformExpressionsInReturn(context, node, insideTryCatch) {
|
|
14
14
|
const expressionType = context.checker.getTypeAtLocation(node);
|
|
15
|
-
|
|
15
|
+
// skip type assertions
|
|
16
|
+
// don't skip parenthesis as it may arise confusion with lua behavior (where parenthesis are significant)
|
|
17
|
+
const innerNode = ts.skipOuterExpressions(node, ts.OuterExpressionKinds.Assertions);
|
|
18
|
+
if (ts.isCallExpression(innerNode)) {
|
|
16
19
|
// $multi(...)
|
|
17
|
-
if ((0, multi_1.isMultiFunctionCall)(context,
|
|
20
|
+
if ((0, multi_1.isMultiFunctionCall)(context, innerNode)) {
|
|
18
21
|
// Don't allow $multi to be implicitly cast to something other than LuaMultiReturn
|
|
19
22
|
const type = context.checker.getContextualType(node);
|
|
20
23
|
if (type && !(0, multi_1.canBeMultiReturnType)(type)) {
|
|
21
|
-
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionReturnType)(
|
|
24
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionReturnType)(innerNode));
|
|
22
25
|
}
|
|
23
|
-
let returnValues = (0, call_1.transformArguments)(context,
|
|
26
|
+
let returnValues = (0, call_1.transformArguments)(context, innerNode.arguments);
|
|
24
27
|
if (insideTryCatch) {
|
|
25
28
|
returnValues = [(0, lua_ast_1.wrapInTable)(...returnValues)]; // Wrap results when returning inside try/catch
|
|
26
29
|
}
|
|
27
30
|
return returnValues;
|
|
28
31
|
}
|
|
29
32
|
// Force-wrap LuaMultiReturn when returning inside try/catch
|
|
30
|
-
if (insideTryCatch &&
|
|
33
|
+
if (insideTryCatch &&
|
|
34
|
+
(0, multi_1.returnsMultiType)(context, innerNode) &&
|
|
35
|
+
!(0, multi_1.shouldMultiReturnCallBeWrapped)(context, innerNode)) {
|
|
31
36
|
return [(0, lua_ast_1.wrapInTable)(context.transformExpression(node))];
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
|
-
else if ((0, multi_1.isInMultiReturnFunction)(context,
|
|
39
|
+
else if ((0, multi_1.isInMultiReturnFunction)(context, innerNode) && (0, multi_1.isMultiReturnType)(expressionType)) {
|
|
35
40
|
// Unpack objects typed as LuaMultiReturn
|
|
36
|
-
return [(0, lua_ast_1.createUnpackCall)(context, context.transformExpression(
|
|
41
|
+
return [(0, lua_ast_1.createUnpackCall)(context, context.transformExpression(innerNode), innerNode)];
|
|
37
42
|
}
|
|
38
43
|
return [context.transformExpression(node)];
|
|
39
44
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|