typescript-to-lua 1.33.0 → 1.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transformation/context/context.d.ts +1 -1
- package/dist/transformation/context/context.js +2 -2
- package/dist/transformation/utils/scope.d.ts +1 -4
- package/dist/transformation/utils/scope.js +1 -5
- package/dist/transformation/visitors/block.js +2 -2
- package/dist/transformation/visitors/class/members/accessors.js +1 -1
- package/dist/transformation/visitors/class/members/constructor.js +1 -1
- package/dist/transformation/visitors/conditional.js +2 -2
- package/dist/transformation/visitors/function.d.ts +1 -1
- package/dist/transformation/visitors/function.js +3 -4
- package/dist/transformation/visitors/loops/for.js +1 -1
- package/dist/transformation/visitors/loops/utils.js +2 -2
- package/dist/transformation/visitors/namespace.js +1 -1
- package/dist/transformation/visitors/sourceFile.js +1 -1
- package/dist/transformation/visitors/spread.js +1 -1
- package/dist/transformation/visitors/switch.js +1 -1
- package/package.json +1 -1
|
@@ -59,6 +59,6 @@ export declare class TransformationContext {
|
|
|
59
59
|
readonly usedLuaLibFeatures: Set<LuaLibFeature>;
|
|
60
60
|
readonly scopeStack: Scope[];
|
|
61
61
|
private lastScopeId;
|
|
62
|
-
pushScope(type: ScopeType): Scope;
|
|
62
|
+
pushScope(type: ScopeType, node: ts.Node): Scope;
|
|
63
63
|
popScope(): Scope;
|
|
64
64
|
}
|
|
@@ -206,8 +206,8 @@ class TransformationContext {
|
|
|
206
206
|
nextSymbolId() {
|
|
207
207
|
return ++this.lastSymbolId;
|
|
208
208
|
}
|
|
209
|
-
pushScope(type) {
|
|
210
|
-
const scope = { type, id: ++this.lastScopeId };
|
|
209
|
+
pushScope(type, node) {
|
|
210
|
+
const scope = { type, id: ++this.lastScopeId, node };
|
|
211
211
|
this.scopeStack.push(scope);
|
|
212
212
|
return scope;
|
|
213
213
|
}
|
|
@@ -24,7 +24,7 @@ export declare enum LoopContinued {
|
|
|
24
24
|
export interface Scope {
|
|
25
25
|
type: ScopeType;
|
|
26
26
|
id: number;
|
|
27
|
-
node
|
|
27
|
+
node: ts.Node;
|
|
28
28
|
referencedSymbols?: Map<lua.SymbolId, ts.Node[]>;
|
|
29
29
|
variableDeclarations?: lua.VariableDeclarationStatement[];
|
|
30
30
|
functionDefinitions?: Map<lua.SymbolId, FunctionDefinitionInfo>;
|
|
@@ -44,9 +44,6 @@ export declare function findScope(context: TransformationContext, scopeTypes: Sc
|
|
|
44
44
|
export declare function addScopeVariableDeclaration(scope: Scope, declaration: lua.VariableDeclarationStatement): void;
|
|
45
45
|
export declare function hasReferencedUndefinedLocalFunction(context: TransformationContext, scope: Scope): boolean;
|
|
46
46
|
export declare function hasReferencedSymbol(context: TransformationContext, scope: Scope, symbol: ts.Symbol): boolean | undefined;
|
|
47
|
-
export declare function isFunctionScopeWithDefinition(scope: Scope): scope is Scope & {
|
|
48
|
-
node: ts.SignatureDeclaration;
|
|
49
|
-
};
|
|
50
47
|
export declare function separateHoistedStatements(context: TransformationContext, statements: lua.Statement[]): HoistingResult;
|
|
51
48
|
export declare function performHoisting(context: TransformationContext, statements: lua.Statement[]): lua.Statement[];
|
|
52
49
|
export {};
|
|
@@ -8,7 +8,6 @@ exports.findScope = findScope;
|
|
|
8
8
|
exports.addScopeVariableDeclaration = addScopeVariableDeclaration;
|
|
9
9
|
exports.hasReferencedUndefinedLocalFunction = hasReferencedUndefinedLocalFunction;
|
|
10
10
|
exports.hasReferencedSymbol = hasReferencedSymbol;
|
|
11
|
-
exports.isFunctionScopeWithDefinition = isFunctionScopeWithDefinition;
|
|
12
11
|
exports.separateHoistedStatements = separateHoistedStatements;
|
|
13
12
|
exports.performHoisting = performHoisting;
|
|
14
13
|
const ts = require("typescript");
|
|
@@ -76,7 +75,7 @@ function isHoistableFunctionDeclaredInScope(symbol, scopeNode) {
|
|
|
76
75
|
// and thus will be hoisted above the current position.
|
|
77
76
|
function hasReferencedUndefinedLocalFunction(context, scope) {
|
|
78
77
|
var _a;
|
|
79
|
-
if (!scope.referencedSymbols
|
|
78
|
+
if (!scope.referencedSymbols) {
|
|
80
79
|
return false;
|
|
81
80
|
}
|
|
82
81
|
for (const [symbolId, nodes] of scope.referencedSymbols) {
|
|
@@ -100,9 +99,6 @@ function hasReferencedSymbol(context, scope, symbol) {
|
|
|
100
99
|
}
|
|
101
100
|
return false;
|
|
102
101
|
}
|
|
103
|
-
function isFunctionScopeWithDefinition(scope) {
|
|
104
|
-
return scope.node !== undefined && ts.isFunctionLike(scope.node);
|
|
105
|
-
}
|
|
106
102
|
function separateHoistedStatements(context, statements) {
|
|
107
103
|
const scope = peekScope(context);
|
|
108
104
|
const allHoistedStatments = [];
|
|
@@ -10,13 +10,13 @@ function transformBlockOrStatement(context, statement) {
|
|
|
10
10
|
return context.transformStatements(ts.isBlock(statement) ? statement.statements : statement);
|
|
11
11
|
}
|
|
12
12
|
function transformScopeBlock(context, node, scopeType) {
|
|
13
|
-
context.pushScope(scopeType);
|
|
13
|
+
context.pushScope(scopeType, node);
|
|
14
14
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
15
15
|
const scope = context.popScope();
|
|
16
16
|
return [lua.createBlock(statements, node), scope];
|
|
17
17
|
}
|
|
18
18
|
const transformBlock = (node, context) => {
|
|
19
|
-
context.pushScope(scope_1.ScopeType.Block);
|
|
19
|
+
context.pushScope(scope_1.ScopeType.Block, node);
|
|
20
20
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
21
21
|
context.popScope();
|
|
22
22
|
return lua.createDoStatement(statements, node);
|
|
@@ -13,7 +13,7 @@ const decorators_1 = require("../decorators");
|
|
|
13
13
|
function transformAccessor(context, node, className) {
|
|
14
14
|
var _a;
|
|
15
15
|
const [params, dot, restParam] = (0, function_1.transformParameters)(context, node.parameters, (0, lua_ast_1.createSelfIdentifier)());
|
|
16
|
-
const body = node.body ? (0, function_1.transformFunctionBody)(context, node.parameters, node.body, restParam)[0] : [];
|
|
16
|
+
const body = node.body ? (0, function_1.transformFunctionBody)(context, node.parameters, node.body, node, restParam)[0] : [];
|
|
17
17
|
const accessorFunction = lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.NodeFlags.Declaration);
|
|
18
18
|
if ((_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
19
19
|
return (0, decorators_1.createClassAccessorDecoratingExpression)(context, node, accessorFunction, className);
|
|
@@ -22,7 +22,7 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
// Transform body
|
|
25
|
-
const scope = context.pushScope(scope_1.ScopeType.Function);
|
|
25
|
+
const scope = context.pushScope(scope_1.ScopeType.Function, statement);
|
|
26
26
|
const body = (0, function_1.transformFunctionBodyContent)(context, statement.body);
|
|
27
27
|
const [params, dotsLiteral, restParamName] = (0, function_1.transformParameters)(context, statement.parameters, (0, lua_ast_1.createSelfIdentifier)());
|
|
28
28
|
// Make sure default parameters are assigned before fields are initialized
|
|
@@ -44,7 +44,7 @@ const transformConditionalExpression = (expression, context) => {
|
|
|
44
44
|
};
|
|
45
45
|
exports.transformConditionalExpression = transformConditionalExpression;
|
|
46
46
|
function transformIfStatement(statement, context) {
|
|
47
|
-
context.pushScope(scope_1.ScopeType.Conditional);
|
|
47
|
+
context.pushScope(scope_1.ScopeType.Conditional, statement);
|
|
48
48
|
// Check if we need to add diagnostic about Lua truthiness
|
|
49
49
|
checkOnlyTruthyCondition(statement.expression, context);
|
|
50
50
|
const condition = context.transformExpression(statement.expression);
|
|
@@ -72,7 +72,7 @@ function transformIfStatement(statement, context) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
|
-
context.pushScope(scope_1.ScopeType.Conditional);
|
|
75
|
+
context.pushScope(scope_1.ScopeType.Conditional, statement);
|
|
76
76
|
const elseStatements = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, statement.elseStatement));
|
|
77
77
|
context.popScope();
|
|
78
78
|
const elseBlock = lua.createBlock(elseStatements);
|
|
@@ -6,7 +6,7 @@ export declare function createCallableTable(functionExpression: lua.Expression):
|
|
|
6
6
|
export declare function isFunctionTypeWithProperties(context: TransformationContext, functionType: ts.Type): boolean;
|
|
7
7
|
export declare function transformFunctionBodyContent(context: TransformationContext, body: ts.ConciseBody): lua.Statement[];
|
|
8
8
|
export declare function transformFunctionBodyHeader(context: TransformationContext, bodyScope: Scope, parameters: ts.NodeArray<ts.ParameterDeclaration>, spreadIdentifier?: lua.Identifier): lua.Statement[];
|
|
9
|
-
export declare function transformFunctionBody(context: TransformationContext, parameters: ts.NodeArray<ts.ParameterDeclaration>, body: ts.ConciseBody,
|
|
9
|
+
export declare function transformFunctionBody(context: TransformationContext, parameters: ts.NodeArray<ts.ParameterDeclaration>, body: ts.ConciseBody, node: ts.FunctionLikeDeclaration, spreadIdentifier?: lua.Identifier): [lua.Statement[], Scope];
|
|
10
10
|
export declare function transformParameters(context: TransformationContext, parameters: ts.NodeArray<ts.ParameterDeclaration>, functionContext?: lua.Identifier): [lua.Identifier[], lua.DotsLiteral | undefined, lua.Identifier | undefined];
|
|
11
11
|
export declare function transformFunctionToExpression(context: TransformationContext, node: ts.FunctionLikeDeclaration): [lua.Expression, Scope];
|
|
12
12
|
export declare function transformFunctionLikeDeclaration(node: ts.FunctionLikeDeclaration, context: TransformationContext): lua.Expression;
|
|
@@ -120,9 +120,8 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
120
120
|
headerStatements.push(...bindingPatternDeclarations);
|
|
121
121
|
return headerStatements;
|
|
122
122
|
}
|
|
123
|
-
function transformFunctionBody(context, parameters, body,
|
|
124
|
-
const scope = context.pushScope(scope_1.ScopeType.Function);
|
|
125
|
-
scope.node = node;
|
|
123
|
+
function transformFunctionBody(context, parameters, body, node, spreadIdentifier) {
|
|
124
|
+
const scope = context.pushScope(scope_1.ScopeType.Function, node);
|
|
126
125
|
let bodyStatements = transformFunctionBodyContent(context, body);
|
|
127
126
|
if (node && (0, async_await_1.isAsyncFunction)(node)) {
|
|
128
127
|
bodyStatements = [lua.createReturnStatement([(0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements)])];
|
|
@@ -191,7 +190,7 @@ function transformFunctionToExpression(context, node) {
|
|
|
191
190
|
flags |= lua.NodeFlags.Declaration;
|
|
192
191
|
}
|
|
193
192
|
const [paramNames, dotsLiteral, spreadIdentifier] = transformParameters(context, node.parameters, functionContext);
|
|
194
|
-
const [transformedBody, functionScope] = transformFunctionBody(context, node.parameters, node.body,
|
|
193
|
+
const [transformedBody, functionScope] = transformFunctionBody(context, node.parameters, node.body, node, spreadIdentifier);
|
|
195
194
|
const functionExpression = lua.createFunctionExpression(lua.createBlock(transformedBody), paramNames, dotsLiteral, flags, node);
|
|
196
195
|
return [
|
|
197
196
|
node.asteriskToken
|
|
@@ -9,7 +9,7 @@ const utils_1 = require("./utils");
|
|
|
9
9
|
const scope_1 = require("../../utils/scope");
|
|
10
10
|
const transformForStatement = (statement, context) => {
|
|
11
11
|
const result = [];
|
|
12
|
-
context.pushScope(scope_1.ScopeType.Loop);
|
|
12
|
+
context.pushScope(scope_1.ScopeType.Loop, statement);
|
|
13
13
|
if (statement.initializer) {
|
|
14
14
|
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
15
15
|
(0, variable_declaration_1.checkVariableDeclarationList)(context, statement.initializer);
|
|
@@ -15,7 +15,7 @@ const block_1 = require("../block");
|
|
|
15
15
|
const identifier_1 = require("../identifier");
|
|
16
16
|
const variable_declaration_1 = require("../variable-declaration");
|
|
17
17
|
function transformLoopBody(context, loop) {
|
|
18
|
-
context.pushScope(scope_1.ScopeType.Loop);
|
|
18
|
+
context.pushScope(scope_1.ScopeType.Loop, loop);
|
|
19
19
|
const body = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, loop.statement));
|
|
20
20
|
const scope = context.popScope();
|
|
21
21
|
const scopeId = scope.id;
|
|
@@ -60,7 +60,7 @@ function getVariableDeclarationBinding(context, node) {
|
|
|
60
60
|
}
|
|
61
61
|
function transformForInitializer(context, initializer, block) {
|
|
62
62
|
const valueVariable = lua.createIdentifier("____value");
|
|
63
|
-
context.pushScope(scope_1.ScopeType.LoopInitializer);
|
|
63
|
+
context.pushScope(scope_1.ScopeType.LoopInitializer, initializer);
|
|
64
64
|
if (ts.isVariableDeclarationList(initializer)) {
|
|
65
65
|
// Declaration of new variable
|
|
66
66
|
const binding = getVariableDeclarationBinding(context, initializer);
|
|
@@ -77,7 +77,7 @@ const transformModuleDeclaration = (node, context) => {
|
|
|
77
77
|
context.currentNamespaces = node;
|
|
78
78
|
// Transform moduleblock to block and visit it
|
|
79
79
|
if (moduleHasEmittedBody(node)) {
|
|
80
|
-
context.pushScope(scope_1.ScopeType.Block);
|
|
80
|
+
context.pushScope(scope_1.ScopeType.Block, node);
|
|
81
81
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(ts.isModuleBlock(node.body) ? node.body.statements : node.body));
|
|
82
82
|
context.popScope();
|
|
83
83
|
result.push(lua.createDoStatement(statements));
|
|
@@ -27,7 +27,7 @@ const transformSourceFileNode = (node, context) => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
context.pushScope(scope_1.ScopeType.File);
|
|
30
|
+
context.pushScope(scope_1.ScopeType.File, node);
|
|
31
31
|
statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
32
32
|
context.popScope();
|
|
33
33
|
if (context.isModule) {
|
|
@@ -28,7 +28,7 @@ function isOptimizedVarArgSpread(context, symbol, identifier) {
|
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
// Scope must be a function scope associated with a real ts function
|
|
31
|
-
if (!
|
|
31
|
+
if (!ts.isFunctionLike(scope.node)) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
// Scope cannot be an async function
|
|
@@ -48,7 +48,7 @@ const coalesceCondition = (condition, conditionPrecedingStatements, switchVariab
|
|
|
48
48
|
return { precedingStatements: [...conditionPrecedingStatements, ...precedingStatements], result: comparison };
|
|
49
49
|
};
|
|
50
50
|
const transformSwitchStatement = (statement, context) => {
|
|
51
|
-
const scope = context.pushScope(scope_1.ScopeType.Switch);
|
|
51
|
+
const scope = context.pushScope(scope_1.ScopeType.Switch, statement);
|
|
52
52
|
// Give the switch and condition accumulator a unique name to prevent nested switches from acting up.
|
|
53
53
|
const switchName = `____switch${scope.id}`;
|
|
54
54
|
const conditionName = `____cond${scope.id}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.33.
|
|
3
|
+
"version": "1.33.2",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|