typescript-to-lua 1.16.0 → 1.16.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/lualib/5.0/Map.lua +1 -1
- package/dist/lualib/5.0/Set.lua +1 -1
- package/dist/lualib/5.0/WeakMap.lua +1 -1
- package/dist/lualib/5.0/WeakSet.lua +1 -1
- package/dist/lualib/5.0/lualib_bundle.lua +4 -4
- package/dist/lualib/universal/Map.lua +1 -1
- package/dist/lualib/universal/Set.lua +1 -1
- package/dist/lualib/universal/WeakMap.lua +1 -1
- package/dist/lualib/universal/WeakSet.lua +1 -1
- package/dist/lualib/universal/lualib_bundle.lua +4 -4
- package/dist/transformation/utils/typescript/types.d.ts +1 -0
- package/dist/transformation/utils/typescript/types.js +19 -1
- package/dist/transformation/visitors/class/index.js +9 -6
- package/dist/transformation/visitors/class/members/method.d.ts +1 -1
- package/dist/transformation/visitors/class/members/method.js +11 -4
- package/dist/transformation/visitors/spread.js +2 -1
- package/package.json +1 -1
package/dist/lualib/5.0/Map.lua
CHANGED
package/dist/lualib/5.0/Set.lua
CHANGED
|
@@ -26,7 +26,6 @@ do
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
WeakMap[Symbol.species] = WeakMap
|
|
30
29
|
function WeakMap.prototype.delete(self, key)
|
|
31
30
|
local contains = self:has(key)
|
|
32
31
|
self.items[key] = nil
|
|
@@ -42,4 +41,5 @@ do
|
|
|
42
41
|
self.items[key] = value
|
|
43
42
|
return self
|
|
44
43
|
end
|
|
44
|
+
WeakMap[Symbol.species] = WeakMap
|
|
45
45
|
end
|
|
@@ -25,7 +25,6 @@ do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
WeakSet[Symbol.species] = WeakSet
|
|
29
28
|
function WeakSet.prototype.add(self, value)
|
|
30
29
|
self.items[value] = true
|
|
31
30
|
return self
|
|
@@ -38,4 +37,5 @@ do
|
|
|
38
37
|
function WeakSet.prototype.has(self, value)
|
|
39
38
|
return self.items[value] == true
|
|
40
39
|
end
|
|
40
|
+
WeakSet[Symbol.species] = WeakSet
|
|
41
41
|
end
|
|
@@ -1278,7 +1278,6 @@ do
|
|
|
1278
1278
|
end
|
|
1279
1279
|
end
|
|
1280
1280
|
end
|
|
1281
|
-
Map[Symbol.species] = Map
|
|
1282
1281
|
function Map.prototype.clear(self)
|
|
1283
1282
|
self.items = {}
|
|
1284
1283
|
self.nextKey = {}
|
|
@@ -1386,6 +1385,7 @@ do
|
|
|
1386
1385
|
end
|
|
1387
1386
|
}
|
|
1388
1387
|
end
|
|
1388
|
+
Map[Symbol.species] = Map
|
|
1389
1389
|
end
|
|
1390
1390
|
|
|
1391
1391
|
local function __TS__StringSlice(self, start, ____end)
|
|
@@ -1902,7 +1902,6 @@ do
|
|
|
1902
1902
|
end
|
|
1903
1903
|
end
|
|
1904
1904
|
end
|
|
1905
|
-
Set[Symbol.species] = Set
|
|
1906
1905
|
function Set.prototype.add(self, value)
|
|
1907
1906
|
local isNewValue = not self:has(value)
|
|
1908
1907
|
if isNewValue then
|
|
@@ -2002,6 +2001,7 @@ do
|
|
|
2002
2001
|
end
|
|
2003
2002
|
}
|
|
2004
2003
|
end
|
|
2004
|
+
Set[Symbol.species] = Set
|
|
2005
2005
|
end
|
|
2006
2006
|
|
|
2007
2007
|
local function __TS__SparseArrayNew(...)
|
|
@@ -2052,7 +2052,6 @@ do
|
|
|
2052
2052
|
end
|
|
2053
2053
|
end
|
|
2054
2054
|
end
|
|
2055
|
-
WeakMap[Symbol.species] = WeakMap
|
|
2056
2055
|
function WeakMap.prototype.delete(self, key)
|
|
2057
2056
|
local contains = self:has(key)
|
|
2058
2057
|
self.items[key] = nil
|
|
@@ -2068,6 +2067,7 @@ do
|
|
|
2068
2067
|
self.items[key] = value
|
|
2069
2068
|
return self
|
|
2070
2069
|
end
|
|
2070
|
+
WeakMap[Symbol.species] = WeakMap
|
|
2071
2071
|
end
|
|
2072
2072
|
|
|
2073
2073
|
local WeakSet
|
|
@@ -2097,7 +2097,6 @@ do
|
|
|
2097
2097
|
end
|
|
2098
2098
|
end
|
|
2099
2099
|
end
|
|
2100
|
-
WeakSet[Symbol.species] = WeakSet
|
|
2101
2100
|
function WeakSet.prototype.add(self, value)
|
|
2102
2101
|
self.items[value] = true
|
|
2103
2102
|
return self
|
|
@@ -2110,6 +2109,7 @@ do
|
|
|
2110
2109
|
function WeakSet.prototype.has(self, value)
|
|
2111
2110
|
return self.items[value] == true
|
|
2112
2111
|
end
|
|
2112
|
+
WeakSet[Symbol.species] = WeakSet
|
|
2113
2113
|
end
|
|
2114
2114
|
|
|
2115
2115
|
local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
@@ -26,7 +26,6 @@ do
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
WeakMap[Symbol.species] = WeakMap
|
|
30
29
|
function WeakMap.prototype.delete(self, key)
|
|
31
30
|
local contains = self:has(key)
|
|
32
31
|
self.items[key] = nil
|
|
@@ -42,4 +41,5 @@ do
|
|
|
42
41
|
self.items[key] = value
|
|
43
42
|
return self
|
|
44
43
|
end
|
|
44
|
+
WeakMap[Symbol.species] = WeakMap
|
|
45
45
|
end
|
|
@@ -25,7 +25,6 @@ do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
WeakSet[Symbol.species] = WeakSet
|
|
29
28
|
function WeakSet.prototype.add(self, value)
|
|
30
29
|
self.items[value] = true
|
|
31
30
|
return self
|
|
@@ -38,4 +37,5 @@ do
|
|
|
38
37
|
function WeakSet.prototype.has(self, value)
|
|
39
38
|
return self.items[value] == true
|
|
40
39
|
end
|
|
40
|
+
WeakSet[Symbol.species] = WeakSet
|
|
41
41
|
end
|
|
@@ -1254,7 +1254,6 @@ do
|
|
|
1254
1254
|
end
|
|
1255
1255
|
end
|
|
1256
1256
|
end
|
|
1257
|
-
Map[Symbol.species] = Map
|
|
1258
1257
|
function Map.prototype.clear(self)
|
|
1259
1258
|
self.items = {}
|
|
1260
1259
|
self.nextKey = {}
|
|
@@ -1362,6 +1361,7 @@ do
|
|
|
1362
1361
|
end
|
|
1363
1362
|
}
|
|
1364
1363
|
end
|
|
1364
|
+
Map[Symbol.species] = Map
|
|
1365
1365
|
end
|
|
1366
1366
|
|
|
1367
1367
|
local __TS__Match = string.match
|
|
@@ -1838,7 +1838,6 @@ do
|
|
|
1838
1838
|
end
|
|
1839
1839
|
end
|
|
1840
1840
|
end
|
|
1841
|
-
Set[Symbol.species] = Set
|
|
1842
1841
|
function Set.prototype.add(self, value)
|
|
1843
1842
|
local isNewValue = not self:has(value)
|
|
1844
1843
|
if isNewValue then
|
|
@@ -1938,6 +1937,7 @@ do
|
|
|
1938
1937
|
end
|
|
1939
1938
|
}
|
|
1940
1939
|
end
|
|
1940
|
+
Set[Symbol.species] = Set
|
|
1941
1941
|
end
|
|
1942
1942
|
|
|
1943
1943
|
local function __TS__SparseArrayNew(...)
|
|
@@ -1989,7 +1989,6 @@ do
|
|
|
1989
1989
|
end
|
|
1990
1990
|
end
|
|
1991
1991
|
end
|
|
1992
|
-
WeakMap[Symbol.species] = WeakMap
|
|
1993
1992
|
function WeakMap.prototype.delete(self, key)
|
|
1994
1993
|
local contains = self:has(key)
|
|
1995
1994
|
self.items[key] = nil
|
|
@@ -2005,6 +2004,7 @@ do
|
|
|
2005
2004
|
self.items[key] = value
|
|
2006
2005
|
return self
|
|
2007
2006
|
end
|
|
2007
|
+
WeakMap[Symbol.species] = WeakMap
|
|
2008
2008
|
end
|
|
2009
2009
|
|
|
2010
2010
|
local WeakSet
|
|
@@ -2034,7 +2034,6 @@ do
|
|
|
2034
2034
|
end
|
|
2035
2035
|
end
|
|
2036
2036
|
end
|
|
2037
|
-
WeakSet[Symbol.species] = WeakSet
|
|
2038
2037
|
function WeakSet.prototype.add(self, value)
|
|
2039
2038
|
self.items[value] = true
|
|
2040
2039
|
return self
|
|
@@ -2047,6 +2046,7 @@ do
|
|
|
2047
2046
|
function WeakSet.prototype.has(self, value)
|
|
2048
2047
|
return self.items[value] == true
|
|
2049
2048
|
end
|
|
2049
|
+
WeakSet[Symbol.species] = WeakSet
|
|
2050
2050
|
end
|
|
2051
2051
|
|
|
2052
2052
|
local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
@@ -9,6 +9,7 @@ export declare function isNumberType(context: TransformationContext, type: ts.Ty
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function forTypeOrAnySupertype(context: TransformationContext, type: ts.Type, predicate: (type: ts.Type) => boolean): boolean;
|
|
11
11
|
export declare function isArrayType(context: TransformationContext, type: ts.Type): boolean;
|
|
12
|
+
export declare function isAlwaysArrayType(context: TransformationContext, type: ts.Type): boolean;
|
|
12
13
|
export declare function isFunctionType(type: ts.Type): boolean;
|
|
13
14
|
export declare function canBeFalsy(context: TransformationContext, type: ts.Type): boolean;
|
|
14
15
|
export declare function canBeFalsyWhenNotNull(context: TransformationContext, type: ts.Type): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0;
|
|
3
|
+
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isAlwaysArrayType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
function typeAlwaysHasSomeOfFlags(context, type, flags) {
|
|
6
6
|
const baseConstraint = context.checker.getBaseConstraintOfType(type);
|
|
@@ -63,6 +63,20 @@ function isExplicitArrayType(context, type) {
|
|
|
63
63
|
}
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
|
+
function isAlwaysExplicitArrayType(context, type) {
|
|
67
|
+
if (context.checker.isArrayType(type) || context.checker.isTupleType(type))
|
|
68
|
+
return true;
|
|
69
|
+
if (type.symbol) {
|
|
70
|
+
const baseConstraint = context.checker.getBaseConstraintOfType(type);
|
|
71
|
+
if (baseConstraint && baseConstraint !== type) {
|
|
72
|
+
return isAlwaysExplicitArrayType(context, baseConstraint);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (type.isUnionOrIntersection()) {
|
|
76
|
+
return type.types.every(t => isAlwaysExplicitArrayType(context, t));
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
66
80
|
/**
|
|
67
81
|
* Iterate over a type and its bases until the callback returns true.
|
|
68
82
|
*/
|
|
@@ -83,6 +97,10 @@ function isArrayType(context, type) {
|
|
|
83
97
|
return forTypeOrAnySupertype(context, type, t => isExplicitArrayType(context, t));
|
|
84
98
|
}
|
|
85
99
|
exports.isArrayType = isArrayType;
|
|
100
|
+
function isAlwaysArrayType(context, type) {
|
|
101
|
+
return forTypeOrAnySupertype(context, type, t => isAlwaysExplicitArrayType(context, t));
|
|
102
|
+
}
|
|
103
|
+
exports.isAlwaysArrayType = isAlwaysArrayType;
|
|
86
104
|
function isFunctionType(type) {
|
|
87
105
|
return type.getCallSignatures().length > 0;
|
|
88
106
|
}
|
|
@@ -102,6 +102,15 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
102
102
|
result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
|
|
103
103
|
}
|
|
104
104
|
// Transform class members
|
|
105
|
+
// First transform the methods, in case the static properties call them
|
|
106
|
+
for (const member of classDeclaration.members) {
|
|
107
|
+
if (ts.isMethodDeclaration(member)) {
|
|
108
|
+
// Methods
|
|
109
|
+
const statements = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
|
|
110
|
+
result.push(...statements);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Then transform the rest
|
|
105
114
|
for (const member of classDeclaration.members) {
|
|
106
115
|
if (ts.isAccessor(member)) {
|
|
107
116
|
// Accessors
|
|
@@ -113,12 +122,6 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
113
122
|
result.push(accessorsResult);
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
|
-
else if (ts.isMethodDeclaration(member)) {
|
|
117
|
-
// Methods
|
|
118
|
-
const statement = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
|
|
119
|
-
if (statement)
|
|
120
|
-
result.push(statement);
|
|
121
|
-
}
|
|
122
125
|
else if (ts.isPropertyDeclaration(member)) {
|
|
123
126
|
// Properties
|
|
124
127
|
if ((0, utils_1.isStaticNode)(member)) {
|
|
@@ -3,4 +3,4 @@ import * as lua from "../../../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../../../context";
|
|
4
4
|
export declare function transformMemberExpressionOwnerName(node: ts.PropertyDeclaration | ts.MethodDeclaration | ts.AccessorDeclaration, className: lua.Identifier): lua.Expression;
|
|
5
5
|
export declare function transformMethodName(context: TransformationContext, node: ts.MethodDeclaration): lua.Expression;
|
|
6
|
-
export declare function transformMethodDeclaration(context: TransformationContext, node: ts.MethodDeclaration, className: lua.Identifier): lua.Statement
|
|
6
|
+
export declare function transformMethodDeclaration(context: TransformationContext, node: ts.MethodDeclaration, className: lua.Identifier): lua.Statement[];
|
|
@@ -24,7 +24,7 @@ function transformMethodDeclaration(context, node, className) {
|
|
|
24
24
|
var _a, _b;
|
|
25
25
|
// Don't transform methods without body (overload declarations)
|
|
26
26
|
if (!node.body)
|
|
27
|
-
return;
|
|
27
|
+
return [];
|
|
28
28
|
const methodTable = transformMemberExpressionOwnerName(node, className);
|
|
29
29
|
const methodName = transformMethodName(context, node);
|
|
30
30
|
const [functionExpression] = (0, function_1.transformFunctionToExpression)(context, node);
|
|
@@ -33,14 +33,21 @@ function transformMethodDeclaration(context, node, className) {
|
|
|
33
33
|
if (methodHasDecorators || methodHasParameterDecorators) {
|
|
34
34
|
if (context.options.experimentalDecorators) {
|
|
35
35
|
// Legacy decorator statement
|
|
36
|
-
return
|
|
36
|
+
return [
|
|
37
|
+
lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression),
|
|
38
|
+
lua.createExpressionStatement((0, decorators_1.createClassMethodDecoratingExpression)(context, node, functionExpression, className)),
|
|
39
|
+
];
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
39
|
-
return
|
|
42
|
+
return [
|
|
43
|
+
lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), (0, decorators_1.createClassMethodDecoratingExpression)(context, node, functionExpression, className), node),
|
|
44
|
+
];
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
|
-
return
|
|
48
|
+
return [
|
|
49
|
+
lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression, node),
|
|
50
|
+
];
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
exports.transformMethodDeclaration = transformMethodDeclaration;
|
|
@@ -83,7 +83,8 @@ const transformSpreadElement = (node, context) => {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts
|
|
86
|
-
if ((0, typescript_1.
|
|
86
|
+
if ((0, typescript_1.isAlwaysArrayType)(context, type)) {
|
|
87
|
+
// All union members must be arrays to be able to shortcut to unpack call
|
|
87
88
|
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
88
89
|
}
|
|
89
90
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Spread, node, innerExpression);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.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/",
|