typescript-to-lua 1.2.0 → 1.3.3
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 +12 -0
- package/dist/LuaLib.d.ts +1 -0
- package/dist/LuaLib.js +2 -1
- package/dist/LuaPrinter.js +4 -4
- package/dist/lualib/Await.lua +7 -3
- package/dist/lualib/CloneDescriptor.lua +6 -6
- package/dist/lualib/MathSign.lua +8 -0
- package/dist/lualib/Promise.lua +10 -2
- package/dist/lualib/lualib_bundle.lua +226 -205
- package/dist/transformation/builtins/function.js +5 -2
- package/dist/transformation/builtins/index.js +9 -7
- package/dist/transformation/builtins/math.js +7 -1
- package/dist/transformation/utils/diagnostics.d.ts +3 -6
- package/dist/transformation/utils/diagnostics.js +2 -3
- package/dist/transformation/utils/language-extensions.d.ts +2 -0
- package/dist/transformation/utils/language-extensions.js +7 -1
- package/dist/transformation/utils/lua-ast.js +5 -5
- package/dist/transformation/utils/safe-names.d.ts +4 -2
- package/dist/transformation/utils/safe-names.js +11 -5
- package/dist/transformation/utils/scope.d.ts +2 -1
- package/dist/transformation/utils/scope.js +1 -0
- package/dist/transformation/utils/typescript/types.d.ts +3 -1
- package/dist/transformation/utils/typescript/types.js +40 -13
- package/dist/transformation/visitors/binary-expression/index.js +1 -3
- package/dist/transformation/visitors/call.js +7 -40
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/class/members/fields.js +12 -8
- package/dist/transformation/visitors/conditional.js +2 -23
- package/dist/transformation/visitors/errors.js +11 -9
- package/dist/transformation/visitors/expression-statement.d.ts +3 -1
- package/dist/transformation/visitors/expression-statement.js +21 -19
- package/dist/transformation/visitors/function.d.ts +2 -0
- package/dist/transformation/visitors/function.js +58 -6
- 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/pairsIterable.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
- 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/loops/for-of.js +4 -0
- package/dist/transformation/visitors/loops/utils.js +6 -1
- package/dist/transformation/visitors/namespace.js +1 -1
- package/dist/transformation/visitors/spread.js +14 -7
- package/dist/transformation/visitors/variable-declaration.js +16 -1
- package/dist/transformation/visitors/void.d.ts +1 -4
- package/dist/transformation/visitors/void.js +6 -8
- package/language-extensions/index.d.ts +11 -1
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ const export_1 = require("../utils/export");
|
|
|
10
10
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
11
11
|
const lualib_1 = require("../utils/lualib");
|
|
12
12
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
13
|
+
const function_1 = require("./function");
|
|
13
14
|
const identifier_1 = require("./identifier");
|
|
14
15
|
const multi_1 = require("./language-extensions/multi");
|
|
15
16
|
const literal_1 = require("./literal");
|
|
@@ -183,7 +184,10 @@ function transformVariableDeclaration(context, statement) {
|
|
|
183
184
|
// Find variable identifier
|
|
184
185
|
const identifierName = (0, identifier_1.transformIdentifier)(context, statement.name);
|
|
185
186
|
const value = statement.initializer && context.transformExpression(statement.initializer);
|
|
186
|
-
|
|
187
|
+
// Wrap functions being assigned to a type that contains additional properties in a callable table
|
|
188
|
+
// This catches 'const foo = function() {}; foo.bar = "FOOBAR";'
|
|
189
|
+
const wrappedValue = value && shouldWrapInitializerInCallableTable() ? (0, function_1.createCallableTable)(value) : value;
|
|
190
|
+
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, identifierName, wrappedValue, statement);
|
|
187
191
|
}
|
|
188
192
|
else if (ts.isArrayBindingPattern(statement.name) || ts.isObjectBindingPattern(statement.name)) {
|
|
189
193
|
return transformBindingVariableDeclaration(context, statement.name, statement.initializer);
|
|
@@ -191,6 +195,17 @@ function transformVariableDeclaration(context, statement) {
|
|
|
191
195
|
else {
|
|
192
196
|
return (0, utils_1.assertNever)(statement.name);
|
|
193
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
|
+
}
|
|
194
209
|
}
|
|
195
210
|
exports.transformVariableDeclaration = transformVariableDeclaration;
|
|
196
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
|
|
@@ -78,6 +78,16 @@ declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
|
|
|
78
78
|
LuaIterator<TValue, TState> &
|
|
79
79
|
LuaExtension<"__luaIterableBrand">;
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Represents an object that can be iterated with pairs()
|
|
83
|
+
* For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
|
|
84
|
+
*
|
|
85
|
+
* @param TKey The type of the key returned each iteration.
|
|
86
|
+
* @param TValue The type of the value returned each iteration.
|
|
87
|
+
*/
|
|
88
|
+
declare type LuaPairsIterable<TKey extends AnyNotNil, TValue> = Iterable<[TKey, TValue]> &
|
|
89
|
+
LuaExtension<"__luaPairsIterableBrand">;
|
|
90
|
+
|
|
81
91
|
/**
|
|
82
92
|
* Calls to functions with this type are translated to `left + right`.
|
|
83
93
|
* For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
|
|
@@ -535,7 +545,7 @@ declare type LuaTableDeleteMethod<TKey extends AnyNotNil> = ((key: TKey) => bool
|
|
|
535
545
|
* @param TKey The type of the keys used to access the table.
|
|
536
546
|
* @param TValue The type of the values stored in the table.
|
|
537
547
|
*/
|
|
538
|
-
declare interface LuaTable<TKey extends AnyNotNil = AnyNotNil, TValue = any> {
|
|
548
|
+
declare interface LuaTable<TKey extends AnyNotNil = AnyNotNil, TValue = any> extends LuaPairsIterable<TKey, TValue> {
|
|
539
549
|
length: LuaLengthMethod<number>;
|
|
540
550
|
get: LuaTableGetMethod<TKey, TValue>;
|
|
541
551
|
set: LuaTableSetMethod<TKey, TValue>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.3",
|
|
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/",
|