typescript-to-lua 1.5.0 → 1.6.2
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/lualib/Map.lua +4 -6
- package/dist/lualib/Promise.lua +6 -3
- package/dist/lualib/lualib_bundle.lua +10 -9
- package/dist/lualib-build/plugin.d.ts +1 -1
- package/dist/transformation/context/context.d.ts +2 -2
- package/dist/transformation/context/context.js +1 -1
- package/dist/transformation/utils/export.d.ts +1 -1
- package/dist/transformation/utils/function-context.js +7 -2
- package/dist/transformation/utils/lua-ast.d.ts +1 -1
- package/dist/transformation/visitors/binary-expression/assignments.js +9 -23
- package/dist/transformation/visitors/binary-expression/compound.d.ts +4 -1
- package/dist/transformation/visitors/binary-expression/compound.js +10 -19
- package/dist/transformation/visitors/call.js +8 -2
- 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 +9 -4
- package/dist/transpilation/resolve.js +1 -1
- package/dist/transpilation/transpiler.js +3 -2
- package/package.json +9 -9
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
|
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)
|
|
@@ -7,7 +7,7 @@ export declare const lualibDiagnostic: ((message: string, file?: ts.SourceFile |
|
|
|
7
7
|
};
|
|
8
8
|
declare class LuaLibPlugin implements tstl.Plugin {
|
|
9
9
|
visitors: {
|
|
10
|
-
|
|
10
|
+
305: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
|
|
11
11
|
};
|
|
12
12
|
printer: tstl.Printer;
|
|
13
13
|
afterPrint(program: ts.Program, options: tstl.CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]): ts.Diagnostic[];
|
|
@@ -16,7 +16,7 @@ export interface EmitResolver {
|
|
|
16
16
|
moduleExportsSomeValue(moduleReferenceExpression: ts.Expression): boolean;
|
|
17
17
|
getAllAccessorDeclarations(declaration: ts.AccessorDeclaration): AllAccessorDeclarations;
|
|
18
18
|
}
|
|
19
|
-
export interface
|
|
19
|
+
export interface TypeCheckerWithEmitResolver extends ts.TypeChecker {
|
|
20
20
|
getEmitResolver(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): EmitResolver;
|
|
21
21
|
}
|
|
22
22
|
export declare class TransformationContext {
|
|
@@ -24,7 +24,7 @@ export declare class TransformationContext {
|
|
|
24
24
|
sourceFile: ts.SourceFile;
|
|
25
25
|
private visitorMap;
|
|
26
26
|
readonly diagnostics: ts.Diagnostic[];
|
|
27
|
-
readonly checker:
|
|
27
|
+
readonly checker: TypeCheckerWithEmitResolver;
|
|
28
28
|
readonly resolver: EmitResolver;
|
|
29
29
|
readonly precedingStatementsStack: lua.Statement[][];
|
|
30
30
|
readonly options: CompilerOptions;
|
|
@@ -16,7 +16,7 @@ class TransformationContext {
|
|
|
16
16
|
this.sourceFile = sourceFile;
|
|
17
17
|
this.visitorMap = visitorMap;
|
|
18
18
|
this.diagnostics = [];
|
|
19
|
-
this.checker = this.program.
|
|
19
|
+
this.checker = this.program.getTypeChecker();
|
|
20
20
|
this.precedingStatementsStack = [];
|
|
21
21
|
this.options = this.program.getCompilerOptions();
|
|
22
22
|
this.luaTarget = (_a = this.options.luaTarget) !== null && _a !== void 0 ? _a : CompilerOptions_1.LuaTarget.Universal;
|
|
@@ -3,7 +3,7 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function hasDefaultExportModifier(node: ts.Node): boolean;
|
|
5
5
|
export declare function hasExportModifier(node: ts.Node): boolean;
|
|
6
|
-
export declare const createDefaultExportStringLiteral: (original?: ts.Node
|
|
6
|
+
export declare const createDefaultExportStringLiteral: (original?: ts.Node) => lua.StringLiteral;
|
|
7
7
|
export declare function getExportedSymbolDeclaration(symbol: ts.Symbol): ts.Declaration | undefined;
|
|
8
8
|
export declare function getSymbolFromIdentifier(context: TransformationContext, identifier: lua.Identifier): ts.Symbol | undefined;
|
|
9
9
|
export declare function getIdentifierExportScope(context: TransformationContext, identifier: lua.Identifier): ts.SourceFile | ts.ModuleDeclaration | undefined;
|
|
@@ -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)) {
|
|
@@ -13,4 +13,4 @@ export declare function wrapInTable(...expressions: lua.Expression[]): lua.Table
|
|
|
13
13
|
export declare function wrapInToStringForConcat(expression: lua.Expression): lua.Expression;
|
|
14
14
|
export declare function createHoistableVariableDeclarationStatement(context: TransformationContext, identifier: lua.Identifier, initializer?: lua.Expression, tsOriginal?: ts.Node): lua.AssignmentStatement | lua.VariableDeclarationStatement;
|
|
15
15
|
export declare function createLocalOrExportedOrGlobalDeclaration(context: TransformationContext, lhs: lua.Identifier | lua.Identifier[], rhs?: lua.Expression | lua.Expression[], tsOriginal?: ts.Node, overrideExportScope?: ts.SourceFile | ts.ModuleDeclaration): lua.Statement[];
|
|
16
|
-
export declare const createNaN: (tsOriginal?: ts.Node
|
|
16
|
+
export declare const createNaN: (tsOriginal?: ts.Node) => lua.BinaryExpression;
|
|
@@ -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));
|
|
@@ -6,7 +6,10 @@ export declare const isCompoundAssignmentToken: (token: ts.BinaryOperator) => to
|
|
|
6
6
|
export declare const unwrapCompoundAssignmentToken: (token: ts.CompoundAssignmentOperator) => CompoundAssignmentToken;
|
|
7
7
|
export declare function transformCompoundAssignment(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): {
|
|
8
8
|
statements: lua.Statement[];
|
|
9
|
-
result: lua.
|
|
9
|
+
result: lua.Identifier;
|
|
10
|
+
} | {
|
|
11
|
+
statements: lua.Statement[];
|
|
12
|
+
result: lua.TableIndexExpression;
|
|
10
13
|
};
|
|
11
14
|
export declare function transformCompoundAssignmentExpression(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): lua.Expression;
|
|
12
15
|
export declare function transformCompoundAssignmentStatement(context: TransformationContext, node: ts.Node, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken): lua.Statement[];
|
|
@@ -39,7 +39,7 @@ exports.unwrapCompoundAssignmentToken = unwrapCompoundAssignmentToken;
|
|
|
39
39
|
function transformCompoundAssignment(context, expression, lhs, rhs, operator, isPostfix) {
|
|
40
40
|
const left = (0, utils_1.cast)(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);
|
|
41
41
|
const [rightPrecedingStatements, right] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
|
|
42
|
-
if (lua.isTableIndexExpression(left)
|
|
42
|
+
if (lua.isTableIndexExpression(left)) {
|
|
43
43
|
// Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
|
|
44
44
|
// local __obj, __index = ${objExpression}, ${indexExpression};
|
|
45
45
|
const obj = context.createTempNameForLuaExpression(left.table);
|
|
@@ -60,6 +60,15 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
+
if (isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
64
|
+
return {
|
|
65
|
+
statements: [
|
|
66
|
+
objAndIndexDeclaration,
|
|
67
|
+
...transformSetterSkippingCompoundAssignment(accessExpression, operator, right, rightPrecedingStatements),
|
|
68
|
+
],
|
|
69
|
+
result: left,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
63
72
|
// local ____tmp = ____obj[____index] ${replacementOperator} ${right};
|
|
64
73
|
// ____obj[____index] = ____tmp;
|
|
65
74
|
// return ____tmp
|
|
@@ -83,24 +92,6 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
83
92
|
const assignStatements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
|
|
84
93
|
return { statements: [tmpDeclaration, ...precedingStatements, ...assignStatements], result: tmpIdentifier };
|
|
85
94
|
}
|
|
86
|
-
else if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
|
|
87
|
-
// Simple property/element access expressions need to cache in temp to avoid double-evaluation
|
|
88
|
-
// local ____tmp = ${left} ${replacementOperator} ${right};
|
|
89
|
-
// ${left} = ____tmp;
|
|
90
|
-
// return ____tmp
|
|
91
|
-
const tmpIdentifier = context.createTempNameForLuaExpression(left);
|
|
92
|
-
const [precedingStatements, operatorExpression] = (0, binary_expression_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, expression);
|
|
93
|
-
const tmpDeclaration = lua.createVariableDeclarationStatement(tmpIdentifier, operatorExpression);
|
|
94
|
-
if (isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
95
|
-
const statements = [
|
|
96
|
-
tmpDeclaration,
|
|
97
|
-
...transformSetterSkippingCompoundAssignment(tmpIdentifier, operator, right, precedingStatements),
|
|
98
|
-
];
|
|
99
|
-
return { statements, result: tmpIdentifier };
|
|
100
|
-
}
|
|
101
|
-
const assignStatements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, tmpIdentifier, precedingStatements);
|
|
102
|
-
return { statements: [tmpDeclaration, ...assignStatements], result: tmpIdentifier };
|
|
103
|
-
}
|
|
104
95
|
else {
|
|
105
96
|
if (rightPrecedingStatements.length > 0 && isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
106
97
|
return {
|
|
@@ -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
|
}
|
|
@@ -204,6 +203,13 @@ const transformCallExpression = (node, context) => {
|
|
|
204
203
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(callExpression) : callExpression;
|
|
205
204
|
};
|
|
206
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
|
+
}
|
|
207
213
|
function getCalledExpression(node) {
|
|
208
214
|
function unwrapExpression(expression) {
|
|
209
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;
|
|
@@ -19,6 +19,7 @@ const fs = require("fs");
|
|
|
19
19
|
const path = require("path");
|
|
20
20
|
const ts = require("typescript");
|
|
21
21
|
const tsconfig_1 = require("../cli/tsconfig");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
22
23
|
const output_collector_1 = require("./output-collector");
|
|
23
24
|
const transpiler_1 = require("./transpiler");
|
|
24
25
|
__exportStar(require("./transpile"), exports);
|
|
@@ -44,8 +45,12 @@ exports.transpileProject = transpileProject;
|
|
|
44
45
|
const libCache = {};
|
|
45
46
|
/** @internal */
|
|
46
47
|
function createVirtualProgram(input, options = {}) {
|
|
48
|
+
const normalizedFiles = {};
|
|
49
|
+
for (const [path, file] of Object.entries(input)) {
|
|
50
|
+
normalizedFiles[(0, utils_1.normalizeSlashes)(path)] = file;
|
|
51
|
+
}
|
|
47
52
|
const compilerHost = {
|
|
48
|
-
fileExists: fileName => fileName in
|
|
53
|
+
fileExists: fileName => fileName in normalizedFiles || ts.sys.fileExists(fileName),
|
|
49
54
|
getCanonicalFileName: fileName => fileName,
|
|
50
55
|
getCurrentDirectory: () => "",
|
|
51
56
|
getDefaultLibFileName: ts.getDefaultLibFileName,
|
|
@@ -54,8 +59,8 @@ function createVirtualProgram(input, options = {}) {
|
|
|
54
59
|
useCaseSensitiveFileNames: () => false,
|
|
55
60
|
writeFile() { },
|
|
56
61
|
getSourceFile(fileName) {
|
|
57
|
-
if (fileName in
|
|
58
|
-
return ts.createSourceFile(fileName,
|
|
62
|
+
if (fileName in normalizedFiles) {
|
|
63
|
+
return ts.createSourceFile(fileName, normalizedFiles[fileName], ts.ScriptTarget.Latest, false);
|
|
59
64
|
}
|
|
60
65
|
let filePath;
|
|
61
66
|
if (fileName.startsWith("lib.")) {
|
|
@@ -75,7 +80,7 @@ function createVirtualProgram(input, options = {}) {
|
|
|
75
80
|
}
|
|
76
81
|
},
|
|
77
82
|
};
|
|
78
|
-
return ts.createProgram(Object.keys(
|
|
83
|
+
return ts.createProgram(Object.keys(normalizedFiles), options, compilerHost);
|
|
79
84
|
}
|
|
80
85
|
exports.createVirtualProgram = createVirtualProgram;
|
|
81
86
|
function transpileVirtualProject(files, options = {}) {
|
|
@@ -115,7 +115,7 @@ 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
|
|
118
|
+
// Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
|
|
119
119
|
if (required === "lualib_bundle") {
|
|
120
120
|
dependencies.push({ fileName: "lualib_bundle", code: "" });
|
|
121
121
|
continue;
|
|
@@ -16,9 +16,10 @@ class Transpiler {
|
|
|
16
16
|
}
|
|
17
17
|
emit(emitOptions) {
|
|
18
18
|
var _a, _b;
|
|
19
|
-
const { program, writeFile = this.emitHost.writeFile } = emitOptions;
|
|
19
|
+
const { program, writeFile = this.emitHost.writeFile, plugins: optionsPlugins = [] } = emitOptions;
|
|
20
20
|
const options = program.getCompilerOptions();
|
|
21
|
-
const { diagnostics: getPluginsDiagnostics, plugins } = (0, plugins_1.getPlugins)(program);
|
|
21
|
+
const { diagnostics: getPluginsDiagnostics, plugins: configPlugins } = (0, plugins_1.getPlugins)(program);
|
|
22
|
+
const plugins = [...optionsPlugins, ...configPlugins];
|
|
22
23
|
const { diagnostics, transpiledFiles: freshFiles } = (0, transpile_1.getProgramTranspileResult)(this.emitHost, writeFile, {
|
|
23
24
|
...emitOptions,
|
|
24
25
|
plugins,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.2",
|
|
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/",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node": ">=12.13.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"typescript": "~4.
|
|
46
|
+
"typescript": "~4.7.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"enhanced-resolve": "^5.8.2",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/fs-extra": "^8.1.0",
|
|
55
55
|
"@types/glob": "^7.1.1",
|
|
56
|
-
"@types/jest": "^27.
|
|
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.
|
|
62
|
-
"eslint-plugin-import": "^2.
|
|
63
|
-
"eslint-plugin-jest": "^26.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
61
|
+
"eslint": "^8.17.0",
|
|
62
|
+
"eslint-plugin-import": "^2.26.0",
|
|
63
|
+
"eslint-plugin-jest": "^26.4.6",
|
|
64
64
|
"fs-extra": "^8.1.0",
|
|
65
65
|
"javascript-stringify": "^2.0.1",
|
|
66
66
|
"jest": "^27.3.0",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
"prettier": "^2.3.2",
|
|
71
71
|
"ts-jest": "^27.1.3",
|
|
72
72
|
"ts-node": "^10.3.0",
|
|
73
|
-
"typescript": "~4.
|
|
73
|
+
"typescript": "~4.7.3"
|
|
74
74
|
}
|
|
75
75
|
}
|