typescript-to-lua 1.7.2 → 1.8.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/dist/LuaLib.d.ts +1 -0
- package/dist/LuaLib.js +1 -0
- package/dist/lualib/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/lualib_bundle.lua +11 -0
- package/dist/lualib/lualib_module_info.json +8 -0
- package/dist/transformation/utils/language-extensions.d.ts +1 -0
- package/dist/transformation/utils/language-extensions.js +5 -1
- package/dist/transformation/visitors/spread.js +4 -0
- package/package.json +1 -1
package/dist/LuaLib.d.ts
CHANGED
package/dist/LuaLib.js
CHANGED
|
@@ -46,6 +46,7 @@ var LuaLibFeature;
|
|
|
46
46
|
LuaLibFeature["InstanceOf"] = "InstanceOf";
|
|
47
47
|
LuaLibFeature["InstanceOfObject"] = "InstanceOfObject";
|
|
48
48
|
LuaLibFeature["Iterator"] = "Iterator";
|
|
49
|
+
LuaLibFeature["LuaIteratorSpread"] = "LuaIteratorSpread";
|
|
49
50
|
LuaLibFeature["Map"] = "Map";
|
|
50
51
|
LuaLibFeature["MathAtan2"] = "MathAtan2";
|
|
51
52
|
LuaLibFeature["MathSign"] = "MathSign";
|
|
@@ -1207,6 +1207,16 @@ local function __TS__InstanceOfObject(value)
|
|
|
1207
1207
|
return valueType == "table" or valueType == "function"
|
|
1208
1208
|
end
|
|
1209
1209
|
|
|
1210
|
+
local function __TS__LuaIteratorSpread(self, state, firstKey)
|
|
1211
|
+
local results = {}
|
|
1212
|
+
local key, value = self(state, firstKey)
|
|
1213
|
+
while key do
|
|
1214
|
+
results[#results + 1] = {key, value}
|
|
1215
|
+
key, value = self(state, key)
|
|
1216
|
+
end
|
|
1217
|
+
return __TS__Unpack(results)
|
|
1218
|
+
end
|
|
1219
|
+
|
|
1210
1220
|
local Map
|
|
1211
1221
|
do
|
|
1212
1222
|
Map = __TS__Class()
|
|
@@ -2448,6 +2458,7 @@ return {
|
|
|
2448
2458
|
__TS__InstanceOf = __TS__InstanceOf,
|
|
2449
2459
|
__TS__InstanceOfObject = __TS__InstanceOfObject,
|
|
2450
2460
|
__TS__Iterator = __TS__Iterator,
|
|
2461
|
+
__TS__LuaIteratorSpread = __TS__LuaIteratorSpread,
|
|
2451
2462
|
Map = Map,
|
|
2452
2463
|
__TS__MathAtan2 = __TS__MathAtan2,
|
|
2453
2464
|
__TS__MathSign = __TS__MathSign,
|
|
@@ -60,5 +60,6 @@ export declare enum IterableExtensionKind {
|
|
|
60
60
|
Pairs = "Pairs",
|
|
61
61
|
PairsKey = "PairsKey"
|
|
62
62
|
}
|
|
63
|
+
export declare function isLuaIterable(context: TransformationContext, type: ts.Type): boolean;
|
|
63
64
|
export declare function getIterableExtensionTypeForType(context: TransformationContext, type: ts.Type): IterableExtensionKind | undefined;
|
|
64
65
|
export declare function getIterableExtensionKindForNode(context: TransformationContext, node: ts.Node): IterableExtensionKind | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
|
|
3
|
+
exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.isLuaIterable = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
var ExtensionKind;
|
|
6
6
|
(function (ExtensionKind) {
|
|
@@ -96,6 +96,10 @@ var IterableExtensionKind;
|
|
|
96
96
|
IterableExtensionKind["Pairs"] = "Pairs";
|
|
97
97
|
IterableExtensionKind["PairsKey"] = "PairsKey";
|
|
98
98
|
})(IterableExtensionKind = exports.IterableExtensionKind || (exports.IterableExtensionKind = {}));
|
|
99
|
+
function isLuaIterable(context, type) {
|
|
100
|
+
return getPropertyValue(context, type, "__tstlIterable") !== undefined;
|
|
101
|
+
}
|
|
102
|
+
exports.isLuaIterable = isLuaIterable;
|
|
99
103
|
function getIterableExtensionTypeForType(context, type) {
|
|
100
104
|
const value = getPropertyValue(context, type, "__tstlIterable");
|
|
101
105
|
if (value && value in IterableExtensionKind) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformSpreadElement = exports.isOptimizedVarArgSpread = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
|
+
const language_extensions_1 = require("../utils/language-extensions");
|
|
6
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
7
8
|
const lualib_1 = require("../utils/lualib");
|
|
8
9
|
const scope_1 = require("../utils/scope");
|
|
@@ -60,6 +61,9 @@ const transformSpreadElement = (node, context) => {
|
|
|
60
61
|
if ((0, multi_1.isMultiReturnCall)(context, tsInnerExpression))
|
|
61
62
|
return innerExpression;
|
|
62
63
|
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts
|
|
64
|
+
if ((0, language_extensions_1.isLuaIterable)(context, type)) {
|
|
65
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.LuaIteratorSpread, node, innerExpression);
|
|
66
|
+
}
|
|
63
67
|
if ((0, typescript_1.isArrayType)(context, type)) {
|
|
64
68
|
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
65
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
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/",
|