typescript-to-lua 1.28.1 → 1.29.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 +2 -1
- package/dist/CompilerOptions.js +1 -0
- package/dist/LuaAST.d.ts +57 -43
- package/dist/LuaAST.js +65 -43
- package/dist/LuaPrinter.d.ts +2 -0
- package/dist/LuaPrinter.js +17 -0
- package/dist/transformation/builtins/index.d.ts +1 -0
- package/dist/transformation/builtins/index.js +1 -0
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/scope.d.ts +2 -1
- package/dist/transformation/utils/scope.js +1 -0
- package/dist/transformation/utils/typescript/types.js +11 -3
- package/dist/transformation/visitors/break-continue.js +12 -5
- package/dist/transformation/visitors/class/new.js +25 -3
- package/dist/transformation/visitors/conditional.js +5 -0
- package/dist/transformation/visitors/loops/utils.js +1 -0
- package/package.json +1 -1
package/dist/CompilerOptions.js
CHANGED
package/dist/LuaAST.d.ts
CHANGED
|
@@ -15,49 +15,51 @@ export declare enum SyntaxKind {
|
|
|
15
15
|
LabelStatement = 11,
|
|
16
16
|
ReturnStatement = 12,
|
|
17
17
|
BreakStatement = 13,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
18
|
+
ContinueStatement = 14,// Luau only.
|
|
19
|
+
ExpressionStatement = 15,
|
|
20
|
+
StringLiteral = 16,
|
|
21
|
+
NumericLiteral = 17,
|
|
22
|
+
NilKeyword = 18,
|
|
23
|
+
DotsKeyword = 19,
|
|
24
|
+
ArgKeyword = 20,
|
|
25
|
+
TrueKeyword = 21,
|
|
26
|
+
FalseKeyword = 22,
|
|
27
|
+
FunctionExpression = 23,
|
|
28
|
+
TableFieldExpression = 24,
|
|
29
|
+
TableExpression = 25,
|
|
30
|
+
UnaryExpression = 26,
|
|
31
|
+
BinaryExpression = 27,
|
|
32
|
+
CallExpression = 28,
|
|
33
|
+
MethodCallExpression = 29,
|
|
34
|
+
Identifier = 30,
|
|
35
|
+
TableIndexExpression = 31,
|
|
36
|
+
ParenthesizedExpression = 32,
|
|
37
|
+
ConditionalExpression = 33,// Luau only
|
|
38
|
+
AdditionOperator = 34,// Maybe use abbreviations for those add, sub, mul ...
|
|
39
|
+
SubtractionOperator = 35,
|
|
40
|
+
MultiplicationOperator = 36,
|
|
41
|
+
DivisionOperator = 37,
|
|
42
|
+
FloorDivisionOperator = 38,
|
|
43
|
+
ModuloOperator = 39,
|
|
44
|
+
PowerOperator = 40,
|
|
45
|
+
NegationOperator = 41,// Unary minus
|
|
46
|
+
ConcatOperator = 42,
|
|
47
|
+
LengthOperator = 43,// Unary
|
|
48
|
+
EqualityOperator = 44,
|
|
49
|
+
InequalityOperator = 45,
|
|
50
|
+
LessThanOperator = 46,
|
|
51
|
+
LessEqualOperator = 47,
|
|
52
|
+
GreaterThanOperator = 48,
|
|
53
|
+
GreaterEqualOperator = 49,// Syntax Sugar `x >= y` <=> `not (y < x)`
|
|
54
|
+
AndOperator = 50,
|
|
55
|
+
OrOperator = 51,
|
|
56
|
+
NotOperator = 52,// Unary
|
|
57
|
+
BitwiseAndOperator = 53,
|
|
58
|
+
BitwiseOrOperator = 54,
|
|
59
|
+
BitwiseExclusiveOrOperator = 55,
|
|
60
|
+
BitwiseRightShiftOperator = 56,
|
|
61
|
+
BitwiseLeftShiftOperator = 57,
|
|
62
|
+
BitwiseNotOperator = 58
|
|
61
63
|
}
|
|
62
64
|
export type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;
|
|
63
65
|
export type UnaryOperator = SyntaxKind.NegationOperator | SyntaxKind.LengthOperator | SyntaxKind.NotOperator | UnaryBitwiseOperator;
|
|
@@ -190,6 +192,11 @@ export interface BreakStatement extends Statement {
|
|
|
190
192
|
}
|
|
191
193
|
export declare function isBreakStatement(node: Node): node is BreakStatement;
|
|
192
194
|
export declare function createBreakStatement(tsOriginal?: ts.Node): BreakStatement;
|
|
195
|
+
export interface ContinueStatement extends Statement {
|
|
196
|
+
kind: SyntaxKind.ContinueStatement;
|
|
197
|
+
}
|
|
198
|
+
export declare function isContinueStatement(node: Node): node is ContinueStatement;
|
|
199
|
+
export declare function createContinueStatement(tsOriginal?: ts.Node): ContinueStatement;
|
|
193
200
|
export interface ExpressionStatement extends Statement {
|
|
194
201
|
kind: SyntaxKind.ExpressionStatement;
|
|
195
202
|
expression: Expression;
|
|
@@ -320,3 +327,10 @@ export type ParenthesizedExpression = Expression & {
|
|
|
320
327
|
};
|
|
321
328
|
export declare function isParenthesizedExpression(node: Node): node is ParenthesizedExpression;
|
|
322
329
|
export declare function createParenthesizedExpression(expression: Expression, tsOriginal?: ts.Node): ParenthesizedExpression;
|
|
330
|
+
export type ConditionalExpression = Expression & {
|
|
331
|
+
condition: Expression;
|
|
332
|
+
whenTrue: Expression;
|
|
333
|
+
whenFalse: Expression;
|
|
334
|
+
};
|
|
335
|
+
export declare function isConditionalExpression(node: Node): node is ConditionalExpression;
|
|
336
|
+
export declare function createConditionalExpression(condition: Expression, whenTrue: Expression, whenFalse: Expression, tsOriginal?: ts.Node): ConditionalExpression;
|
package/dist/LuaAST.js
CHANGED
|
@@ -38,6 +38,8 @@ exports.isReturnStatement = isReturnStatement;
|
|
|
38
38
|
exports.createReturnStatement = createReturnStatement;
|
|
39
39
|
exports.isBreakStatement = isBreakStatement;
|
|
40
40
|
exports.createBreakStatement = createBreakStatement;
|
|
41
|
+
exports.isContinueStatement = isContinueStatement;
|
|
42
|
+
exports.createContinueStatement = createContinueStatement;
|
|
41
43
|
exports.isExpressionStatement = isExpressionStatement;
|
|
42
44
|
exports.createExpressionStatement = createExpressionStatement;
|
|
43
45
|
exports.isNilLiteral = isNilLiteral;
|
|
@@ -78,6 +80,8 @@ exports.isFunctionDefinition = isFunctionDefinition;
|
|
|
78
80
|
exports.isInlineFunctionExpression = isInlineFunctionExpression;
|
|
79
81
|
exports.isParenthesizedExpression = isParenthesizedExpression;
|
|
80
82
|
exports.createParenthesizedExpression = createParenthesizedExpression;
|
|
83
|
+
exports.isConditionalExpression = isConditionalExpression;
|
|
84
|
+
exports.createConditionalExpression = createConditionalExpression;
|
|
81
85
|
// We can elide a lot of nodes especially tokens and keywords
|
|
82
86
|
// because we don't create the AST from text
|
|
83
87
|
const ts = require("typescript");
|
|
@@ -99,59 +103,61 @@ var SyntaxKind;
|
|
|
99
103
|
SyntaxKind[SyntaxKind["LabelStatement"] = 11] = "LabelStatement";
|
|
100
104
|
SyntaxKind[SyntaxKind["ReturnStatement"] = 12] = "ReturnStatement";
|
|
101
105
|
SyntaxKind[SyntaxKind["BreakStatement"] = 13] = "BreakStatement";
|
|
102
|
-
SyntaxKind[SyntaxKind["
|
|
106
|
+
SyntaxKind[SyntaxKind["ContinueStatement"] = 14] = "ContinueStatement";
|
|
107
|
+
SyntaxKind[SyntaxKind["ExpressionStatement"] = 15] = "ExpressionStatement";
|
|
103
108
|
// Expression
|
|
104
|
-
SyntaxKind[SyntaxKind["StringLiteral"] =
|
|
105
|
-
SyntaxKind[SyntaxKind["NumericLiteral"] =
|
|
106
|
-
SyntaxKind[SyntaxKind["NilKeyword"] =
|
|
107
|
-
SyntaxKind[SyntaxKind["DotsKeyword"] =
|
|
108
|
-
SyntaxKind[SyntaxKind["ArgKeyword"] =
|
|
109
|
-
SyntaxKind[SyntaxKind["TrueKeyword"] =
|
|
110
|
-
SyntaxKind[SyntaxKind["FalseKeyword"] =
|
|
111
|
-
SyntaxKind[SyntaxKind["FunctionExpression"] =
|
|
112
|
-
SyntaxKind[SyntaxKind["TableFieldExpression"] =
|
|
113
|
-
SyntaxKind[SyntaxKind["TableExpression"] =
|
|
114
|
-
SyntaxKind[SyntaxKind["UnaryExpression"] =
|
|
115
|
-
SyntaxKind[SyntaxKind["BinaryExpression"] =
|
|
116
|
-
SyntaxKind[SyntaxKind["CallExpression"] =
|
|
117
|
-
SyntaxKind[SyntaxKind["MethodCallExpression"] =
|
|
118
|
-
SyntaxKind[SyntaxKind["Identifier"] =
|
|
119
|
-
SyntaxKind[SyntaxKind["TableIndexExpression"] =
|
|
120
|
-
SyntaxKind[SyntaxKind["ParenthesizedExpression"] =
|
|
109
|
+
SyntaxKind[SyntaxKind["StringLiteral"] = 16] = "StringLiteral";
|
|
110
|
+
SyntaxKind[SyntaxKind["NumericLiteral"] = 17] = "NumericLiteral";
|
|
111
|
+
SyntaxKind[SyntaxKind["NilKeyword"] = 18] = "NilKeyword";
|
|
112
|
+
SyntaxKind[SyntaxKind["DotsKeyword"] = 19] = "DotsKeyword";
|
|
113
|
+
SyntaxKind[SyntaxKind["ArgKeyword"] = 20] = "ArgKeyword";
|
|
114
|
+
SyntaxKind[SyntaxKind["TrueKeyword"] = 21] = "TrueKeyword";
|
|
115
|
+
SyntaxKind[SyntaxKind["FalseKeyword"] = 22] = "FalseKeyword";
|
|
116
|
+
SyntaxKind[SyntaxKind["FunctionExpression"] = 23] = "FunctionExpression";
|
|
117
|
+
SyntaxKind[SyntaxKind["TableFieldExpression"] = 24] = "TableFieldExpression";
|
|
118
|
+
SyntaxKind[SyntaxKind["TableExpression"] = 25] = "TableExpression";
|
|
119
|
+
SyntaxKind[SyntaxKind["UnaryExpression"] = 26] = "UnaryExpression";
|
|
120
|
+
SyntaxKind[SyntaxKind["BinaryExpression"] = 27] = "BinaryExpression";
|
|
121
|
+
SyntaxKind[SyntaxKind["CallExpression"] = 28] = "CallExpression";
|
|
122
|
+
SyntaxKind[SyntaxKind["MethodCallExpression"] = 29] = "MethodCallExpression";
|
|
123
|
+
SyntaxKind[SyntaxKind["Identifier"] = 30] = "Identifier";
|
|
124
|
+
SyntaxKind[SyntaxKind["TableIndexExpression"] = 31] = "TableIndexExpression";
|
|
125
|
+
SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 32] = "ParenthesizedExpression";
|
|
126
|
+
SyntaxKind[SyntaxKind["ConditionalExpression"] = 33] = "ConditionalExpression";
|
|
121
127
|
// Operators
|
|
122
128
|
// Arithmetic
|
|
123
|
-
SyntaxKind[SyntaxKind["AdditionOperator"] =
|
|
124
|
-
SyntaxKind[SyntaxKind["SubtractionOperator"] =
|
|
125
|
-
SyntaxKind[SyntaxKind["MultiplicationOperator"] =
|
|
126
|
-
SyntaxKind[SyntaxKind["DivisionOperator"] =
|
|
127
|
-
SyntaxKind[SyntaxKind["FloorDivisionOperator"] =
|
|
128
|
-
SyntaxKind[SyntaxKind["ModuloOperator"] =
|
|
129
|
-
SyntaxKind[SyntaxKind["PowerOperator"] =
|
|
130
|
-
SyntaxKind[SyntaxKind["NegationOperator"] =
|
|
129
|
+
SyntaxKind[SyntaxKind["AdditionOperator"] = 34] = "AdditionOperator";
|
|
130
|
+
SyntaxKind[SyntaxKind["SubtractionOperator"] = 35] = "SubtractionOperator";
|
|
131
|
+
SyntaxKind[SyntaxKind["MultiplicationOperator"] = 36] = "MultiplicationOperator";
|
|
132
|
+
SyntaxKind[SyntaxKind["DivisionOperator"] = 37] = "DivisionOperator";
|
|
133
|
+
SyntaxKind[SyntaxKind["FloorDivisionOperator"] = 38] = "FloorDivisionOperator";
|
|
134
|
+
SyntaxKind[SyntaxKind["ModuloOperator"] = 39] = "ModuloOperator";
|
|
135
|
+
SyntaxKind[SyntaxKind["PowerOperator"] = 40] = "PowerOperator";
|
|
136
|
+
SyntaxKind[SyntaxKind["NegationOperator"] = 41] = "NegationOperator";
|
|
131
137
|
// Concat
|
|
132
|
-
SyntaxKind[SyntaxKind["ConcatOperator"] =
|
|
138
|
+
SyntaxKind[SyntaxKind["ConcatOperator"] = 42] = "ConcatOperator";
|
|
133
139
|
// Length
|
|
134
|
-
SyntaxKind[SyntaxKind["LengthOperator"] =
|
|
140
|
+
SyntaxKind[SyntaxKind["LengthOperator"] = 43] = "LengthOperator";
|
|
135
141
|
// Relational Ops
|
|
136
|
-
SyntaxKind[SyntaxKind["EqualityOperator"] =
|
|
137
|
-
SyntaxKind[SyntaxKind["InequalityOperator"] =
|
|
138
|
-
SyntaxKind[SyntaxKind["LessThanOperator"] =
|
|
139
|
-
SyntaxKind[SyntaxKind["LessEqualOperator"] =
|
|
142
|
+
SyntaxKind[SyntaxKind["EqualityOperator"] = 44] = "EqualityOperator";
|
|
143
|
+
SyntaxKind[SyntaxKind["InequalityOperator"] = 45] = "InequalityOperator";
|
|
144
|
+
SyntaxKind[SyntaxKind["LessThanOperator"] = 46] = "LessThanOperator";
|
|
145
|
+
SyntaxKind[SyntaxKind["LessEqualOperator"] = 47] = "LessEqualOperator";
|
|
140
146
|
// Syntax Sugar `x > y` <=> `not (y <= x)`
|
|
141
147
|
// but we should probably use them to make the output code more readable
|
|
142
|
-
SyntaxKind[SyntaxKind["GreaterThanOperator"] =
|
|
143
|
-
SyntaxKind[SyntaxKind["GreaterEqualOperator"] =
|
|
148
|
+
SyntaxKind[SyntaxKind["GreaterThanOperator"] = 48] = "GreaterThanOperator";
|
|
149
|
+
SyntaxKind[SyntaxKind["GreaterEqualOperator"] = 49] = "GreaterEqualOperator";
|
|
144
150
|
// Logical
|
|
145
|
-
SyntaxKind[SyntaxKind["AndOperator"] =
|
|
146
|
-
SyntaxKind[SyntaxKind["OrOperator"] =
|
|
147
|
-
SyntaxKind[SyntaxKind["NotOperator"] =
|
|
151
|
+
SyntaxKind[SyntaxKind["AndOperator"] = 50] = "AndOperator";
|
|
152
|
+
SyntaxKind[SyntaxKind["OrOperator"] = 51] = "OrOperator";
|
|
153
|
+
SyntaxKind[SyntaxKind["NotOperator"] = 52] = "NotOperator";
|
|
148
154
|
// Bitwise
|
|
149
|
-
SyntaxKind[SyntaxKind["BitwiseAndOperator"] =
|
|
150
|
-
SyntaxKind[SyntaxKind["BitwiseOrOperator"] =
|
|
151
|
-
SyntaxKind[SyntaxKind["BitwiseExclusiveOrOperator"] =
|
|
152
|
-
SyntaxKind[SyntaxKind["BitwiseRightShiftOperator"] =
|
|
153
|
-
SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] =
|
|
154
|
-
SyntaxKind[SyntaxKind["BitwiseNotOperator"] =
|
|
155
|
+
SyntaxKind[SyntaxKind["BitwiseAndOperator"] = 53] = "BitwiseAndOperator";
|
|
156
|
+
SyntaxKind[SyntaxKind["BitwiseOrOperator"] = 54] = "BitwiseOrOperator";
|
|
157
|
+
SyntaxKind[SyntaxKind["BitwiseExclusiveOrOperator"] = 55] = "BitwiseExclusiveOrOperator";
|
|
158
|
+
SyntaxKind[SyntaxKind["BitwiseRightShiftOperator"] = 56] = "BitwiseRightShiftOperator";
|
|
159
|
+
SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] = 57] = "BitwiseLeftShiftOperator";
|
|
160
|
+
SyntaxKind[SyntaxKind["BitwiseNotOperator"] = 58] = "BitwiseNotOperator";
|
|
155
161
|
})(SyntaxKind || (exports.SyntaxKind = SyntaxKind = {}));
|
|
156
162
|
var NodeFlags;
|
|
157
163
|
(function (NodeFlags) {
|
|
@@ -337,6 +343,12 @@ function isBreakStatement(node) {
|
|
|
337
343
|
function createBreakStatement(tsOriginal) {
|
|
338
344
|
return createNode(SyntaxKind.BreakStatement, tsOriginal);
|
|
339
345
|
}
|
|
346
|
+
function isContinueStatement(node) {
|
|
347
|
+
return node.kind === SyntaxKind.ContinueStatement;
|
|
348
|
+
}
|
|
349
|
+
function createContinueStatement(tsOriginal) {
|
|
350
|
+
return createNode(SyntaxKind.ContinueStatement, tsOriginal);
|
|
351
|
+
}
|
|
340
352
|
function isExpressionStatement(node) {
|
|
341
353
|
return node.kind === SyntaxKind.ExpressionStatement;
|
|
342
354
|
}
|
|
@@ -510,4 +522,14 @@ function createParenthesizedExpression(expression, tsOriginal) {
|
|
|
510
522
|
parenthesizedExpression.expression = expression;
|
|
511
523
|
return parenthesizedExpression;
|
|
512
524
|
}
|
|
525
|
+
function isConditionalExpression(node) {
|
|
526
|
+
return node.kind === SyntaxKind.ConditionalExpression;
|
|
527
|
+
}
|
|
528
|
+
function createConditionalExpression(condition, whenTrue, whenFalse, tsOriginal) {
|
|
529
|
+
const conditionalExpression = createNode(SyntaxKind.ConditionalExpression, tsOriginal);
|
|
530
|
+
conditionalExpression.condition = condition;
|
|
531
|
+
conditionalExpression.whenTrue = whenTrue;
|
|
532
|
+
conditionalExpression.whenFalse = whenFalse;
|
|
533
|
+
return conditionalExpression;
|
|
534
|
+
}
|
|
513
535
|
//# sourceMappingURL=LuaAST.js.map
|
package/dist/LuaPrinter.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export declare class LuaPrinter {
|
|
|
54
54
|
printLabelStatement(statement: lua.LabelStatement): SourceNode;
|
|
55
55
|
printReturnStatement(statement: lua.ReturnStatement): SourceNode;
|
|
56
56
|
printBreakStatement(statement: lua.BreakStatement): SourceNode;
|
|
57
|
+
printContinueStatement(statement: lua.ContinueStatement): SourceNode;
|
|
57
58
|
printExpressionStatement(statement: lua.ExpressionStatement): SourceNode;
|
|
58
59
|
printExpression(expression: lua.Expression): SourceNode;
|
|
59
60
|
printStringLiteral(expression: lua.StringLiteral): SourceNode;
|
|
@@ -76,6 +77,7 @@ export declare class LuaPrinter {
|
|
|
76
77
|
printIdentifier(expression: lua.Identifier): SourceNode;
|
|
77
78
|
printTableIndexExpression(expression: lua.TableIndexExpression): SourceNode;
|
|
78
79
|
printParenthesizedExpression(expression: lua.ParenthesizedExpression): SourceNode;
|
|
80
|
+
printConditionalExpression(expression: lua.ConditionalExpression): SourceNode;
|
|
79
81
|
printOperator(kind: lua.Operator): SourceNode;
|
|
80
82
|
protected joinChunksWithComma(chunks: SourceChunk[]): SourceChunk[];
|
|
81
83
|
/**
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -260,6 +260,8 @@ class LuaPrinter {
|
|
|
260
260
|
return this.printReturnStatement(statement);
|
|
261
261
|
case lua.SyntaxKind.BreakStatement:
|
|
262
262
|
return this.printBreakStatement(statement);
|
|
263
|
+
case lua.SyntaxKind.ContinueStatement:
|
|
264
|
+
return this.printContinueStatement(statement);
|
|
263
265
|
case lua.SyntaxKind.ExpressionStatement:
|
|
264
266
|
return this.printExpressionStatement(statement);
|
|
265
267
|
default:
|
|
@@ -393,6 +395,9 @@ class LuaPrinter {
|
|
|
393
395
|
printBreakStatement(statement) {
|
|
394
396
|
return this.createSourceNode(statement, this.indent("break"));
|
|
395
397
|
}
|
|
398
|
+
printContinueStatement(statement) {
|
|
399
|
+
return this.createSourceNode(statement, this.indent("continue"));
|
|
400
|
+
}
|
|
396
401
|
printExpressionStatement(statement) {
|
|
397
402
|
return this.createSourceNode(statement, [this.indent(), this.printExpression(statement.expression)]);
|
|
398
403
|
}
|
|
@@ -432,6 +437,8 @@ class LuaPrinter {
|
|
|
432
437
|
return this.printTableIndexExpression(expression);
|
|
433
438
|
case lua.SyntaxKind.ParenthesizedExpression:
|
|
434
439
|
return this.printParenthesizedExpression(expression);
|
|
440
|
+
case lua.SyntaxKind.ConditionalExpression:
|
|
441
|
+
return this.printConditionalExpression(expression);
|
|
435
442
|
default:
|
|
436
443
|
throw new Error(`Tried to print unknown statement kind: ${lua.SyntaxKind[expression.kind]}`);
|
|
437
444
|
}
|
|
@@ -587,6 +594,16 @@ class LuaPrinter {
|
|
|
587
594
|
printParenthesizedExpression(expression) {
|
|
588
595
|
return this.createSourceNode(expression, ["(", this.printExpression(expression.expression), ")"]);
|
|
589
596
|
}
|
|
597
|
+
printConditionalExpression(expression) {
|
|
598
|
+
return this.createSourceNode(expression, [
|
|
599
|
+
"if ",
|
|
600
|
+
this.printExpression(expression.condition),
|
|
601
|
+
" then ",
|
|
602
|
+
this.printExpression(expression.whenTrue),
|
|
603
|
+
" else ",
|
|
604
|
+
this.printExpression(expression.whenFalse),
|
|
605
|
+
]);
|
|
606
|
+
}
|
|
590
607
|
printOperator(kind) {
|
|
591
608
|
return new source_map_1.SourceNode(null, null, this.relativeSourcePath, LuaPrinter.operatorMap[kind]);
|
|
592
609
|
}
|
|
@@ -5,3 +5,4 @@ export declare function transformBuiltinPropertyAccessExpression(context: Transf
|
|
|
5
5
|
export declare function transformBuiltinCallExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression | undefined;
|
|
6
6
|
export declare function transformBuiltinIdentifierExpression(context: TransformationContext, node: ts.Identifier, symbol: ts.Symbol | undefined): lua.Expression | undefined;
|
|
7
7
|
export declare function checkForLuaLibType(context: TransformationContext, type: ts.Type): void;
|
|
8
|
+
export declare function tryGetStandardLibrarySymbolOfType(context: TransformationContext, type: ts.Type): ts.Symbol | undefined;
|
|
@@ -4,6 +4,7 @@ exports.transformBuiltinPropertyAccessExpression = transformBuiltinPropertyAcces
|
|
|
4
4
|
exports.transformBuiltinCallExpression = transformBuiltinCallExpression;
|
|
5
5
|
exports.transformBuiltinIdentifierExpression = transformBuiltinIdentifierExpression;
|
|
6
6
|
exports.checkForLuaLibType = checkForLuaLibType;
|
|
7
|
+
exports.tryGetStandardLibrarySymbolOfType = tryGetStandardLibrarySymbolOfType;
|
|
7
8
|
const ts = require("typescript");
|
|
8
9
|
const lua = require("../../LuaAST");
|
|
9
10
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
@@ -104,3 +104,6 @@ export declare const cannotAssignToNodeOfKind: ((node: ts.Node, kind: lua.Syntax
|
|
|
104
104
|
export declare const incompleteFieldDecoratorWarning: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
105
105
|
code: number;
|
|
106
106
|
};
|
|
107
|
+
export declare const unsupportedArrayWithLengthConstructor: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
108
|
+
code: number;
|
|
109
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.incompleteFieldDecoratorWarning = exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
3
|
+
exports.unsupportedArrayWithLengthConstructor = exports.incompleteFieldDecoratorWarning = exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
@@ -64,4 +64,5 @@ exports.invalidMethodCallExtensionUse = createErrorDiagnosticFactory("This langu
|
|
|
64
64
|
exports.invalidSpreadInCallExtension = createErrorDiagnosticFactory("Spread elements are not supported in call extensions.");
|
|
65
65
|
exports.cannotAssignToNodeOfKind = createErrorDiagnosticFactory((kind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`);
|
|
66
66
|
exports.incompleteFieldDecoratorWarning = createWarningDiagnosticFactory("You are using a class field decorator, note that tstl ignores returned value initializers!");
|
|
67
|
+
exports.unsupportedArrayWithLengthConstructor = createErrorDiagnosticFactory(`Constructing new Array with length is not supported.`);
|
|
67
68
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -32,6 +32,7 @@ var LoopContinued;
|
|
|
32
32
|
(function (LoopContinued) {
|
|
33
33
|
LoopContinued[LoopContinued["WithGoto"] = 0] = "WithGoto";
|
|
34
34
|
LoopContinued[LoopContinued["WithRepeatBreak"] = 1] = "WithRepeatBreak";
|
|
35
|
+
LoopContinued[LoopContinued["WithContinue"] = 2] = "WithContinue";
|
|
35
36
|
})(LoopContinued || (exports.LoopContinued = LoopContinued = {}));
|
|
36
37
|
function* walkScopesUp(context) {
|
|
37
38
|
const scopeStack = context.scopeStack;
|
|
@@ -57,15 +57,23 @@ function isNumberType(context, type) {
|
|
|
57
57
|
function isExplicitArrayType(context, type) {
|
|
58
58
|
if (context.checker.isArrayType(type) || context.checker.isTupleType(type))
|
|
59
59
|
return true;
|
|
60
|
+
if (type.isUnionOrIntersection()) {
|
|
61
|
+
if (type.types.some(t => isExplicitArrayType(context, t))) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const baseTypes = type.getBaseTypes();
|
|
66
|
+
if (baseTypes) {
|
|
67
|
+
if (baseTypes.some(t => isExplicitArrayType(context, t))) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
60
71
|
if (type.symbol) {
|
|
61
72
|
const baseConstraint = context.checker.getBaseConstraintOfType(type);
|
|
62
73
|
if (baseConstraint && baseConstraint !== type) {
|
|
63
74
|
return isExplicitArrayType(context, baseConstraint);
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
|
-
if (type.isUnionOrIntersection()) {
|
|
67
|
-
return type.types.some(t => isExplicitArrayType(context, t));
|
|
68
|
-
}
|
|
69
77
|
return false;
|
|
70
78
|
}
|
|
71
79
|
function isAlwaysExplicitArrayType(context, type) {
|
|
@@ -12,11 +12,16 @@ exports.transformBreakStatement = transformBreakStatement;
|
|
|
12
12
|
const transformContinueStatement = (statement, context) => {
|
|
13
13
|
var _a;
|
|
14
14
|
const scope = (0, scope_1.findScope)(context, scope_1.ScopeType.Loop);
|
|
15
|
-
const continuedWith =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: scope_1.LoopContinued.WithGoto
|
|
15
|
+
const continuedWith = {
|
|
16
|
+
[CompilerOptions_1.LuaTarget.Universal]: scope_1.LoopContinued.WithRepeatBreak,
|
|
17
|
+
[CompilerOptions_1.LuaTarget.Lua50]: scope_1.LoopContinued.WithRepeatBreak,
|
|
18
|
+
[CompilerOptions_1.LuaTarget.Lua51]: scope_1.LoopContinued.WithRepeatBreak,
|
|
19
|
+
[CompilerOptions_1.LuaTarget.Lua52]: scope_1.LoopContinued.WithGoto,
|
|
20
|
+
[CompilerOptions_1.LuaTarget.Lua53]: scope_1.LoopContinued.WithGoto,
|
|
21
|
+
[CompilerOptions_1.LuaTarget.Lua54]: scope_1.LoopContinued.WithGoto,
|
|
22
|
+
[CompilerOptions_1.LuaTarget.LuaJIT]: scope_1.LoopContinued.WithGoto,
|
|
23
|
+
[CompilerOptions_1.LuaTarget.Luau]: scope_1.LoopContinued.WithContinue,
|
|
24
|
+
}[context.luaTarget];
|
|
20
25
|
if (scope) {
|
|
21
26
|
scope.loopContinued = continuedWith;
|
|
22
27
|
}
|
|
@@ -24,6 +29,8 @@ const transformContinueStatement = (statement, context) => {
|
|
|
24
29
|
switch (continuedWith) {
|
|
25
30
|
case scope_1.LoopContinued.WithGoto:
|
|
26
31
|
return lua.createGotoStatement(label, statement);
|
|
32
|
+
case scope_1.LoopContinued.WithContinue:
|
|
33
|
+
return lua.createContinueStatement(statement);
|
|
27
34
|
case scope_1.LoopContinued.WithRepeatBreak:
|
|
28
35
|
return [
|
|
29
36
|
lua.createAssignmentStatement(lua.createIdentifier(label), lua.createBooleanLiteral(true), statement),
|
|
@@ -7,19 +7,41 @@ const diagnostics_1 = require("../../utils/diagnostics");
|
|
|
7
7
|
const lualib_1 = require("../../utils/lualib");
|
|
8
8
|
const call_1 = require("../call");
|
|
9
9
|
const table_1 = require("../language-extensions/table");
|
|
10
|
+
const builtins_1 = require("../../builtins");
|
|
10
11
|
const transformNewExpression = (node, context) => {
|
|
11
|
-
var _a, _b;
|
|
12
|
+
var _a, _b, _c;
|
|
12
13
|
if ((0, table_1.isTableNewCall)(context, node)) {
|
|
13
14
|
return lua.createTableExpression(undefined, node);
|
|
14
15
|
}
|
|
16
|
+
const constructorType = context.checker.getTypeAtLocation(node.expression);
|
|
17
|
+
if (((_a = (0, builtins_1.tryGetStandardLibrarySymbolOfType)(context, constructorType)) === null || _a === void 0 ? void 0 : _a.name) === "ArrayConstructor") {
|
|
18
|
+
if (node.arguments === undefined || node.arguments.length === 0) {
|
|
19
|
+
// turn new Array<>() into a simple {}
|
|
20
|
+
return lua.createTableExpression([], node);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// More than one argument, check if items constructor
|
|
24
|
+
const signature = context.checker.getResolvedSignature(node);
|
|
25
|
+
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
26
|
+
if ((signatureDeclaration === null || signatureDeclaration === void 0 ? void 0 : signatureDeclaration.parameters.length) === 1 &&
|
|
27
|
+
signatureDeclaration.parameters[0].dotDotDotToken === undefined) {
|
|
28
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedArrayWithLengthConstructor)(node));
|
|
29
|
+
return lua.createTableExpression([], node);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const callArguments = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
33
|
+
return lua.createTableExpression(callArguments.map(e => lua.createTableFieldExpression(e)), node);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
15
37
|
const signature = context.checker.getResolvedSignature(node);
|
|
16
|
-
const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (
|
|
38
|
+
const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (_b = node.arguments) !== null && _b !== void 0 ? _b : [], signature);
|
|
17
39
|
const type = context.checker.getTypeAtLocation(node);
|
|
18
40
|
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
19
41
|
const customConstructorAnnotation = annotations.get(annotations_1.AnnotationKind.CustomConstructor);
|
|
20
42
|
if (customConstructorAnnotation) {
|
|
21
43
|
if (customConstructorAnnotation.args.length === 1) {
|
|
22
|
-
return lua.createCallExpression(lua.createIdentifier(customConstructorAnnotation.args[0]), (0, call_1.transformArguments)(context, (
|
|
44
|
+
return lua.createCallExpression(lua.createIdentifier(customConstructorAnnotation.args[0]), (0, call_1.transformArguments)(context, (_c = node.arguments) !== null && _c !== void 0 ? _c : []), node);
|
|
23
45
|
}
|
|
24
46
|
else {
|
|
25
47
|
context.diagnostics.push((0, diagnostics_1.annotationInvalidArgumentCount)(node, annotations_1.AnnotationKind.CustomConstructor, customConstructorAnnotation.args.length, 1));
|
|
@@ -10,6 +10,7 @@ const scope_1 = require("../utils/scope");
|
|
|
10
10
|
const block_1 = require("./block");
|
|
11
11
|
const typescript_1 = require("../utils/typescript");
|
|
12
12
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
13
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
13
14
|
function transformProtectedConditionalExpression(context, expression, condition, whenTrue, whenFalse) {
|
|
14
15
|
const tempVar = context.createTempNameForNode(expression.condition);
|
|
15
16
|
const trueStatements = whenTrue.precedingStatements.concat(lua.createAssignmentStatement(lua.cloneIdentifier(tempVar), whenTrue.result, expression.whenTrue));
|
|
@@ -22,6 +23,10 @@ function transformProtectedConditionalExpression(context, expression, condition,
|
|
|
22
23
|
return lua.cloneIdentifier(tempVar);
|
|
23
24
|
}
|
|
24
25
|
const transformConditionalExpression = (expression, context) => {
|
|
26
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Luau) {
|
|
27
|
+
// Luau's ternary operator doesn't have these issues
|
|
28
|
+
return lua.createConditionalExpression(context.transformExpression(expression.condition), context.transformExpression(expression.whenTrue), context.transformExpression(expression.whenFalse), expression);
|
|
29
|
+
}
|
|
25
30
|
// Check if we need to add diagnostic about Lua truthiness
|
|
26
31
|
checkOnlyTruthyCondition(expression.condition, context);
|
|
27
32
|
const condition = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.condition));
|
|
@@ -21,6 +21,7 @@ function transformLoopBody(context, loop) {
|
|
|
21
21
|
const scopeId = scope.id;
|
|
22
22
|
switch (scope.loopContinued) {
|
|
23
23
|
case undefined:
|
|
24
|
+
case scope_1.LoopContinued.WithContinue:
|
|
24
25
|
return body;
|
|
25
26
|
case scope_1.LoopContinued.WithGoto:
|
|
26
27
|
return [lua.createDoStatement(body), lua.createLabelStatement(`__continue${scopeId}`)];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.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/",
|