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 CHANGED
@@ -42,6 +42,7 @@ export declare enum LuaLibFeature {
42
42
  InstanceOf = "InstanceOf",
43
43
  InstanceOfObject = "InstanceOfObject",
44
44
  Iterator = "Iterator",
45
+ LuaIteratorSpread = "LuaIteratorSpread",
45
46
  Map = "Map",
46
47
  MathAtan2 = "MathAtan2",
47
48
  MathSign = "MathSign",
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";
@@ -0,0 +1,9 @@
1
+ local function __TS__LuaIteratorSpread(self, state, firstKey)
2
+ local results = {}
3
+ local key, value = self(state, firstKey)
4
+ while key do
5
+ results[#results + 1] = {key, value}
6
+ key, value = self(state, key)
7
+ end
8
+ return __TS__Unpack(results)
9
+ end
@@ -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,
@@ -264,6 +264,14 @@
264
264
  "Symbol"
265
265
  ]
266
266
  },
267
+ "LuaIteratorSpread": {
268
+ "exports": [
269
+ "__TS__LuaIteratorSpread"
270
+ ],
271
+ "dependencies": [
272
+ "Unpack"
273
+ ]
274
+ },
267
275
  "Map": {
268
276
  "exports": [
269
277
  "Map"
@@ -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.7.2",
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/",