typescript-to-lua 1.0.1 → 1.1.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/CHANGELOG.md +18 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +1 -0
- package/dist/LuaLib.js +1 -0
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/Await.lua +26 -10
- package/dist/lualib/Promise.lua +20 -6
- package/dist/lualib/SourceMapTraceBack.lua +18 -8
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/lualib_bundle.lua +106 -35
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +33 -33
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -3
- package/dist/transformation/utils/annotations.js +0 -2
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.js +4 -4
- package/dist/transformation/utils/export.js +4 -4
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +16 -16
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +21 -21
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +2 -2
- package/dist/transformation/visitors/call.js +35 -35
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +34 -34
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +12 -12
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -30
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +26 -26
- package/dist/transformation/visitors/identifier.js +22 -22
- package/dist/transformation/visitors/index.js +2 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -3
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -13
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +11 -11
- package/dist/transformation/visitors/switch.js +34 -11
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +28 -28
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +52 -10
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +19 -12
- package/dist/transpilation/transformers.js +41 -24
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformThrowStatement = exports.transformTryStatement = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
4
5
|
const lua = require("../../LuaAST");
|
|
6
|
+
const diagnostics_1 = require("../utils/diagnostics");
|
|
5
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
6
8
|
const scope_1 = require("../utils/scope");
|
|
9
|
+
const typescript_1 = require("../utils/typescript");
|
|
7
10
|
const block_1 = require("./block");
|
|
8
11
|
const identifier_1 = require("./identifier");
|
|
9
12
|
const multi_1 = require("./language-extensions/multi");
|
|
13
|
+
const return_1 = require("./return");
|
|
10
14
|
const transformTryStatement = (statement, context) => {
|
|
11
|
-
const [tryBlock, tryScope] = block_1.transformScopeBlock(context, statement.tryBlock, scope_1.ScopeType.Try);
|
|
15
|
+
const [tryBlock, tryScope] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
|
|
16
|
+
if (context.options.luaTarget === __1.LuaTarget.Lua51 && (0, typescript_1.isInAsyncFunction)(statement)) {
|
|
17
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "try/catch inside async functions", __1.LuaTarget.Lua51));
|
|
18
|
+
return tryBlock.statements;
|
|
19
|
+
}
|
|
20
|
+
if (context.options.luaTarget === __1.LuaTarget.Lua51 && (0, typescript_1.isInGeneratorFunction)(statement)) {
|
|
21
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "try/catch inside generator functions", __1.LuaTarget.Lua51));
|
|
22
|
+
return tryBlock.statements;
|
|
23
|
+
}
|
|
12
24
|
const tryResultIdentifier = lua.createIdentifier("____try");
|
|
13
25
|
const returnValueIdentifier = lua.createIdentifier("____returnValue");
|
|
14
26
|
const result = [];
|
|
15
|
-
|
|
27
|
+
const returnedIdentifier = lua.createIdentifier("____hasReturned");
|
|
16
28
|
let returnCondition;
|
|
17
29
|
const pCall = lua.createIdentifier("pcall");
|
|
18
30
|
const tryCall = lua.createCallExpression(pCall, [lua.createFunctionExpression(tryBlock)]);
|
|
19
31
|
if (statement.catchClause && statement.catchClause.block.statements.length > 0) {
|
|
20
32
|
// try with catch
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
const [catchBlock, catchScope] = (0, block_1.transformScopeBlock)(context, statement.catchClause.block, scope_1.ScopeType.Catch);
|
|
34
|
+
const catchParameter = statement.catchClause.variableDeclaration
|
|
35
|
+
? (0, identifier_1.transformIdentifier)(context, statement.catchClause.variableDeclaration.name)
|
|
36
|
+
: undefined;
|
|
37
|
+
const catchParameters = () => (catchParameter ? [lua.cloneIdentifier(catchParameter)] : []);
|
|
38
|
+
const catchIdentifier = lua.createIdentifier("____catch");
|
|
39
|
+
const catchFunction = lua.createFunctionExpression(catchBlock, catchParameters());
|
|
40
|
+
result.push(lua.createVariableDeclarationStatement(catchIdentifier, catchFunction));
|
|
29
41
|
const tryReturnIdentifiers = [tryResultIdentifier]; // ____try
|
|
30
42
|
if (returnedIdentifier) {
|
|
31
43
|
tryReturnIdentifiers.push(returnedIdentifier); // ____returned or catch variable
|
|
@@ -35,18 +47,15 @@ const transformTryStatement = (statement, context) => {
|
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
result.push(lua.createVariableDeclarationStatement(tryReturnIdentifiers, tryCall));
|
|
38
|
-
if
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const catchAssign = lua.createAssignmentStatement([lua.cloneIdentifier(returnedIdentifier), lua.cloneIdentifier(returnValueIdentifier)], catchCall);
|
|
42
|
-
catchBlock = lua.createBlock([catchAssign]);
|
|
43
|
-
}
|
|
50
|
+
// Wrap catch in function if try or catch has return
|
|
51
|
+
const catchCall = lua.createCallExpression(catchIdentifier, [lua.cloneIdentifier(returnedIdentifier)]);
|
|
52
|
+
const catchAssign = lua.createAssignmentStatement([lua.cloneIdentifier(returnedIdentifier), lua.cloneIdentifier(returnValueIdentifier)], catchCall);
|
|
44
53
|
const notTryCondition = lua.createUnaryExpression(tryResultIdentifier, lua.SyntaxKind.NotOperator);
|
|
45
|
-
result.push(lua.createIfStatement(notTryCondition,
|
|
54
|
+
result.push(lua.createIfStatement(notTryCondition, lua.createBlock([catchAssign])));
|
|
46
55
|
}
|
|
47
56
|
else if (tryScope.functionReturned) {
|
|
48
57
|
// try with return, but no catch
|
|
49
|
-
returnedIdentifier = lua.createIdentifier("____returned");
|
|
58
|
+
// returnedIdentifier = lua.createIdentifier("____returned");
|
|
50
59
|
const returnedVariables = [tryResultIdentifier, returnedIdentifier, returnValueIdentifier];
|
|
51
60
|
result.push(lua.createVariableDeclarationStatement(returnedVariables, tryCall));
|
|
52
61
|
// change return condition from '____returned' to '____try and ____returned'
|
|
@@ -60,23 +69,14 @@ const transformTryStatement = (statement, context) => {
|
|
|
60
69
|
result.push(...context.transformStatements(statement.finallyBlock));
|
|
61
70
|
}
|
|
62
71
|
if (returnCondition && returnedIdentifier) {
|
|
63
|
-
// With catch clause:
|
|
64
|
-
// if ____returned then return ____returnValue end
|
|
65
|
-
// No catch clause:
|
|
66
|
-
// if ____try and ____returned then return ____returnValue end
|
|
67
72
|
const returnValues = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Nested try/catch needs to prefix a 'true' return value
|
|
71
|
-
returnValues.push(lua.createBooleanLiteral(true));
|
|
72
|
-
}
|
|
73
|
-
if (multi_1.isInMultiReturnFunction(context, statement)) {
|
|
74
|
-
returnValues.push(lua_ast_1.createUnpackCall(context, lua.cloneIdentifier(returnValueIdentifier)));
|
|
73
|
+
if ((0, multi_1.isInMultiReturnFunction)(context, statement)) {
|
|
74
|
+
returnValues.push((0, lua_ast_1.createUnpackCall)(context, lua.cloneIdentifier(returnValueIdentifier)));
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
returnValues.push(lua.cloneIdentifier(returnValueIdentifier));
|
|
78
78
|
}
|
|
79
|
-
const returnStatement =
|
|
79
|
+
const returnStatement = (0, return_1.createReturnStatement)(context, returnValues, statement);
|
|
80
80
|
const ifReturnedStatement = lua.createIfStatement(returnCondition, lua.createBlock([returnStatement]));
|
|
81
81
|
result.push(ifReturnedStatement);
|
|
82
82
|
}
|
|
@@ -6,19 +6,23 @@ const lua = require("../../LuaAST");
|
|
|
6
6
|
const binary_expression_1 = require("./binary-expression");
|
|
7
7
|
const table_1 = require("./language-extensions/table");
|
|
8
8
|
const unary_expression_1 = require("./unary-expression");
|
|
9
|
+
const void_1 = require("./void");
|
|
9
10
|
const transformExpressionStatement = (node, context) => {
|
|
10
11
|
const expression = node.expression;
|
|
11
|
-
if (ts.isCallExpression(expression) && table_1.isTableDeleteCall(context, expression)) {
|
|
12
|
-
return table_1.transformTableDeleteExpression(context, expression);
|
|
12
|
+
if (ts.isCallExpression(expression) && (0, table_1.isTableDeleteCall)(context, expression)) {
|
|
13
|
+
return (0, table_1.transformTableDeleteExpression)(context, expression);
|
|
13
14
|
}
|
|
14
|
-
if (ts.isCallExpression(expression) && table_1.isTableSetCall(context, expression)) {
|
|
15
|
-
return table_1.transformTableSetExpression(context, expression);
|
|
15
|
+
if (ts.isCallExpression(expression) && (0, table_1.isTableSetCall)(context, expression)) {
|
|
16
|
+
return (0, table_1.transformTableSetExpression)(context, expression);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
if (ts.isVoidExpression(expression)) {
|
|
19
|
+
return (0, void_1.transformVoidExpressionStatement)(expression, context);
|
|
20
|
+
}
|
|
21
|
+
const unaryExpressionResult = (0, unary_expression_1.transformUnaryExpressionStatement)(context, node);
|
|
18
22
|
if (unaryExpressionResult) {
|
|
19
23
|
return unaryExpressionResult;
|
|
20
24
|
}
|
|
21
|
-
const binaryExpressionResult = binary_expression_1.transformBinaryExpressionStatement(context, node);
|
|
25
|
+
const binaryExpressionResult = (0, binary_expression_1.transformBinaryExpressionStatement)(context, node);
|
|
22
26
|
if (binaryExpressionResult) {
|
|
23
27
|
return binaryExpressionResult;
|
|
24
28
|
}
|
|
@@ -34,10 +34,10 @@ function isRestParameterReferenced(identifier, scope) {
|
|
|
34
34
|
}
|
|
35
35
|
function transformFunctionBodyContent(context, body) {
|
|
36
36
|
if (!ts.isBlock(body)) {
|
|
37
|
-
const returnStatement = return_1.transformExpressionBodyToReturnStatement(context, body);
|
|
37
|
+
const returnStatement = (0, return_1.transformExpressionBodyToReturnStatement)(context, body);
|
|
38
38
|
return [returnStatement];
|
|
39
39
|
}
|
|
40
|
-
const bodyStatements = scope_1.performHoisting(context, context.transformStatements(body.statements));
|
|
40
|
+
const bodyStatements = (0, scope_1.performHoisting)(context, context.transformStatements(body.statements));
|
|
41
41
|
return bodyStatements;
|
|
42
42
|
}
|
|
43
43
|
exports.transformFunctionBodyContent = transformFunctionBodyContent;
|
|
@@ -54,16 +54,16 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
54
54
|
headerStatements.push(transformParameterDefaultValueDeclaration(context, identifier, declaration.initializer));
|
|
55
55
|
}
|
|
56
56
|
// Binding pattern
|
|
57
|
-
bindingPatternDeclarations.push(...variable_declaration_1.transformBindingPattern(context, declaration.name, identifier));
|
|
57
|
+
bindingPatternDeclarations.push(...(0, variable_declaration_1.transformBindingPattern)(context, declaration.name, identifier));
|
|
58
58
|
}
|
|
59
59
|
else if (declaration.initializer !== undefined) {
|
|
60
60
|
// Default parameter
|
|
61
|
-
headerStatements.push(transformParameterDefaultValueDeclaration(context, identifier_1.transformIdentifier(context, declaration.name), declaration.initializer));
|
|
61
|
+
headerStatements.push(transformParameterDefaultValueDeclaration(context, (0, identifier_1.transformIdentifier)(context, declaration.name), declaration.initializer));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
// Push spread operator here
|
|
65
65
|
if (spreadIdentifier && isRestParameterReferenced(spreadIdentifier, bodyScope)) {
|
|
66
|
-
const spreadTable = lua_ast_1.wrapInTable(lua.createDotsLiteral());
|
|
66
|
+
const spreadTable = (0, lua_ast_1.wrapInTable)(lua.createDotsLiteral());
|
|
67
67
|
headerStatements.push(lua.createVariableDeclarationStatement(spreadIdentifier, spreadTable));
|
|
68
68
|
}
|
|
69
69
|
// Binding pattern statements need to be after spread table is declared
|
|
@@ -72,14 +72,14 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
72
72
|
}
|
|
73
73
|
exports.transformFunctionBodyHeader = transformFunctionBodyHeader;
|
|
74
74
|
function transformFunctionBody(context, parameters, body, spreadIdentifier, node) {
|
|
75
|
-
const scope = scope_1.pushScope(context, scope_1.ScopeType.Function);
|
|
75
|
+
const scope = (0, scope_1.pushScope)(context, scope_1.ScopeType.Function);
|
|
76
76
|
scope.node = node;
|
|
77
77
|
let bodyStatements = transformFunctionBodyContent(context, body);
|
|
78
|
-
if (node && async_await_1.isAsyncFunction(node)) {
|
|
79
|
-
bodyStatements = async_await_1.wrapInAsyncAwaiter(context, bodyStatements);
|
|
78
|
+
if (node && (0, async_await_1.isAsyncFunction)(node)) {
|
|
79
|
+
bodyStatements = (0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements);
|
|
80
80
|
}
|
|
81
81
|
const headerStatements = transformFunctionBodyHeader(context, scope, parameters, spreadIdentifier);
|
|
82
|
-
scope_1.popScope(context);
|
|
82
|
+
(0, scope_1.popScope)(context);
|
|
83
83
|
return [[...headerStatements, ...bodyStatements], scope];
|
|
84
84
|
}
|
|
85
85
|
exports.transformFunctionBody = transformFunctionBody;
|
|
@@ -101,7 +101,7 @@ function transformParameters(context, parameters, functionContext) {
|
|
|
101
101
|
// See transformFunctionBody for how these values are destructured
|
|
102
102
|
const paramName = ts.isObjectBindingPattern(param.name) || ts.isArrayBindingPattern(param.name)
|
|
103
103
|
? lua.createIdentifier(`____bindingPattern${identifierIndex++}`)
|
|
104
|
-
: identifier_1.transformIdentifier(context, param.name);
|
|
104
|
+
: (0, identifier_1.transformIdentifier)(context, param.name);
|
|
105
105
|
// This parameter is a spread parameter (...param)
|
|
106
106
|
if (!param.dotDotDotToken) {
|
|
107
107
|
paramNames.push(paramName);
|
|
@@ -116,10 +116,10 @@ function transformParameters(context, parameters, functionContext) {
|
|
|
116
116
|
}
|
|
117
117
|
exports.transformParameters = transformParameters;
|
|
118
118
|
function transformFunctionToExpression(context, node) {
|
|
119
|
-
utils_1.assert(node.body);
|
|
119
|
+
(0, utils_1.assert)(node.body);
|
|
120
120
|
const type = context.checker.getTypeAtLocation(node);
|
|
121
121
|
let functionContext;
|
|
122
|
-
if (function_context_1.getFunctionContextType(context, type) !== function_context_1.ContextType.Void) {
|
|
122
|
+
if ((0, function_context_1.getFunctionContextType)(context, type) !== function_context_1.ContextType.Void) {
|
|
123
123
|
if (ts.isArrowFunction(node)) {
|
|
124
124
|
// dummy context for arrow functions with parameters
|
|
125
125
|
if (node.parameters.length > 0) {
|
|
@@ -128,7 +128,7 @@ function transformFunctionToExpression(context, node) {
|
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
// self context
|
|
131
|
-
functionContext = lua_ast_1.createSelfIdentifier();
|
|
131
|
+
functionContext = (0, lua_ast_1.createSelfIdentifier)();
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
let flags = lua.FunctionExpressionFlags.None;
|
|
@@ -142,7 +142,7 @@ function transformFunctionToExpression(context, node) {
|
|
|
142
142
|
const functionExpression = lua.createFunctionExpression(lua.createBlock(transformedBody), paramNames, dotsLiteral, flags, node);
|
|
143
143
|
return [
|
|
144
144
|
node.asteriskToken
|
|
145
|
-
? lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.Generator, undefined, functionExpression)
|
|
145
|
+
? (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Generator, undefined, functionExpression)
|
|
146
146
|
: functionExpression,
|
|
147
147
|
functionScope,
|
|
148
148
|
];
|
|
@@ -153,8 +153,8 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
153
153
|
// This code can be reached only from object methods, which is TypeScript error
|
|
154
154
|
return lua.createNilLiteral();
|
|
155
155
|
}
|
|
156
|
-
if (annotations_1.getNodeAnnotations(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
157
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.TupleReturn));
|
|
156
|
+
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
157
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
158
158
|
}
|
|
159
159
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
160
160
|
// Handle named function expressions which reference themselves
|
|
@@ -165,12 +165,12 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
165
165
|
const isReferenced = [...functionScope.referencedSymbols].some(([, nodes]) => nodes.some(n => { var _a; return ((_a = context.checker.getSymbolAtLocation(n)) === null || _a === void 0 ? void 0 : _a.valueDeclaration) === symbol.valueDeclaration; }));
|
|
166
166
|
// Only wrap if the name is actually referenced inside the function
|
|
167
167
|
if (isReferenced) {
|
|
168
|
-
const nameIdentifier = identifier_1.transformIdentifier(context, node.name);
|
|
168
|
+
const nameIdentifier = (0, identifier_1.transformIdentifier)(context, node.name);
|
|
169
169
|
// We cannot use transformToImmediatelyInvokedFunctionExpression() here because we need to transpile
|
|
170
170
|
// the function first to determine if it's self-referencing. Fortunately, this does not cause issues
|
|
171
171
|
// with var-arg optimization because the IIFE is just wrapping another function which will already push
|
|
172
172
|
// another scope.
|
|
173
|
-
return lua_ast_1.createImmediatelyInvokedFunctionExpression([lua.createVariableDeclarationStatement(nameIdentifier, functionExpression)], lua.cloneIdentifier(nameIdentifier));
|
|
173
|
+
return (0, lua_ast_1.createImmediatelyInvokedFunctionExpression)([lua.createVariableDeclarationStatement(nameIdentifier, functionExpression)], lua.cloneIdentifier(nameIdentifier));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -179,35 +179,35 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
179
179
|
exports.transformFunctionLikeDeclaration = transformFunctionLikeDeclaration;
|
|
180
180
|
const transformFunctionDeclaration = (node, context) => {
|
|
181
181
|
var _a;
|
|
182
|
-
if (annotations_1.getNodeAnnotations(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
183
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.TupleReturn));
|
|
182
|
+
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
183
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
184
184
|
}
|
|
185
185
|
// Don't transform functions without body (overload declarations)
|
|
186
186
|
if (node.body === undefined) {
|
|
187
187
|
return undefined;
|
|
188
188
|
}
|
|
189
|
-
if (export_1.hasDefaultExportModifier(node)) {
|
|
190
|
-
return lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createExportsIdentifier(), export_1.createDefaultExportStringLiteral(node)), transformFunctionLikeDeclaration(node, context));
|
|
189
|
+
if ((0, export_1.hasDefaultExportModifier)(node)) {
|
|
190
|
+
return lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, export_1.createDefaultExportStringLiteral)(node)), transformFunctionLikeDeclaration(node, context));
|
|
191
191
|
}
|
|
192
192
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
193
193
|
// Name being undefined without default export is a TypeScript error
|
|
194
|
-
const name = node.name ? identifier_1.transformIdentifier(context, node.name) : lua.createAnonymousIdentifier();
|
|
194
|
+
const name = node.name ? (0, identifier_1.transformIdentifier)(context, node.name) : lua.createAnonymousIdentifier();
|
|
195
195
|
// Remember symbols referenced in this function for hoisting later
|
|
196
196
|
if (name.symbolId !== undefined) {
|
|
197
|
-
const scope = scope_1.peekScope(context);
|
|
197
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
198
198
|
if (!scope.functionDefinitions) {
|
|
199
199
|
scope.functionDefinitions = new Map();
|
|
200
200
|
}
|
|
201
201
|
const functionInfo = { referencedSymbols: (_a = functionScope.referencedSymbols) !== null && _a !== void 0 ? _a : new Map() };
|
|
202
202
|
scope.functionDefinitions.set(name.symbolId, functionInfo);
|
|
203
203
|
}
|
|
204
|
-
return lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, name, functionExpression, node);
|
|
204
|
+
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, name, functionExpression, node);
|
|
205
205
|
};
|
|
206
206
|
exports.transformFunctionDeclaration = transformFunctionDeclaration;
|
|
207
207
|
const transformYieldExpression = (expression, context) => {
|
|
208
208
|
const parameters = expression.expression ? [context.transformExpression(expression.expression)] : [];
|
|
209
209
|
return expression.asteriskToken
|
|
210
|
-
? lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.DelegatedYield, expression, ...parameters)
|
|
210
|
+
? (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DelegatedYield, expression, ...parameters)
|
|
211
211
|
: lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("coroutine"), lua.createStringLiteral("yield")), parameters, expression);
|
|
212
212
|
};
|
|
213
213
|
exports.transformYieldExpression = transformYieldExpression;
|
|
@@ -17,52 +17,52 @@ const range_1 = require("./language-extensions/range");
|
|
|
17
17
|
const table_1 = require("./language-extensions/table");
|
|
18
18
|
const vararg_1 = require("./language-extensions/vararg");
|
|
19
19
|
function transformIdentifier(context, identifier) {
|
|
20
|
-
if (multi_1.isMultiFunctionNode(context, identifier)) {
|
|
21
|
-
context.diagnostics.push(diagnostics_1.invalidMultiFunctionUse(identifier));
|
|
20
|
+
if ((0, multi_1.isMultiFunctionNode)(context, identifier)) {
|
|
21
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(identifier));
|
|
22
22
|
return lua.createAnonymousIdentifier(identifier);
|
|
23
23
|
}
|
|
24
|
-
if (operators_1.isOperatorMapping(context, identifier)) {
|
|
25
|
-
context.diagnostics.push(diagnostics_1.invalidOperatorMappingUse(identifier));
|
|
24
|
+
if ((0, operators_1.isOperatorMapping)(context, identifier)) {
|
|
25
|
+
context.diagnostics.push((0, diagnostics_1.invalidOperatorMappingUse)(identifier));
|
|
26
26
|
}
|
|
27
|
-
if (table_1.isTableExtensionIdentifier(context, identifier)) {
|
|
28
|
-
context.diagnostics.push(diagnostics_1.invalidTableExtensionUse(identifier));
|
|
27
|
+
if ((0, table_1.isTableExtensionIdentifier)(context, identifier)) {
|
|
28
|
+
context.diagnostics.push((0, diagnostics_1.invalidTableExtensionUse)(identifier));
|
|
29
29
|
}
|
|
30
|
-
if (range_1.isRangeFunctionNode(context, identifier)) {
|
|
31
|
-
context.diagnostics.push(diagnostics_1.invalidRangeUse(identifier));
|
|
30
|
+
if ((0, range_1.isRangeFunctionNode)(context, identifier)) {
|
|
31
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeUse)(identifier));
|
|
32
32
|
return lua.createAnonymousIdentifier(identifier);
|
|
33
33
|
}
|
|
34
|
-
if (vararg_1.isVarargConstantNode(context, identifier)) {
|
|
35
|
-
context.diagnostics.push(diagnostics_1.invalidVarargUse(identifier));
|
|
34
|
+
if ((0, vararg_1.isVarargConstantNode)(context, identifier)) {
|
|
35
|
+
context.diagnostics.push((0, diagnostics_1.invalidVarargUse)(identifier));
|
|
36
36
|
return lua.createAnonymousIdentifier(identifier);
|
|
37
37
|
}
|
|
38
|
-
if (annotations_1.isForRangeType(context, identifier)) {
|
|
39
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(identifier, annotations_1.AnnotationKind.ForRange));
|
|
38
|
+
if ((0, annotations_1.isForRangeType)(context, identifier)) {
|
|
39
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(identifier, annotations_1.AnnotationKind.ForRange));
|
|
40
40
|
}
|
|
41
|
-
if (promise_1.isPromiseClass(context, identifier)) {
|
|
42
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Promise);
|
|
43
|
-
return promise_1.createPromiseIdentifier(identifier);
|
|
41
|
+
if ((0, promise_1.isPromiseClass)(context, identifier)) {
|
|
42
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
43
|
+
return (0, promise_1.createPromiseIdentifier)(identifier);
|
|
44
44
|
}
|
|
45
|
-
const text = safe_names_1.hasUnsafeIdentifierName(context, identifier) ? safe_names_1.createSafeName(identifier.text) : identifier.text;
|
|
46
|
-
const symbolId = symbols_1.getIdentifierSymbolId(context, identifier);
|
|
45
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier) ? (0, safe_names_1.createSafeName)(identifier.text) : identifier.text;
|
|
46
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, identifier);
|
|
47
47
|
return lua.createIdentifier(text, identifier, symbolId, identifier.text);
|
|
48
48
|
}
|
|
49
49
|
exports.transformIdentifier = transformIdentifier;
|
|
50
50
|
const transformIdentifierExpression = (node, context) => {
|
|
51
51
|
const symbol = context.checker.getSymbolAtLocation(node);
|
|
52
52
|
if (symbol) {
|
|
53
|
-
const exportScope = export_1.getSymbolExportScope(context, symbol);
|
|
53
|
+
const exportScope = (0, export_1.getSymbolExportScope)(context, symbol);
|
|
54
54
|
if (exportScope) {
|
|
55
55
|
const name = symbol.name;
|
|
56
|
-
const text = safe_names_1.hasUnsafeIdentifierName(context, node) ? safe_names_1.createSafeName(name) : name;
|
|
57
|
-
const symbolId = symbols_1.getIdentifierSymbolId(context, node);
|
|
56
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, node) ? (0, safe_names_1.createSafeName)(name) : name;
|
|
57
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, node);
|
|
58
58
|
const identifier = lua.createIdentifier(text, node, symbolId, name);
|
|
59
|
-
return export_1.createExportedIdentifier(context, identifier, exportScope);
|
|
59
|
+
return (0, export_1.createExportedIdentifier)(context, identifier, exportScope);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
|
|
63
63
|
return lua.createNilLiteral();
|
|
64
64
|
}
|
|
65
|
-
const builtinResult = builtins_1.transformBuiltinIdentifierExpression(context, node);
|
|
65
|
+
const builtinResult = (0, builtins_1.transformBuiltinIdentifierExpression)(context, node);
|
|
66
66
|
if (builtinResult) {
|
|
67
67
|
return builtinResult;
|
|
68
68
|
}
|
|
@@ -33,14 +33,13 @@ const typeof_1 = require("./typeof");
|
|
|
33
33
|
const typescript_1 = require("./typescript");
|
|
34
34
|
const unary_expression_1 = require("./unary-expression");
|
|
35
35
|
const variable_declaration_1 = require("./variable-declaration");
|
|
36
|
-
const jsx_1 = require("./jsx/jsx");
|
|
37
36
|
const async_await_1 = require("./async-await");
|
|
37
|
+
const void_1 = require("./void");
|
|
38
38
|
const transformEmptyStatement = () => undefined;
|
|
39
39
|
const transformParenthesizedExpression = (node, context) => context.transformExpression(node.expression);
|
|
40
40
|
exports.standardVisitors = {
|
|
41
41
|
...literal_1.literalVisitors,
|
|
42
42
|
...typescript_1.typescriptVisitors,
|
|
43
|
-
...jsx_1.jsxVisitors,
|
|
44
43
|
[ts.SyntaxKind.ArrowFunction]: function_1.transformFunctionLikeDeclaration,
|
|
45
44
|
[ts.SyntaxKind.AwaitExpression]: async_await_1.transformAwaitExpression,
|
|
46
45
|
[ts.SyntaxKind.BinaryExpression]: binary_expression_1.transformBinaryExpression,
|
|
@@ -90,5 +89,6 @@ exports.standardVisitors = {
|
|
|
90
89
|
[ts.SyntaxKind.VariableStatement]: variable_declaration_1.transformVariableStatement,
|
|
91
90
|
[ts.SyntaxKind.WhileStatement]: do_while_1.transformWhileStatement,
|
|
92
91
|
[ts.SyntaxKind.YieldExpression]: function_1.transformYieldExpression,
|
|
92
|
+
[ts.SyntaxKind.VoidExpression]: void_1.transformVoidExpression,
|
|
93
93
|
};
|
|
94
94
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,12 +30,12 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
30
30
|
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
31
31
|
// Variables declared in for loop
|
|
32
32
|
// for ${initializer} in ${iterable} do
|
|
33
|
-
const binding = utils_1.getVariableDeclarationBinding(context, statement.initializer);
|
|
33
|
+
const binding = (0, utils_1.getVariableDeclarationBinding)(context, statement.initializer);
|
|
34
34
|
if (ts.isArrayBindingPattern(binding)) {
|
|
35
|
-
identifiers = binding.elements.map(e => variable_declaration_1.transformArrayBindingElement(context, e));
|
|
35
|
+
identifiers = binding.elements.map(e => (0, variable_declaration_1.transformArrayBindingElement)(context, e));
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
context.diagnostics.push(diagnostics_1.invalidMultiIterableWithoutDestructuring(binding));
|
|
38
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiIterableWithoutDestructuring)(binding));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
else if (ts.isArrayLiteralExpression(statement.initializer)) {
|
|
@@ -44,11 +44,11 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
44
44
|
// ${initializer} = ____value0
|
|
45
45
|
identifiers = statement.initializer.elements.map((_, i) => lua.createIdentifier(`____value${i}`));
|
|
46
46
|
if (identifiers.length > 0) {
|
|
47
|
-
block.statements.unshift(lua.createAssignmentStatement(statement.initializer.elements.map(e => utils_2.cast(context.transformExpression(e), lua.isAssignmentLeftHandSideExpression)), identifiers));
|
|
47
|
+
block.statements.unshift(lua.createAssignmentStatement(statement.initializer.elements.map(e => (0, utils_2.cast)(context.transformExpression(e), lua.isAssignmentLeftHandSideExpression)), identifiers));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
context.diagnostics.push(diagnostics_1.invalidMultiIterableWithoutDestructuring(statement.initializer));
|
|
51
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiIterableWithoutDestructuring)(statement.initializer));
|
|
52
52
|
}
|
|
53
53
|
if (identifiers.length === 0) {
|
|
54
54
|
identifiers.push(lua.createAnonymousIdentifier());
|
|
@@ -58,11 +58,11 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
58
58
|
function transformForOfIterableStatement(context, statement, block) {
|
|
59
59
|
var _a;
|
|
60
60
|
const type = context.checker.getTypeAtLocation(statement.expression);
|
|
61
|
-
if (((_a = type.aliasTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 2 && multi_1.isMultiReturnType(type.aliasTypeArguments[0])) {
|
|
61
|
+
if (((_a = type.aliasTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 2 && (0, multi_1.isMultiReturnType)(type.aliasTypeArguments[0])) {
|
|
62
62
|
return transformForOfMultiIterableStatement(context, statement, block);
|
|
63
63
|
}
|
|
64
64
|
const luaIterator = context.transformExpression(statement.expression);
|
|
65
|
-
const identifier = utils_1.transformForInitializer(context, statement.initializer, block);
|
|
65
|
+
const identifier = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
66
66
|
return lua.createForInStatement(block, [identifier], [luaIterator], statement);
|
|
67
67
|
}
|
|
68
68
|
exports.transformForOfIterableStatement = transformForOfIterableStatement;
|
|
@@ -8,4 +8,4 @@ export declare function isMultiReturnCall(context: TransformationContext, expres
|
|
|
8
8
|
export declare function isMultiFunctionNode(context: TransformationContext, node: ts.Node): boolean;
|
|
9
9
|
export declare function isInMultiReturnFunction(context: TransformationContext, node: ts.Node): boolean;
|
|
10
10
|
export declare function shouldMultiReturnCallBeWrapped(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
11
|
-
export declare function findMultiAssignmentViolations(context: TransformationContext, node: ts.
|
|
11
|
+
export declare function findMultiAssignmentViolations(context: TransformationContext, node: ts.ObjectLiteralExpression): ts.Node[];
|
|
@@ -34,7 +34,7 @@ function isMultiFunctionNode(context, node) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.isMultiFunctionNode = isMultiFunctionNode;
|
|
36
36
|
function isInMultiReturnFunction(context, node) {
|
|
37
|
-
const declaration = typescript_1.findFirstNodeAbove(node, ts.isFunctionLike);
|
|
37
|
+
const declaration = (0, typescript_1.findFirstNodeAbove)(node, ts.isFunctionLike);
|
|
38
38
|
if (!declaration) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
@@ -75,7 +75,7 @@ function shouldMultiReturnCallBeWrapped(context, node) {
|
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
// LuaIterable in for...of
|
|
78
|
-
if (ts.isForOfStatement(node.parent) && iterable_1.isIterableExpression(context, node)) {
|
|
78
|
+
if (ts.isForOfStatement(node.parent) && (0, iterable_1.isIterableExpression)(context, node)) {
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
return true;
|
|
@@ -89,7 +89,7 @@ function findMultiAssignmentViolations(context, node) {
|
|
|
89
89
|
const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(element);
|
|
90
90
|
if (valueSymbol) {
|
|
91
91
|
if (extensions.isExtensionValue(context, valueSymbol, extensions.ExtensionKind.MultiFunction)) {
|
|
92
|
-
context.diagnostics.push(diagnostics_1.invalidMultiFunctionUse(element));
|
|
92
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(element));
|
|
93
93
|
result.push(element);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -64,7 +64,7 @@ const bitwiseOperatorMapExtensions = new Set([
|
|
|
64
64
|
extensions.ExtensionKind.BitwiseNotOperatorMethodType,
|
|
65
65
|
]);
|
|
66
66
|
function getOperatorMapExtensionKindForCall(context, node) {
|
|
67
|
-
const type = typescript_1.getFunctionTypeForCall(context, node);
|
|
67
|
+
const type = (0, typescript_1.getFunctionTypeForCall)(context, node);
|
|
68
68
|
return type && operatorMapExtensions.find(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
69
69
|
}
|
|
70
70
|
function isOperatorMapping(context, node) {
|
|
@@ -79,7 +79,7 @@ function isOperatorMapping(context, node) {
|
|
|
79
79
|
exports.isOperatorMapping = isOperatorMapping;
|
|
80
80
|
function transformOperatorMappingExpression(context, node) {
|
|
81
81
|
const extensionKind = getOperatorMapExtensionKindForCall(context, node);
|
|
82
|
-
utils_1.assert(extensionKind);
|
|
82
|
+
(0, utils_1.assert)(extensionKind);
|
|
83
83
|
const isBefore53 = context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
84
84
|
context.luaTarget === CompilerOptions_1.LuaTarget.Lua52 ||
|
|
85
85
|
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT ||
|
|
@@ -87,11 +87,11 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
87
87
|
if (isBefore53) {
|
|
88
88
|
const luaTarget = context.luaTarget === CompilerOptions_1.LuaTarget.Universal ? CompilerOptions_1.LuaTarget.Lua51 : context.luaTarget;
|
|
89
89
|
if (bitwiseOperatorMapExtensions.has(extensionKind)) {
|
|
90
|
-
context.diagnostics.push(diagnostics_1.unsupportedForTarget(node, "Native bitwise operations", luaTarget));
|
|
90
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Native bitwise operations", luaTarget));
|
|
91
91
|
}
|
|
92
92
|
else if (extensionKind === extensions.ExtensionKind.FloorDivisionOperatorType ||
|
|
93
93
|
extensionKind === extensions.ExtensionKind.FloorDivisionOperatorMethodType) {
|
|
94
|
-
context.diagnostics.push(diagnostics_1.unsupportedForTarget(node, "Floor division operator", luaTarget));
|
|
94
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Floor division operator", luaTarget));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
const args = node.arguments.slice();
|
|
@@ -101,7 +101,7 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
101
101
|
args.unshift(node.expression.expression);
|
|
102
102
|
}
|
|
103
103
|
const luaOperator = binaryOperatorMappings.get(extensionKind);
|
|
104
|
-
utils_1.assert(luaOperator);
|
|
104
|
+
(0, utils_1.assert)(luaOperator);
|
|
105
105
|
return lua.createBinaryExpression(context.transformExpression(args[0]), context.transformExpression(args[1]), luaOperator);
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
@@ -114,7 +114,7 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
114
114
|
arg = args[0];
|
|
115
115
|
}
|
|
116
116
|
const luaOperator = unaryOperatorMappings.get(extensionKind);
|
|
117
|
-
utils_1.assert(luaOperator);
|
|
117
|
+
(0, utils_1.assert)(luaOperator);
|
|
118
118
|
return lua.createUnaryExpression(context.transformExpression(arg), luaOperator);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -20,21 +20,21 @@ function isRangeFunctionNode(context, node) {
|
|
|
20
20
|
exports.isRangeFunctionNode = isRangeFunctionNode;
|
|
21
21
|
function getControlVariable(context, statement) {
|
|
22
22
|
if (!ts.isVariableDeclarationList(statement.initializer)) {
|
|
23
|
-
context.diagnostics.push(diagnostics_1.invalidRangeControlVariable(statement.initializer));
|
|
23
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeControlVariable)(statement.initializer));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const binding = utils_1.getVariableDeclarationBinding(context, statement.initializer);
|
|
26
|
+
const binding = (0, utils_1.getVariableDeclarationBinding)(context, statement.initializer);
|
|
27
27
|
if (!ts.isIdentifier(binding)) {
|
|
28
|
-
context.diagnostics.push(diagnostics_1.invalidRangeControlVariable(statement.initializer));
|
|
28
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeControlVariable)(statement.initializer));
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
return identifier_1.transformIdentifier(context, binding);
|
|
31
|
+
return (0, identifier_1.transformIdentifier)(context, binding);
|
|
32
32
|
}
|
|
33
33
|
function transformRangeStatement(context, statement, block) {
|
|
34
34
|
var _a;
|
|
35
|
-
utils_2.assert(ts.isCallExpression(statement.expression));
|
|
35
|
+
(0, utils_2.assert)(ts.isCallExpression(statement.expression));
|
|
36
36
|
const controlVariable = (_a = getControlVariable(context, statement)) !== null && _a !== void 0 ? _a : lua.createAnonymousIdentifier(statement.initializer);
|
|
37
|
-
const [start = lua.createNumericLiteral(0), limit = lua.createNumericLiteral(0), step] = call_1.transformArguments(context, statement.expression.arguments, context.checker.getResolvedSignature(statement.expression));
|
|
37
|
+
const [start = lua.createNumericLiteral(0), limit = lua.createNumericLiteral(0), step] = (0, call_1.transformArguments)(context, statement.expression.arguments, context.checker.getResolvedSignature(statement.expression));
|
|
38
38
|
return lua.createForStatement(block, controlVariable, start, limit, step, statement);
|
|
39
39
|
}
|
|
40
40
|
exports.transformRangeStatement = transformRangeStatement;
|
|
@@ -21,7 +21,7 @@ const tableExtensions = [
|
|
|
21
21
|
...tableSetExtensions,
|
|
22
22
|
];
|
|
23
23
|
function getTableExtensionKindForCall(context, node, validExtensions) {
|
|
24
|
-
const type = typescript_1.getFunctionTypeForCall(context, node);
|
|
24
|
+
const type = (0, typescript_1.getFunctionTypeForCall)(context, node);
|
|
25
25
|
return type && validExtensions.find(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
26
26
|
}
|
|
27
27
|
function isTableExtensionIdentifier(context, node) {
|
|
@@ -52,7 +52,7 @@ function isTableNewCall(context, node) {
|
|
|
52
52
|
exports.isTableNewCall = isTableNewCall;
|
|
53
53
|
function transformTableDeleteExpression(context, node) {
|
|
54
54
|
const extensionKind = getTableExtensionKindForCall(context, node, tableDeleteExtensions);
|
|
55
|
-
utils_1.assert(extensionKind);
|
|
55
|
+
(0, utils_1.assert)(extensionKind);
|
|
56
56
|
const args = node.arguments.slice();
|
|
57
57
|
if (args.length === 1 &&
|
|
58
58
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -65,7 +65,7 @@ function transformTableDeleteExpression(context, node) {
|
|
|
65
65
|
exports.transformTableDeleteExpression = transformTableDeleteExpression;
|
|
66
66
|
function transformTableGetExpression(context, node) {
|
|
67
67
|
const extensionKind = getTableExtensionKindForCall(context, node, tableGetExtensions);
|
|
68
|
-
utils_1.assert(extensionKind);
|
|
68
|
+
(0, utils_1.assert)(extensionKind);
|
|
69
69
|
const args = node.arguments.slice();
|
|
70
70
|
if (args.length === 1 &&
|
|
71
71
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -78,7 +78,7 @@ function transformTableGetExpression(context, node) {
|
|
|
78
78
|
exports.transformTableGetExpression = transformTableGetExpression;
|
|
79
79
|
function transformTableHasExpression(context, node) {
|
|
80
80
|
const extensionKind = getTableExtensionKindForCall(context, node, tableHasExtensions);
|
|
81
|
-
utils_1.assert(extensionKind);
|
|
81
|
+
(0, utils_1.assert)(extensionKind);
|
|
82
82
|
const args = node.arguments.slice();
|
|
83
83
|
if (args.length === 1 &&
|
|
84
84
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -93,7 +93,7 @@ function transformTableHasExpression(context, node) {
|
|
|
93
93
|
exports.transformTableHasExpression = transformTableHasExpression;
|
|
94
94
|
function transformTableSetExpression(context, node) {
|
|
95
95
|
const extensionKind = getTableExtensionKindForCall(context, node, tableSetExtensions);
|
|
96
|
-
utils_1.assert(extensionKind);
|
|
96
|
+
(0, utils_1.assert)(extensionKind);
|
|
97
97
|
const args = node.arguments.slice();
|
|
98
98
|
if (args.length === 2 &&
|
|
99
99
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
|
-
import {
|
|
3
|
+
import { TransformationContext, Visitors } from "../context";
|
|
4
4
|
export declare function transformPropertyName(context: TransformationContext, node: ts.PropertyName): lua.Expression;
|
|
5
5
|
export declare function createShorthandIdentifier(context: TransformationContext, valueSymbol: ts.Symbol | undefined, propertyIdentifier: ts.Identifier): lua.Expression;
|
|
6
|
-
export declare const transformJsxAttributes: FunctionVisitor<ts.JsxAttributes>;
|
|
7
6
|
export declare const literalVisitors: Visitors;
|