typescript-to-lua 1.3.0 → 1.3.1
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/transformation/builtins/index.js +7 -5
- package/dist/transformation/utils/diagnostics.d.ts +0 -6
- package/dist/transformation/utils/diagnostics.js +1 -3
- package/dist/transformation/visitors/call.js +6 -39
- package/dist/transformation/visitors/expression-statement.d.ts +3 -1
- package/dist/transformation/visitors/expression-statement.js +21 -19
- package/dist/transformation/visitors/function.js +5 -2
- package/dist/transformation/visitors/identifier.js +2 -1
- package/dist/transformation/visitors/language-extensions/index.d.ts +4 -0
- package/dist/transformation/visitors/language-extensions/index.js +17 -0
- package/dist/transformation/visitors/language-extensions/operators.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/operators.js +7 -2
- package/dist/transformation/visitors/language-extensions/table.d.ts +1 -8
- package/dist/transformation/visitors/language-extensions/table.js +55 -53
- package/dist/transformation/visitors/variable-declaration.js +12 -6
- package/dist/transformation/visitors/void.d.ts +1 -4
- package/dist/transformation/visitors/void.js +6 -8
- package/package.json +1 -1
|
@@ -42,12 +42,18 @@ function transformBuiltinPropertyAccessExpression(context, node) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.transformBuiltinPropertyAccessExpression = transformBuiltinPropertyAccessExpression;
|
|
44
44
|
function transformBuiltinCallExpression(context, node, isOptionalCall) {
|
|
45
|
+
const unsupportedOptionalCall = () => {
|
|
46
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
47
|
+
return lua.createNilLiteral();
|
|
48
|
+
};
|
|
45
49
|
const expressionType = context.checker.getTypeAtLocation(node.expression);
|
|
46
50
|
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, expressionType, undefined)) {
|
|
47
51
|
// TODO:
|
|
48
52
|
(0, new_1.checkForLuaLibType)(context, expressionType);
|
|
49
53
|
const result = (0, global_1.transformGlobalCall)(context, node);
|
|
50
54
|
if (result) {
|
|
55
|
+
if (isOptionalCall)
|
|
56
|
+
return unsupportedOptionalCall();
|
|
51
57
|
return result;
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -55,12 +61,8 @@ function transformBuiltinCallExpression(context, node, isOptionalCall) {
|
|
|
55
61
|
if (!ts.isPropertyAccessExpression(expression)) {
|
|
56
62
|
return;
|
|
57
63
|
}
|
|
58
|
-
(0, utils_1.assume)(node);
|
|
59
64
|
const isOptionalAccess = expression.questionDotToken;
|
|
60
|
-
|
|
61
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
62
|
-
return lua.createNilLiteral();
|
|
63
|
-
};
|
|
65
|
+
(0, utils_1.assume)(node);
|
|
64
66
|
// If the function being called is of type owner.func, get the type of owner
|
|
65
67
|
const ownerType = context.checker.getTypeAtLocation(expression.expression);
|
|
66
68
|
if ((0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
|
|
@@ -76,12 +76,6 @@ export declare const invalidOperatorMappingUse: ((node: ts.Node, ...args: any[])
|
|
|
76
76
|
export declare const invalidTableExtensionUse: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
77
77
|
code: number;
|
|
78
78
|
};
|
|
79
|
-
export declare const invalidTableDeleteExpression: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
80
|
-
code: number;
|
|
81
|
-
};
|
|
82
|
-
export declare const invalidTableSetExpression: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
83
|
-
code: number;
|
|
84
|
-
};
|
|
85
79
|
export declare const annotationRemoved: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
|
|
86
80
|
code: number;
|
|
87
81
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.
|
|
3
|
+
exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = 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 CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
@@ -51,8 +51,6 @@ exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = createErrorDiagnosticFact
|
|
|
51
51
|
exports.invalidMultiReturnAccess = createErrorDiagnosticFactory("The LuaMultiReturn type can only be accessed via an element access expression of a numeric type.");
|
|
52
52
|
exports.invalidOperatorMappingUse = createErrorDiagnosticFactory("This function must always be directly called and cannot be referred to.");
|
|
53
53
|
exports.invalidTableExtensionUse = createErrorDiagnosticFactory("This function must be called directly and cannot be referred to.");
|
|
54
|
-
exports.invalidTableDeleteExpression = createErrorDiagnosticFactory("Table delete extension can only be called as a stand-alone statement. It cannot be used as an expression in another statement.");
|
|
55
|
-
exports.invalidTableSetExpression = createErrorDiagnosticFactory("Table set extension can only be called as a stand-alone statement. It cannot be used as an expression in another statement.");
|
|
56
54
|
exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' has been removed and will no longer have any effect.` +
|
|
57
55
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
58
56
|
exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
|
|
@@ -12,12 +12,11 @@ const safe_names_1 = require("../utils/safe-names");
|
|
|
12
12
|
const typescript_1 = require("../utils/typescript");
|
|
13
13
|
const access_1 = require("./access");
|
|
14
14
|
const multi_1 = require("./language-extensions/multi");
|
|
15
|
-
const operators_1 = require("./language-extensions/operators");
|
|
16
|
-
const table_1 = require("./language-extensions/table");
|
|
17
15
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
18
16
|
const expression_list_1 = require("./expression-list");
|
|
19
17
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
20
18
|
const optional_chaining_1 = require("./optional-chaining");
|
|
19
|
+
const language_extensions_1 = require("./language-extensions");
|
|
21
20
|
function validateArguments(context, params, signature) {
|
|
22
21
|
if (!signature || signature.parameters.length < params.length) {
|
|
23
22
|
return;
|
|
@@ -145,6 +144,7 @@ function transformElementCall(context, node) {
|
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
const transformCallExpression = (node, context) => {
|
|
147
|
+
var _a;
|
|
148
148
|
if (ts.isOptionalChain(node)) {
|
|
149
149
|
return (0, optional_chaining_1.transformOptionalChain)(context, node);
|
|
150
150
|
}
|
|
@@ -152,46 +152,13 @@ const transformCallExpression = (node, context) => {
|
|
|
152
152
|
? (0, optional_chaining_1.getOptionalContinuationData)(node.expression)
|
|
153
153
|
: undefined;
|
|
154
154
|
const wrapResultInTable = (0, multi_1.isMultiReturnCall)(context, node) && (0, multi_1.shouldMultiReturnCallBeWrapped)(context, node);
|
|
155
|
-
const builtinResult = (0, builtins_1.transformBuiltinCallExpression)(context, node, optionalContinuation !== undefined);
|
|
156
|
-
if (builtinResult) {
|
|
157
|
-
if (optionalContinuation) {
|
|
158
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
159
|
-
}
|
|
160
|
-
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinResult) : builtinResult;
|
|
161
|
-
}
|
|
162
155
|
if ((0, annotations_1.isTupleReturnCall)(context, node)) {
|
|
163
156
|
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
164
157
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
return (0, operators_1.transformOperatorMappingExpression)(context, node);
|
|
171
|
-
}
|
|
172
|
-
if ((0, table_1.isTableDeleteCall)(context, node)) {
|
|
173
|
-
context.diagnostics.push((0, diagnostics_1.invalidTableDeleteExpression)(node));
|
|
174
|
-
context.addPrecedingStatements((0, table_1.transformTableDeleteExpression)(context, node));
|
|
175
|
-
return lua.createNilLiteral();
|
|
176
|
-
}
|
|
177
|
-
if ((0, table_1.isTableGetCall)(context, node)) {
|
|
178
|
-
if (optionalContinuation) {
|
|
179
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
180
|
-
return lua.createNilLiteral();
|
|
181
|
-
}
|
|
182
|
-
return (0, table_1.transformTableGetExpression)(context, node);
|
|
183
|
-
}
|
|
184
|
-
if ((0, table_1.isTableHasCall)(context, node)) {
|
|
185
|
-
if (optionalContinuation) {
|
|
186
|
-
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
187
|
-
return lua.createNilLiteral();
|
|
188
|
-
}
|
|
189
|
-
return (0, table_1.transformTableHasExpression)(context, node);
|
|
190
|
-
}
|
|
191
|
-
if ((0, table_1.isTableSetCall)(context, node)) {
|
|
192
|
-
context.diagnostics.push((0, diagnostics_1.invalidTableSetExpression)(node));
|
|
193
|
-
context.addPrecedingStatements((0, table_1.transformTableSetExpression)(context, node));
|
|
194
|
-
return lua.createNilLiteral();
|
|
158
|
+
const builtinOrExtensionResult = (_a = (0, builtins_1.transformBuiltinCallExpression)(context, node, optionalContinuation !== undefined)) !== null && _a !== void 0 ? _a : (0, language_extensions_1.transformLanguageExtensionCallExpression)(context, node, optionalContinuation !== undefined);
|
|
159
|
+
if (builtinOrExtensionResult) {
|
|
160
|
+
// unsupportedOptionalCall diagnostic already present
|
|
161
|
+
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinOrExtensionResult) : builtinOrExtensionResult;
|
|
195
162
|
}
|
|
196
163
|
if (ts.isPropertyAccessExpression(node.expression)) {
|
|
197
164
|
const ownerType = context.checker.getTypeAtLocation(node.expression.expression);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import
|
|
2
|
+
import * as lua from "../../LuaAST";
|
|
3
|
+
import { FunctionVisitor, TransformationContext } from "../context";
|
|
3
4
|
export declare const transformExpressionStatement: FunctionVisitor<ts.ExpressionStatement>;
|
|
5
|
+
export declare function transformExpressionToStatement(context: TransformationContext, expression: ts.Expression): lua.Statement | undefined;
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformExpressionStatement = void 0;
|
|
4
|
-
const ts = require("typescript");
|
|
3
|
+
exports.transformExpressionToStatement = exports.transformExpressionStatement = void 0;
|
|
5
4
|
const lua = require("../../LuaAST");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
6
|
const binary_expression_1 = require("./binary-expression");
|
|
7
|
-
const table_1 = require("./language-extensions/table");
|
|
8
7
|
const unary_expression_1 = require("./unary-expression");
|
|
9
|
-
const void_1 = require("./void");
|
|
10
8
|
const transformExpressionStatement = (node, context) => {
|
|
11
|
-
const expression = node.expression;
|
|
12
|
-
if (ts.isCallExpression(expression) && (0, table_1.isTableDeleteCall)(context, expression)) {
|
|
13
|
-
return (0, table_1.transformTableDeleteExpression)(context, expression);
|
|
14
|
-
}
|
|
15
|
-
if (ts.isCallExpression(expression) && (0, table_1.isTableSetCall)(context, expression)) {
|
|
16
|
-
return (0, table_1.transformTableSetExpression)(context, expression);
|
|
17
|
-
}
|
|
18
|
-
if (ts.isVoidExpression(expression)) {
|
|
19
|
-
return (0, void_1.transformVoidExpressionStatement)(expression, context);
|
|
20
|
-
}
|
|
21
9
|
const unaryExpressionResult = (0, unary_expression_1.transformUnaryExpressionStatement)(context, node);
|
|
22
10
|
if (unaryExpressionResult) {
|
|
23
11
|
return unaryExpressionResult;
|
|
@@ -26,11 +14,25 @@ const transformExpressionStatement = (node, context) => {
|
|
|
26
14
|
if (binaryExpressionResult) {
|
|
27
15
|
return binaryExpressionResult;
|
|
28
16
|
}
|
|
29
|
-
|
|
30
|
-
return lua.isCallExpression(result) || lua.isMethodCallExpression(result)
|
|
31
|
-
? lua.createExpressionStatement(result)
|
|
32
|
-
: // Assign expression statements to dummy to make sure they're legal Lua
|
|
33
|
-
lua.createVariableDeclarationStatement(lua.createAnonymousIdentifier(), result);
|
|
17
|
+
return transformExpressionToStatement(context, node.expression);
|
|
34
18
|
};
|
|
35
19
|
exports.transformExpressionStatement = transformExpressionStatement;
|
|
20
|
+
function transformExpressionToStatement(context, expression) {
|
|
21
|
+
const result = context.transformExpression(expression);
|
|
22
|
+
const isTempVariable = lua.isIdentifier(result) && result.symbolId === context_1.tempSymbolId;
|
|
23
|
+
if (isTempVariable) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// "synthetic": no side effects and no original source
|
|
27
|
+
const isSyntheticExpression = (lua.isIdentifier(result) || lua.isLiteral(result)) && result.line === undefined;
|
|
28
|
+
if (isSyntheticExpression) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (lua.isCallExpression(result) || lua.isMethodCallExpression(result)) {
|
|
32
|
+
return lua.createExpressionStatement(result);
|
|
33
|
+
}
|
|
34
|
+
// Assign expression statements to dummy to make sure they're legal Lua
|
|
35
|
+
return lua.createVariableDeclarationStatement(lua.createAnonymousIdentifier(), result);
|
|
36
|
+
}
|
|
37
|
+
exports.transformExpressionToStatement = transformExpressionToStatement;
|
|
36
38
|
//# sourceMappingURL=expression-statement.js.map
|
|
@@ -195,8 +195,9 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
195
195
|
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
196
196
|
}
|
|
197
197
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
198
|
+
const isNamedFunctionExpression = ts.isFunctionExpression(node) && node.name;
|
|
198
199
|
// Handle named function expressions which reference themselves
|
|
199
|
-
if (
|
|
200
|
+
if (isNamedFunctionExpression && functionScope.referencedSymbols) {
|
|
200
201
|
const symbol = context.checker.getSymbolAtLocation(node.name);
|
|
201
202
|
if (symbol) {
|
|
202
203
|
// TODO: Not using symbol ids because of https://github.com/microsoft/TypeScript/issues/37131
|
|
@@ -217,7 +218,9 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
|
-
return
|
|
221
|
+
return isNamedFunctionExpression && isFunctionTypeWithProperties(context.checker.getTypeAtLocation(node))
|
|
222
|
+
? createCallableTable(functionExpression)
|
|
223
|
+
: functionExpression;
|
|
221
224
|
}
|
|
222
225
|
exports.transformFunctionLikeDeclaration = transformFunctionLikeDeclaration;
|
|
223
226
|
const transformFunctionDeclaration = (node, context) => {
|
|
@@ -5,6 +5,7 @@ const ts = require("typescript");
|
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const builtins_1 = require("../builtins");
|
|
7
7
|
const promise_1 = require("../builtins/promise");
|
|
8
|
+
const context_1 = require("../context");
|
|
8
9
|
const annotations_1 = require("../utils/annotations");
|
|
9
10
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
10
11
|
const export_1 = require("../utils/export");
|
|
@@ -19,7 +20,7 @@ const vararg_1 = require("./language-extensions/vararg");
|
|
|
19
20
|
const optional_chaining_1 = require("./optional-chaining");
|
|
20
21
|
function transformIdentifier(context, identifier) {
|
|
21
22
|
if ((0, optional_chaining_1.isOptionalContinuation)(identifier)) {
|
|
22
|
-
return lua.createIdentifier(identifier.text);
|
|
23
|
+
return lua.createIdentifier(identifier.text, undefined, context_1.tempSymbolId);
|
|
23
24
|
}
|
|
24
25
|
if ((0, multi_1.isMultiFunctionNode)(context, identifier)) {
|
|
25
26
|
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(identifier));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransformationContext } from "../../context";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import * as lua from "../../../LuaAST";
|
|
4
|
+
export declare function transformLanguageExtensionCallExpression(context: TransformationContext, node: ts.CallExpression, isOptionalCall: boolean): lua.Expression | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformLanguageExtensionCallExpression = void 0;
|
|
4
|
+
const operators_1 = require("./operators");
|
|
5
|
+
const table_1 = require("./table");
|
|
6
|
+
function transformLanguageExtensionCallExpression(context, node, isOptionalCall) {
|
|
7
|
+
const operatorMapping = (0, operators_1.transformOperatorMappingExpression)(context, node, isOptionalCall);
|
|
8
|
+
if (operatorMapping) {
|
|
9
|
+
return operatorMapping;
|
|
10
|
+
}
|
|
11
|
+
const tableCall = (0, table_1.transformTableExtensionCall)(context, node, isOptionalCall);
|
|
12
|
+
if (tableCall) {
|
|
13
|
+
return tableCall;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.transformLanguageExtensionCallExpression = transformLanguageExtensionCallExpression;
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -2,4 +2,4 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../../context";
|
|
4
4
|
export declare function isOperatorMapping(context: TransformationContext, node: ts.CallExpression | ts.Identifier): boolean;
|
|
5
|
-
export declare function transformOperatorMappingExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression;
|
|
5
|
+
export declare function transformOperatorMappingExpression(context: TransformationContext, node: ts.CallExpression, isOptionalCall: boolean): lua.Expression | undefined;
|
|
@@ -77,9 +77,14 @@ function isOperatorMapping(context, node) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
exports.isOperatorMapping = isOperatorMapping;
|
|
80
|
-
function transformOperatorMappingExpression(context, node) {
|
|
80
|
+
function transformOperatorMappingExpression(context, node, isOptionalCall) {
|
|
81
81
|
const extensionKind = getOperatorMapExtensionKindForCall(context, node);
|
|
82
|
-
|
|
82
|
+
if (!extensionKind)
|
|
83
|
+
return undefined;
|
|
84
|
+
if (isOptionalCall) {
|
|
85
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
86
|
+
return lua.createNilLiteral();
|
|
87
|
+
}
|
|
83
88
|
const isBefore53 = context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
84
89
|
context.luaTarget === CompilerOptions_1.LuaTarget.Lua52 ||
|
|
85
90
|
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT ||
|
|
@@ -2,12 +2,5 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../../context";
|
|
4
4
|
export declare function isTableExtensionIdentifier(context: TransformationContext, node: ts.Identifier): boolean;
|
|
5
|
-
export declare function isTableDeleteCall(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
6
|
-
export declare function isTableGetCall(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
7
|
-
export declare function isTableHasCall(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
8
|
-
export declare function isTableSetCall(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
9
5
|
export declare function isTableNewCall(context: TransformationContext, node: ts.NewExpression): boolean;
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function transformTableGetExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression;
|
|
12
|
-
export declare function transformTableHasExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression;
|
|
13
|
-
export declare function transformTableSetExpression(context: TransformationContext, node: ts.CallExpression): lua.Statement;
|
|
6
|
+
export declare function transformTableExtensionCall(context: TransformationContext, node: ts.CallExpression, isOptionalCall: boolean): lua.Expression | undefined;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.transformTableExtensionCall = exports.isTableNewCall = exports.isTableExtensionIdentifier = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
6
|
const extensions = require("../../utils/language-extensions");
|
|
7
7
|
const typescript_1 = require("../../utils/typescript");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const expression_list_1 = require("../expression-list");
|
|
9
|
+
const diagnostics_1 = require("../../utils/diagnostics");
|
|
10
|
+
const tableCallExtensions = [
|
|
10
11
|
extensions.ExtensionKind.TableDeleteType,
|
|
11
12
|
extensions.ExtensionKind.TableDeleteMethodType,
|
|
13
|
+
extensions.ExtensionKind.TableGetType,
|
|
14
|
+
extensions.ExtensionKind.TableGetMethodType,
|
|
15
|
+
extensions.ExtensionKind.TableHasType,
|
|
16
|
+
extensions.ExtensionKind.TableHasMethodType,
|
|
17
|
+
extensions.ExtensionKind.TableSetType,
|
|
18
|
+
extensions.ExtensionKind.TableSetMethodType,
|
|
12
19
|
];
|
|
13
|
-
const
|
|
14
|
-
const tableHasExtensions = [extensions.ExtensionKind.TableHasType, extensions.ExtensionKind.TableHasMethodType];
|
|
15
|
-
const tableSetExtensions = [extensions.ExtensionKind.TableSetType, extensions.ExtensionKind.TableSetMethodType];
|
|
16
|
-
const tableExtensions = [
|
|
17
|
-
extensions.ExtensionKind.TableNewType,
|
|
18
|
-
...tableDeleteExtensions,
|
|
19
|
-
...tableGetExtensions,
|
|
20
|
-
...tableHasExtensions,
|
|
21
|
-
...tableSetExtensions,
|
|
22
|
-
];
|
|
20
|
+
const tableExtensions = [extensions.ExtensionKind.TableNewType, ...tableCallExtensions];
|
|
23
21
|
function getTableExtensionKindForCall(context, node, validExtensions) {
|
|
24
22
|
const type = (0, typescript_1.getFunctionTypeForCall)(context, node);
|
|
25
23
|
return type && validExtensions.find(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
@@ -29,79 +27,83 @@ function isTableExtensionIdentifier(context, node) {
|
|
|
29
27
|
return tableExtensions.some(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
30
28
|
}
|
|
31
29
|
exports.isTableExtensionIdentifier = isTableExtensionIdentifier;
|
|
32
|
-
function isTableDeleteCall(context, node) {
|
|
33
|
-
return getTableExtensionKindForCall(context, node, tableDeleteExtensions) !== undefined;
|
|
34
|
-
}
|
|
35
|
-
exports.isTableDeleteCall = isTableDeleteCall;
|
|
36
|
-
function isTableGetCall(context, node) {
|
|
37
|
-
return getTableExtensionKindForCall(context, node, tableGetExtensions) !== undefined;
|
|
38
|
-
}
|
|
39
|
-
exports.isTableGetCall = isTableGetCall;
|
|
40
|
-
function isTableHasCall(context, node) {
|
|
41
|
-
return getTableExtensionKindForCall(context, node, tableHasExtensions) !== undefined;
|
|
42
|
-
}
|
|
43
|
-
exports.isTableHasCall = isTableHasCall;
|
|
44
|
-
function isTableSetCall(context, node) {
|
|
45
|
-
return getTableExtensionKindForCall(context, node, tableSetExtensions) !== undefined;
|
|
46
|
-
}
|
|
47
|
-
exports.isTableSetCall = isTableSetCall;
|
|
48
30
|
function isTableNewCall(context, node) {
|
|
49
31
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
50
32
|
return extensions.isExtensionType(type, extensions.ExtensionKind.TableNewType);
|
|
51
33
|
}
|
|
52
34
|
exports.isTableNewCall = isTableNewCall;
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
|
|
35
|
+
function transformTableExtensionCall(context, node, isOptionalCall) {
|
|
36
|
+
const extensionType = getTableExtensionKindForCall(context, node, tableCallExtensions);
|
|
37
|
+
if (!extensionType)
|
|
38
|
+
return;
|
|
39
|
+
if (isOptionalCall) {
|
|
40
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
41
|
+
return lua.createNilLiteral();
|
|
42
|
+
}
|
|
43
|
+
if (extensionType === extensions.ExtensionKind.TableDeleteType ||
|
|
44
|
+
extensionType === extensions.ExtensionKind.TableDeleteMethodType) {
|
|
45
|
+
return transformTableDeleteExpression(context, node, extensionType);
|
|
46
|
+
}
|
|
47
|
+
if (extensionType === extensions.ExtensionKind.TableGetType ||
|
|
48
|
+
extensionType === extensions.ExtensionKind.TableGetMethodType) {
|
|
49
|
+
return transformTableGetExpression(context, node, extensionType);
|
|
50
|
+
}
|
|
51
|
+
if (extensionType === extensions.ExtensionKind.TableHasType ||
|
|
52
|
+
extensionType === extensions.ExtensionKind.TableHasMethodType) {
|
|
53
|
+
return transformTableHasExpression(context, node, extensionType);
|
|
54
|
+
}
|
|
55
|
+
if (extensionType === extensions.ExtensionKind.TableSetType ||
|
|
56
|
+
extensionType === extensions.ExtensionKind.TableSetMethodType) {
|
|
57
|
+
return transformTableSetExpression(context, node, extensionType);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.transformTableExtensionCall = transformTableExtensionCall;
|
|
61
|
+
function transformTableDeleteExpression(context, node, extensionKind) {
|
|
56
62
|
const args = node.arguments.slice();
|
|
57
|
-
if (
|
|
63
|
+
if (extensionKind === extensions.ExtensionKind.TableDeleteMethodType &&
|
|
58
64
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
59
65
|
// In case of method (no table argument), push method owner to front of args list
|
|
60
66
|
args.unshift(node.expression.expression);
|
|
61
67
|
}
|
|
62
68
|
// arg0[arg1] = nil
|
|
63
|
-
|
|
69
|
+
const [table, accessExpression] = (0, expression_list_1.transformExpressionList)(context, args);
|
|
70
|
+
context.addPrecedingStatements(lua.createAssignmentStatement(lua.createTableIndexExpression(table, accessExpression), lua.createNilLiteral(), node));
|
|
71
|
+
return lua.createBooleanLiteral(true);
|
|
64
72
|
}
|
|
65
|
-
|
|
66
|
-
function transformTableGetExpression(context, node) {
|
|
67
|
-
const extensionKind = getTableExtensionKindForCall(context, node, tableGetExtensions);
|
|
68
|
-
(0, utils_1.assert)(extensionKind);
|
|
73
|
+
function transformTableGetExpression(context, node, extensionKind) {
|
|
69
74
|
const args = node.arguments.slice();
|
|
70
|
-
if (
|
|
75
|
+
if (extensionKind === extensions.ExtensionKind.TableGetMethodType &&
|
|
71
76
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
72
77
|
// In case of method (no table argument), push method owner to front of args list
|
|
73
78
|
args.unshift(node.expression.expression);
|
|
74
79
|
}
|
|
80
|
+
const [table, accessExpression] = (0, expression_list_1.transformExpressionList)(context, args);
|
|
75
81
|
// arg0[arg1]
|
|
76
|
-
return lua.createTableIndexExpression(
|
|
82
|
+
return lua.createTableIndexExpression(table, accessExpression, node);
|
|
77
83
|
}
|
|
78
|
-
|
|
79
|
-
function transformTableHasExpression(context, node) {
|
|
80
|
-
const extensionKind = getTableExtensionKindForCall(context, node, tableHasExtensions);
|
|
81
|
-
(0, utils_1.assert)(extensionKind);
|
|
84
|
+
function transformTableHasExpression(context, node, extensionKind) {
|
|
82
85
|
const args = node.arguments.slice();
|
|
83
|
-
if (
|
|
86
|
+
if (extensionKind === extensions.ExtensionKind.TableHasMethodType &&
|
|
84
87
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
85
88
|
// In case of method (no table argument), push method owner to front of args list
|
|
86
89
|
args.unshift(node.expression.expression);
|
|
87
90
|
}
|
|
88
91
|
// arg0[arg1]
|
|
89
|
-
const
|
|
92
|
+
const [table, accessExpression] = (0, expression_list_1.transformExpressionList)(context, args);
|
|
93
|
+
const tableIndexExpression = lua.createTableIndexExpression(table, accessExpression);
|
|
90
94
|
// arg0[arg1] ~= nil
|
|
91
95
|
return lua.createBinaryExpression(tableIndexExpression, lua.createNilLiteral(), lua.SyntaxKind.InequalityOperator, node);
|
|
92
96
|
}
|
|
93
|
-
|
|
94
|
-
function transformTableSetExpression(context, node) {
|
|
95
|
-
const extensionKind = getTableExtensionKindForCall(context, node, tableSetExtensions);
|
|
96
|
-
(0, utils_1.assert)(extensionKind);
|
|
97
|
+
function transformTableSetExpression(context, node, extensionKind) {
|
|
97
98
|
const args = node.arguments.slice();
|
|
98
|
-
if (
|
|
99
|
+
if (extensionKind === extensions.ExtensionKind.TableSetMethodType &&
|
|
99
100
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
100
101
|
// In case of method (no table argument), push method owner to front of args list
|
|
101
102
|
args.unshift(node.expression.expression);
|
|
102
103
|
}
|
|
103
104
|
// arg0[arg1] = arg2
|
|
104
|
-
|
|
105
|
+
const [table, accessExpression, value] = (0, expression_list_1.transformExpressionList)(context, args);
|
|
106
|
+
context.addPrecedingStatements(lua.createAssignmentStatement(lua.createTableIndexExpression(table, accessExpression), value, node));
|
|
107
|
+
return lua.createNilLiteral();
|
|
105
108
|
}
|
|
106
|
-
exports.transformTableSetExpression = transformTableSetExpression;
|
|
107
109
|
//# sourceMappingURL=table.js.map
|
|
@@ -186,12 +186,7 @@ function transformVariableDeclaration(context, statement) {
|
|
|
186
186
|
const value = statement.initializer && context.transformExpression(statement.initializer);
|
|
187
187
|
// Wrap functions being assigned to a type that contains additional properties in a callable table
|
|
188
188
|
// This catches 'const foo = function() {}; foo.bar = "FOOBAR";'
|
|
189
|
-
const wrappedValue = value &&
|
|
190
|
-
// Skip named function expressions because they will have been wrapped already
|
|
191
|
-
!(statement.initializer && ts.isFunctionExpression(statement.initializer) && statement.initializer.name) &&
|
|
192
|
-
(0, function_1.isFunctionTypeWithProperties)(context.checker.getTypeAtLocation(statement.name))
|
|
193
|
-
? (0, function_1.createCallableTable)(value)
|
|
194
|
-
: value;
|
|
189
|
+
const wrappedValue = value && shouldWrapInitializerInCallableTable() ? (0, function_1.createCallableTable)(value) : value;
|
|
195
190
|
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, identifierName, wrappedValue, statement);
|
|
196
191
|
}
|
|
197
192
|
else if (ts.isArrayBindingPattern(statement.name) || ts.isObjectBindingPattern(statement.name)) {
|
|
@@ -200,6 +195,17 @@ function transformVariableDeclaration(context, statement) {
|
|
|
200
195
|
else {
|
|
201
196
|
return (0, utils_1.assertNever)(statement.name);
|
|
202
197
|
}
|
|
198
|
+
function shouldWrapInitializerInCallableTable() {
|
|
199
|
+
(0, utils_1.assert)(statement.initializer);
|
|
200
|
+
const initializer = ts.skipOuterExpressions(statement.initializer);
|
|
201
|
+
// do not wrap if not a function expression
|
|
202
|
+
if (!ts.isFunctionExpression(initializer) && !ts.isArrowFunction(initializer))
|
|
203
|
+
return false;
|
|
204
|
+
// Skip named function expressions because they will have been wrapped already
|
|
205
|
+
if (ts.isFunctionExpression(initializer) && initializer.name)
|
|
206
|
+
return false;
|
|
207
|
+
return (0, function_1.isFunctionTypeWithProperties)(context.checker.getTypeAtLocation(statement.name));
|
|
208
|
+
}
|
|
203
209
|
}
|
|
204
210
|
exports.transformVariableDeclaration = transformVariableDeclaration;
|
|
205
211
|
function checkVariableDeclarationList(context, node) {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import
|
|
3
|
-
import { TransformationContext } from "../context";
|
|
4
|
-
import { FunctionVisitor } from "../context/visitors";
|
|
2
|
+
import { FunctionVisitor } from "../context";
|
|
5
3
|
export declare const transformVoidExpression: FunctionVisitor<ts.VoidExpression>;
|
|
6
|
-
export declare const transformVoidExpressionStatement: (node: ts.VoidExpression, context: TransformationContext) => lua.VariableDeclarationStatement;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.transformVoidExpression = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
|
+
const expression_statement_1 = require("./expression-statement");
|
|
6
7
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
|
|
7
8
|
const transformVoidExpression = (node, context) => {
|
|
8
9
|
// If content is a literal it is safe to replace the entire expression with nil
|
|
9
10
|
if (!ts.isLiteralExpression(node.expression)) {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const statements = (0, expression_statement_1.transformExpressionToStatement)(context, node.expression);
|
|
12
|
+
if (statements)
|
|
13
|
+
context.addPrecedingStatements(statements);
|
|
12
14
|
}
|
|
13
|
-
return lua.createNilLiteral(
|
|
15
|
+
return lua.createNilLiteral();
|
|
14
16
|
};
|
|
15
17
|
exports.transformVoidExpression = transformVoidExpression;
|
|
16
|
-
const transformVoidExpressionStatement = (node, context) =>
|
|
17
|
-
// In case of a void expression statement we can omit the IIFE
|
|
18
|
-
lua.createVariableDeclarationStatement(lua.createAnonymousIdentifier(), context.transformExpression(node.expression), node);
|
|
19
|
-
exports.transformVoidExpressionStatement = transformVoidExpressionStatement;
|
|
20
18
|
//# sourceMappingURL=void.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
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/",
|