typescript-to-lua 1.6.0 → 1.6.3
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/LuaPrinter.js +1 -0
- package/dist/cli/diagnostics.d.ts +3 -0
- package/dist/cli/diagnostics.js +2 -1
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +42 -11
- package/dist/lualib/Map.lua +4 -6
- package/dist/lualib/Promise.lua +6 -3
- package/dist/lualib/lualib_bundle.lua +10 -9
- package/dist/transformation/utils/function-context.js +7 -2
- package/dist/transformation/visitors/binary-expression/assignments.js +9 -23
- package/dist/transformation/visitors/call.js +9 -5
- package/dist/transformation/visitors/expression-list.js +4 -1
- package/dist/transformation/visitors/variable-declaration.d.ts +1 -1
- package/dist/transformation/visitors/variable-declaration.js +11 -14
- package/dist/transpilation/index.js +4 -8
- package/dist/transpilation/resolve.js +2 -2
- package/dist/tstl.js +2 -4
- package/package.json +1 -1
package/dist/LuaPrinter.js
CHANGED
|
@@ -142,6 +142,7 @@ class LuaPrinter {
|
|
|
142
142
|
// Inline lualib features
|
|
143
143
|
sourceChunks.push("-- Lua Library inline imports\n");
|
|
144
144
|
sourceChunks.push((0, LuaLib_1.loadInlineLualibFeatures)(file.luaLibFeatures, this.emitHost));
|
|
145
|
+
sourceChunks.push("-- End of Lua Library inline imports\n");
|
|
145
146
|
}
|
|
146
147
|
if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {
|
|
147
148
|
// In bundle mode the traceback is being generated for the entire file in getBundleResult
|
|
@@ -9,6 +9,9 @@ export declare const unknownCompilerOption: ((name: string) => ts.Diagnostic) &
|
|
|
9
9
|
export declare const compilerOptionRequiresAValueOfType: ((name: string, type: string) => ts.Diagnostic) & {
|
|
10
10
|
code: number;
|
|
11
11
|
};
|
|
12
|
+
export declare const compilerOptionCouldNotParseJson: ((name: string, error: string) => ts.Diagnostic) & {
|
|
13
|
+
code: number;
|
|
14
|
+
};
|
|
12
15
|
export declare const optionProjectCannotBeMixedWithSourceFilesOnACommandLine: (() => ts.Diagnostic) & {
|
|
13
16
|
code: number;
|
|
14
17
|
};
|
package/dist/cli/diagnostics.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
|
|
3
|
+
exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionCouldNotParseJson = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
exports.tstlOptionsAreMovingToTheTstlObject = (0, utils_1.createSerialDiagnosticFactory)((tstl) => ({
|
|
@@ -22,6 +22,7 @@ exports.watchErrorSummary = watchErrorSummary;
|
|
|
22
22
|
const createCommandLineError = (code, getMessage) => (0, utils_1.createDiagnosticFactoryWithCode)(code, (...args) => ({ messageText: getMessage(...args) }));
|
|
23
23
|
exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`);
|
|
24
24
|
exports.compilerOptionRequiresAValueOfType = createCommandLineError(5024, (name, type) => `Compiler option '${name}' requires a value of type ${type}.`);
|
|
25
|
+
exports.compilerOptionCouldNotParseJson = createCommandLineError(5025, (name, error) => `Compiler option '${name}' failed to parse the given JSON value: '${error}'.`);
|
|
25
26
|
exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError(5042, () => "Option 'project' cannot be mixed with source files on a command line.");
|
|
26
27
|
exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = createCommandLineError(5057, (dir) => `Cannot find a tsconfig.json file at the specified directory: '${dir}'.`);
|
|
27
28
|
exports.theSpecifiedPathDoesNotExist = createCommandLineError(5058, (dir) => `The specified path does not exist: '${dir}'.`);
|
package/dist/cli/parse.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
|
|
|
13
13
|
choices: string[];
|
|
14
14
|
}
|
|
15
15
|
interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
|
|
16
|
-
type: "boolean" | "string" | "
|
|
16
|
+
type: "boolean" | "string" | "json-array-of-objects" | "array";
|
|
17
17
|
}
|
|
18
18
|
declare type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
|
|
19
19
|
export declare const optionDeclarations: CommandLineOption[];
|
package/dist/cli/parse.js
CHANGED
|
@@ -62,7 +62,7 @@ exports.optionDeclarations = [
|
|
|
62
62
|
{
|
|
63
63
|
name: "luaPlugins",
|
|
64
64
|
description: "List of TypeScriptToLua plugins.",
|
|
65
|
-
type: "
|
|
65
|
+
type: "json-array-of-objects",
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
name: "tstlVerbose",
|
|
@@ -101,7 +101,7 @@ function updateParsedConfigFile(parsedConfigFile) {
|
|
|
101
101
|
parsedConfigFile.errors.push(cliDiagnostics.unknownCompilerOption(name));
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
|
-
const { error, value } = readValue(option, rawValue);
|
|
104
|
+
const { error, value } = readValue(option, rawValue, OptionSource.TsConfig);
|
|
105
105
|
if (error)
|
|
106
106
|
parsedConfigFile.errors.push(error);
|
|
107
107
|
if (parsedConfigFile.options[name] === undefined)
|
|
@@ -140,9 +140,9 @@ function updateParsedCommandLine(parsedCommandLine, args) {
|
|
|
140
140
|
parsedCommandLine.errors.push(error);
|
|
141
141
|
parsedCommandLine.options[option.name] = value;
|
|
142
142
|
if (consumed) {
|
|
143
|
-
i += 1;
|
|
144
143
|
// Values of custom options are parsed as a file name, exclude them
|
|
145
|
-
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !==
|
|
144
|
+
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !== args[i + 1]);
|
|
145
|
+
i += 1;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -165,15 +165,19 @@ function readCommandLineArgument(option, value) {
|
|
|
165
165
|
consumed: false,
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
-
return { ...readValue(option, value), consumed: true };
|
|
168
|
+
return { ...readValue(option, value, OptionSource.CommandLine), consumed: true };
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
var OptionSource;
|
|
171
|
+
(function (OptionSource) {
|
|
172
|
+
OptionSource[OptionSource["CommandLine"] = 0] = "CommandLine";
|
|
173
|
+
OptionSource[OptionSource["TsConfig"] = 1] = "TsConfig";
|
|
174
|
+
})(OptionSource || (OptionSource = {}));
|
|
175
|
+
function readValue(option, value, source) {
|
|
171
176
|
if (value === null)
|
|
172
177
|
return { value };
|
|
173
178
|
switch (option.type) {
|
|
174
179
|
case "boolean":
|
|
175
|
-
case "string":
|
|
176
|
-
case "object": {
|
|
180
|
+
case "string": {
|
|
177
181
|
if (typeof value !== option.type) {
|
|
178
182
|
return {
|
|
179
183
|
value: undefined,
|
|
@@ -182,14 +186,41 @@ function readValue(option, value) {
|
|
|
182
186
|
}
|
|
183
187
|
return { value };
|
|
184
188
|
}
|
|
185
|
-
case "array":
|
|
186
|
-
|
|
189
|
+
case "array":
|
|
190
|
+
case "json-array-of-objects": {
|
|
191
|
+
const isInvalidNonCliValue = source === OptionSource.TsConfig && !Array.isArray(value);
|
|
192
|
+
const isInvalidCliValue = source === OptionSource.CommandLine && typeof value !== "string";
|
|
193
|
+
if (isInvalidNonCliValue || isInvalidCliValue) {
|
|
187
194
|
return {
|
|
188
195
|
value: undefined,
|
|
189
196
|
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
190
197
|
};
|
|
191
198
|
}
|
|
192
|
-
|
|
199
|
+
const shouldParseValue = source === OptionSource.CommandLine && typeof value === "string";
|
|
200
|
+
if (!shouldParseValue)
|
|
201
|
+
return { value };
|
|
202
|
+
if (option.type === "array") {
|
|
203
|
+
const array = value.split(",");
|
|
204
|
+
return { value: array };
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const objects = JSON.parse(value);
|
|
208
|
+
if (!Array.isArray(objects)) {
|
|
209
|
+
return {
|
|
210
|
+
value: undefined,
|
|
211
|
+
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { value: objects };
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
if (!(e instanceof SyntaxError))
|
|
218
|
+
throw e;
|
|
219
|
+
return {
|
|
220
|
+
value: undefined,
|
|
221
|
+
error: cliDiagnostics.compilerOptionCouldNotParseJson(option.name, e.message),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
193
224
|
}
|
|
194
225
|
case "enum": {
|
|
195
226
|
if (typeof value !== "string") {
|
package/dist/lualib/Map.lua
CHANGED
|
@@ -93,9 +93,8 @@ do
|
|
|
93
93
|
return self:entries()
|
|
94
94
|
end
|
|
95
95
|
function Map.prototype.entries(self)
|
|
96
|
-
local
|
|
97
|
-
local
|
|
98
|
-
local nextKey = ____temp_0.nextKey
|
|
96
|
+
local items = self.items
|
|
97
|
+
local nextKey = self.nextKey
|
|
99
98
|
local key = self.firstKey
|
|
100
99
|
return {
|
|
101
100
|
[Symbol.iterator] = function(self)
|
|
@@ -123,9 +122,8 @@ do
|
|
|
123
122
|
}
|
|
124
123
|
end
|
|
125
124
|
function Map.prototype.values(self)
|
|
126
|
-
local
|
|
127
|
-
local
|
|
128
|
-
local nextKey = ____temp_1.nextKey
|
|
125
|
+
local items = self.items
|
|
126
|
+
local nextKey = self.nextKey
|
|
129
127
|
local key = self.firstKey
|
|
130
128
|
return {
|
|
131
129
|
[Symbol.iterator] = function(self)
|
package/dist/lualib/Promise.lua
CHANGED
|
@@ -74,7 +74,7 @@ do
|
|
|
74
74
|
end
|
|
75
75
|
else
|
|
76
76
|
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
77
|
-
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function() return resolve(nil,
|
|
77
|
+
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
|
|
78
78
|
end
|
|
79
79
|
if onRejected then
|
|
80
80
|
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
@@ -83,6 +83,9 @@ do
|
|
|
83
83
|
if isRejected then
|
|
84
84
|
internalCallback(nil, self.rejectionReason)
|
|
85
85
|
end
|
|
86
|
+
else
|
|
87
|
+
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
|
|
88
|
+
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
|
|
86
89
|
end
|
|
87
90
|
if isFulfilled then
|
|
88
91
|
resolve(nil, self.value)
|
|
@@ -97,8 +100,8 @@ do
|
|
|
97
100
|
end
|
|
98
101
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
99
102
|
if onFinally then
|
|
100
|
-
local
|
|
101
|
-
|
|
103
|
+
local ____self_finallyCallbacks_5 = self.finallyCallbacks
|
|
104
|
+
____self_finallyCallbacks_5[#____self_finallyCallbacks_5 + 1] = onFinally
|
|
102
105
|
if self.state ~= 0 then
|
|
103
106
|
onFinally(nil)
|
|
104
107
|
end
|
|
@@ -651,7 +651,7 @@ do
|
|
|
651
651
|
end
|
|
652
652
|
else
|
|
653
653
|
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
654
|
-
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function() return resolve(nil,
|
|
654
|
+
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
|
|
655
655
|
end
|
|
656
656
|
if onRejected then
|
|
657
657
|
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
@@ -660,6 +660,9 @@ do
|
|
|
660
660
|
if isRejected then
|
|
661
661
|
internalCallback(nil, self.rejectionReason)
|
|
662
662
|
end
|
|
663
|
+
else
|
|
664
|
+
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
|
|
665
|
+
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
|
|
663
666
|
end
|
|
664
667
|
if isFulfilled then
|
|
665
668
|
resolve(nil, self.value)
|
|
@@ -674,8 +677,8 @@ do
|
|
|
674
677
|
end
|
|
675
678
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
676
679
|
if onFinally then
|
|
677
|
-
local
|
|
678
|
-
|
|
680
|
+
local ____self_finallyCallbacks_5 = self.finallyCallbacks
|
|
681
|
+
____self_finallyCallbacks_5[#____self_finallyCallbacks_5 + 1] = onFinally
|
|
679
682
|
if self.state ~= 0 then
|
|
680
683
|
onFinally(nil)
|
|
681
684
|
end
|
|
@@ -1280,9 +1283,8 @@ do
|
|
|
1280
1283
|
return self:entries()
|
|
1281
1284
|
end
|
|
1282
1285
|
function Map.prototype.entries(self)
|
|
1283
|
-
local
|
|
1284
|
-
local
|
|
1285
|
-
local nextKey = ____temp_0.nextKey
|
|
1286
|
+
local items = self.items
|
|
1287
|
+
local nextKey = self.nextKey
|
|
1286
1288
|
local key = self.firstKey
|
|
1287
1289
|
return {
|
|
1288
1290
|
[Symbol.iterator] = function(self)
|
|
@@ -1310,9 +1312,8 @@ do
|
|
|
1310
1312
|
}
|
|
1311
1313
|
end
|
|
1312
1314
|
function Map.prototype.values(self)
|
|
1313
|
-
local
|
|
1314
|
-
local
|
|
1315
|
-
local nextKey = ____temp_1.nextKey
|
|
1315
|
+
local items = self.items
|
|
1316
|
+
local nextKey = self.nextKey
|
|
1316
1317
|
local key = self.firstKey
|
|
1317
1318
|
return {
|
|
1318
1319
|
[Symbol.iterator] = function(self)
|
|
@@ -59,8 +59,13 @@ function getDeclarationContextType({ program }, signatureDeclaration) {
|
|
|
59
59
|
}
|
|
60
60
|
// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
|
|
61
61
|
const options = program.getCompilerOptions();
|
|
62
|
-
if (options.noImplicitSelf
|
|
63
|
-
|
|
62
|
+
if (options.noImplicitSelf) {
|
|
63
|
+
const sourceFile = program.getSourceFile(signatureDeclaration.getSourceFile().fileName);
|
|
64
|
+
if (sourceFile !== undefined &&
|
|
65
|
+
!program.isSourceFileDefaultLibrary(sourceFile) &&
|
|
66
|
+
!program.isSourceFileFromExternalLibrary(sourceFile)) {
|
|
67
|
+
return ContextType.Void;
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
// Walk up to find @noSelf or @noSelfInFile
|
|
66
71
|
if (hasNoSelfAncestor(signatureDeclaration)) {
|
|
@@ -72,17 +72,14 @@ function transformAssignmentWithRightPrecedingStatements(context, lhs, right, ri
|
|
|
72
72
|
}
|
|
73
73
|
exports.transformAssignmentWithRightPrecedingStatements = transformAssignmentWithRightPrecedingStatements;
|
|
74
74
|
function transformDestructuredAssignmentExpression(context, expression) {
|
|
75
|
-
const rootIdentifier = context.createTempNameForNode(expression.right);
|
|
76
75
|
let [rightPrecedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
77
76
|
context.addPrecedingStatements(rightPrecedingStatements);
|
|
78
77
|
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
|
|
79
78
|
right = (0, lua_ast_1.wrapInTable)(right);
|
|
80
79
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
];
|
|
85
|
-
return { statements, result: rootIdentifier };
|
|
80
|
+
const rightExpr = (0, expression_list_1.moveToPrecedingTemp)(context, right, expression.right);
|
|
81
|
+
const statements = (0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rightExpr, rightPrecedingStatements.length > 0);
|
|
82
|
+
return { statements, result: rightExpr };
|
|
86
83
|
}
|
|
87
84
|
function transformAssignmentExpression(context, expression) {
|
|
88
85
|
// Validate assignment
|
|
@@ -99,15 +96,12 @@ function transformAssignmentExpression(context, expression) {
|
|
|
99
96
|
return result;
|
|
100
97
|
}
|
|
101
98
|
if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) {
|
|
102
|
-
const tempVar = context.createTempNameForNode(expression.right);
|
|
103
99
|
const [precedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
104
100
|
const left = transformAssignmentLeftHandSideExpression(context, expression.left, precedingStatements.length > 0);
|
|
105
|
-
context.addPrecedingStatements(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]);
|
|
110
|
-
return lua.cloneIdentifier(tempVar);
|
|
101
|
+
context.addPrecedingStatements(precedingStatements);
|
|
102
|
+
const rightExpr = (0, expression_list_1.moveToPrecedingTemp)(context, right, expression.right);
|
|
103
|
+
context.addPrecedingStatements(lua.createAssignmentStatement(left, rightExpr, expression.left));
|
|
104
|
+
return rightExpr;
|
|
111
105
|
}
|
|
112
106
|
else {
|
|
113
107
|
// Simple assignment
|
|
@@ -158,16 +152,8 @@ function transformAssignmentStatement(context, expression) {
|
|
|
158
152
|
const left = expression.left.elements.map(e => transformAssignmentLeftHandSideExpression(context, e));
|
|
159
153
|
return [lua.createAssignmentStatement(left, right, expression)];
|
|
160
154
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
|
|
164
|
-
right = (0, lua_ast_1.wrapInTable)(right);
|
|
165
|
-
}
|
|
166
|
-
const rootIdentifier = context.createTempNameForNode(expression.left);
|
|
167
|
-
return [
|
|
168
|
-
lua.createVariableDeclarationStatement(rootIdentifier, right),
|
|
169
|
-
...(0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rootIdentifier, rightPrecedingStatements.length > 0),
|
|
170
|
-
];
|
|
155
|
+
const { statements } = transformDestructuredAssignmentExpression(context, expression);
|
|
156
|
+
return statements;
|
|
171
157
|
}
|
|
172
158
|
else {
|
|
173
159
|
const [precedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
@@ -184,10 +184,9 @@ const transformCallExpression = (node, context) => {
|
|
|
184
184
|
const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
|
|
185
185
|
return lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), parameters);
|
|
186
186
|
}
|
|
187
|
-
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
188
187
|
let callPath;
|
|
189
188
|
let parameters;
|
|
190
|
-
const isContextualCall =
|
|
189
|
+
const isContextualCall = isContextualCallExpression(context, signature);
|
|
191
190
|
if (!isContextualCall) {
|
|
192
191
|
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature);
|
|
193
192
|
}
|
|
@@ -195,9 +194,7 @@ const transformCallExpression = (node, context) => {
|
|
|
195
194
|
// if is optionalContinuation, context will be handled by transformOptionalChain.
|
|
196
195
|
const useGlobalContext = !context.isStrict && optionalContinuation === undefined;
|
|
197
196
|
const callContext = useGlobalContext ? ts.factory.createIdentifier("_G") : ts.factory.createNull();
|
|
198
|
-
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature,
|
|
199
|
-
// Only pass context if noImplicitSelf is not configured
|
|
200
|
-
context.options.noImplicitSelf ? undefined : callContext);
|
|
197
|
+
[callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature, callContext);
|
|
201
198
|
}
|
|
202
199
|
const callExpression = lua.createCallExpression(callPath, parameters, node);
|
|
203
200
|
if (optionalContinuation && isContextualCall) {
|
|
@@ -206,6 +203,13 @@ const transformCallExpression = (node, context) => {
|
|
|
206
203
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(callExpression) : callExpression;
|
|
207
204
|
};
|
|
208
205
|
exports.transformCallExpression = transformCallExpression;
|
|
206
|
+
function isContextualCallExpression(context, signature) {
|
|
207
|
+
const declaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
208
|
+
if (!declaration) {
|
|
209
|
+
return !context.options.noImplicitSelf;
|
|
210
|
+
}
|
|
211
|
+
return (0, function_context_1.getDeclarationContextType)(context, declaration) !== function_context_1.ContextType.Void;
|
|
212
|
+
}
|
|
209
213
|
function getCalledExpression(node) {
|
|
210
214
|
function unwrapExpression(expression) {
|
|
211
215
|
expression = ts.skipOuterExpressions(expression);
|
|
@@ -12,7 +12,10 @@ const optional_chaining_1 = require("./optional-chaining");
|
|
|
12
12
|
function shouldMoveToTemp(context, expression, tsOriginal) {
|
|
13
13
|
return (!lua.isLiteral(expression) &&
|
|
14
14
|
!(lua.isIdentifier(expression) && expression.symbolId === context_1.tempSymbolId) && // Treat generated temps as consts
|
|
15
|
-
!(tsOriginal &&
|
|
15
|
+
!(tsOriginal &&
|
|
16
|
+
((0, typescript_1.isConstIdentifier)(context, tsOriginal) ||
|
|
17
|
+
(0, optional_chaining_1.isOptionalContinuation)(tsOriginal) ||
|
|
18
|
+
tsOriginal.kind === ts.SyntaxKind.ThisKeyword)));
|
|
16
19
|
}
|
|
17
20
|
exports.shouldMoveToTemp = shouldMoveToTemp;
|
|
18
21
|
// Cache an expression in a preceding statement and return the temp identifier
|
|
@@ -2,7 +2,7 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
4
|
export declare function transformArrayBindingElement(context: TransformationContext, name: ts.ArrayBindingElement): lua.Identifier;
|
|
5
|
-
export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.
|
|
5
|
+
export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.Expression, propertyAccessStack?: ts.PropertyName[]): lua.Statement[];
|
|
6
6
|
export declare function transformBindingVariableDeclaration(context: TransformationContext, bindingPattern: ts.BindingPattern, initializer?: ts.Expression): lua.Statement[];
|
|
7
7
|
export declare function transformVariableDeclaration(context: TransformationContext, statement: ts.VariableDeclaration): lua.Statement[];
|
|
8
8
|
export declare function checkVariableDeclarationList(context: TransformationContext, node: ts.VariableDeclarationList): void;
|
|
@@ -14,6 +14,7 @@ const function_1 = require("./function");
|
|
|
14
14
|
const identifier_1 = require("./identifier");
|
|
15
15
|
const multi_1 = require("./language-extensions/multi");
|
|
16
16
|
const literal_1 = require("./literal");
|
|
17
|
+
const expression_list_1 = require("./expression-list");
|
|
17
18
|
function transformArrayBindingElement(context, name) {
|
|
18
19
|
if (ts.isOmittedExpression(name)) {
|
|
19
20
|
return lua.createAnonymousIdentifier(name);
|
|
@@ -117,22 +118,18 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
|
|
|
117
118
|
const isComplexBindingElement = (e) => ts.isBindingElement(e) && (!ts.isIdentifier(e.name) || e.dotDotDotToken);
|
|
118
119
|
if (ts.isObjectBindingPattern(bindingPattern) || bindingPattern.elements.some(isComplexBindingElement)) {
|
|
119
120
|
let table;
|
|
120
|
-
if (initializer
|
|
121
|
-
table = (0, identifier_1.transformIdentifier)(context, initializer);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
121
|
+
if (initializer) {
|
|
124
122
|
// Contain the expression in a temporary variable
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
129
|
-
expression = (0, lua_ast_1.wrapInTable)(expression);
|
|
130
|
-
}
|
|
131
|
-
statements.push(lua.createVariableDeclarationStatement(table, expression));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
table = lua.createAnonymousIdentifier();
|
|
123
|
+
let expression = context.transformExpression(initializer);
|
|
124
|
+
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
125
|
+
expression = (0, lua_ast_1.wrapInTable)(expression);
|
|
135
126
|
}
|
|
127
|
+
const [moveStatements, movedExpr] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, expression_list_1.moveToPrecedingTemp)(context, expression, initializer));
|
|
128
|
+
statements.push(...moveStatements);
|
|
129
|
+
table = movedExpr;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
table = lua.createAnonymousIdentifier();
|
|
136
133
|
}
|
|
137
134
|
statements.push(...transformBindingPattern(context, bindingPattern, table));
|
|
138
135
|
return statements;
|
|
@@ -26,11 +26,9 @@ __exportStar(require("./transpile"), exports);
|
|
|
26
26
|
__exportStar(require("./transpiler"), exports);
|
|
27
27
|
function transpileFiles(rootNames, options = {}, writeFile) {
|
|
28
28
|
const program = ts.createProgram(rootNames, options);
|
|
29
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
29
30
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new transpiler_1.Transpiler().emit({ program, writeFile });
|
|
30
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
31
|
-
...ts.getPreEmitDiagnostics(program),
|
|
32
|
-
...transpileDiagnostics,
|
|
33
|
-
]);
|
|
31
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
34
32
|
return { diagnostics: [...diagnostics], emitSkipped };
|
|
35
33
|
}
|
|
36
34
|
exports.transpileFiles = transpileFiles;
|
|
@@ -85,12 +83,10 @@ function createVirtualProgram(input, options = {}) {
|
|
|
85
83
|
exports.createVirtualProgram = createVirtualProgram;
|
|
86
84
|
function transpileVirtualProject(files, options = {}) {
|
|
87
85
|
const program = createVirtualProgram(files, options);
|
|
86
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
88
87
|
const collector = (0, output_collector_1.createEmitOutputCollector)();
|
|
89
88
|
const { diagnostics: transpileDiagnostics } = new transpiler_1.Transpiler().emit({ program, writeFile: collector.writeFile });
|
|
90
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
91
|
-
...ts.getPreEmitDiagnostics(program),
|
|
92
|
-
...transpileDiagnostics,
|
|
93
|
-
]);
|
|
89
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
94
90
|
return { diagnostics: [...diagnostics], transpiledFiles: collector.files };
|
|
95
91
|
}
|
|
96
92
|
exports.transpileVirtualProject = transpileVirtualProject;
|
|
@@ -115,8 +115,8 @@ function resolveFileDependencies(file, context) {
|
|
|
115
115
|
const dependencies = [];
|
|
116
116
|
const diagnostics = [];
|
|
117
117
|
for (const required of findRequiredPaths(file.code)) {
|
|
118
|
-
// Do no resolve lualib,
|
|
119
|
-
if (required === "lualib_bundle"
|
|
118
|
+
// Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
|
|
119
|
+
if (required === "lualib_bundle") {
|
|
120
120
|
dependencies.push({ fileName: "lualib_bundle", code: "" });
|
|
121
121
|
continue;
|
|
122
122
|
}
|
package/dist/tstl.js
CHANGED
|
@@ -81,11 +81,9 @@ function performCompilation(rootNames, projectReferences, options, configFilePar
|
|
|
81
81
|
projectReferences,
|
|
82
82
|
configFileParsingDiagnostics,
|
|
83
83
|
});
|
|
84
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
84
85
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new tstl.Transpiler().emit({ program });
|
|
85
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
86
|
-
...ts.getPreEmitDiagnostics(program),
|
|
87
|
-
...transpileDiagnostics,
|
|
88
|
-
]);
|
|
86
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
89
87
|
diagnostics.forEach(reportDiagnostic);
|
|
90
88
|
const exitCode = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error).length === 0
|
|
91
89
|
? ts.ExitStatus.Success
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
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/",
|