typescript-to-lua 1.24.0 → 1.25.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
@@ -55,6 +55,7 @@ export declare enum LuaLibFeature {
55
55
  Iterator = "Iterator",
56
56
  LuaIteratorSpread = "LuaIteratorSpread",
57
57
  Map = "Map",
58
+ MapGroupBy = "MapGroupBy",
58
59
  Match = "Match",
59
60
  MathAtan2 = "MathAtan2",
60
61
  MathModf = "MathModf",
@@ -74,6 +75,7 @@ export declare enum LuaLibFeature {
74
75
  ObjectFromEntries = "ObjectFromEntries",
75
76
  ObjectGetOwnPropertyDescriptor = "ObjectGetOwnPropertyDescriptor",
76
77
  ObjectGetOwnPropertyDescriptors = "ObjectGetOwnPropertyDescriptors",
78
+ ObjectGroupBy = "ObjectGroupBy",
77
79
  ObjectKeys = "ObjectKeys",
78
80
  ObjectRest = "ObjectRest",
79
81
  ObjectValues = "ObjectValues",
package/dist/LuaLib.js CHANGED
@@ -60,6 +60,7 @@ var LuaLibFeature;
60
60
  LuaLibFeature["Iterator"] = "Iterator";
61
61
  LuaLibFeature["LuaIteratorSpread"] = "LuaIteratorSpread";
62
62
  LuaLibFeature["Map"] = "Map";
63
+ LuaLibFeature["MapGroupBy"] = "MapGroupBy";
63
64
  LuaLibFeature["Match"] = "Match";
64
65
  LuaLibFeature["MathAtan2"] = "MathAtan2";
65
66
  LuaLibFeature["MathModf"] = "MathModf";
@@ -79,6 +80,7 @@ var LuaLibFeature;
79
80
  LuaLibFeature["ObjectFromEntries"] = "ObjectFromEntries";
80
81
  LuaLibFeature["ObjectGetOwnPropertyDescriptor"] = "ObjectGetOwnPropertyDescriptor";
81
82
  LuaLibFeature["ObjectGetOwnPropertyDescriptors"] = "ObjectGetOwnPropertyDescriptors";
83
+ LuaLibFeature["ObjectGroupBy"] = "ObjectGroupBy";
82
84
  LuaLibFeature["ObjectKeys"] = "ObjectKeys";
83
85
  LuaLibFeature["ObjectRest"] = "ObjectRest";
84
86
  LuaLibFeature["ObjectValues"] = "ObjectValues";
@@ -97,7 +97,7 @@ function createConfigFileUpdater(optionsToExtend) {
97
97
  if (!configFile || !configFilePath)
98
98
  return [];
99
99
  if (!configFileMap.has(configFile)) {
100
- const parsedConfigFile = (0, parse_1.updateParsedConfigFile)(ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, path.dirname(configFilePath), optionsToExtend, configFilePath));
100
+ const parsedConfigFile = parseConfigFileWithSystem(configFilePath, optionsToExtend, ts.sys);
101
101
  configFileMap.set(configFile, parsedConfigFile);
102
102
  }
103
103
  const parsedConfigFile = configFileMap.get(configFile);
@@ -0,0 +1,15 @@
1
+ local function __TS__MapGroupBy(items, keySelector)
2
+ local result = __TS__New(Map)
3
+ local i = 0
4
+ for ____, item in __TS__Iterator(items) do
5
+ local key = keySelector(nil, item, i)
6
+ if result:has(key) then
7
+ local ____temp_0 = result:get(key)
8
+ ____temp_0[table.getn(____temp_0) + 1] = item
9
+ else
10
+ result:set(key, {item})
11
+ end
12
+ i = i + 1
13
+ end
14
+ return result
15
+ end
@@ -0,0 +1,15 @@
1
+ local function __TS__ObjectGroupBy(items, keySelector)
2
+ local result = {}
3
+ local i = 0
4
+ for ____, item in __TS__Iterator(items) do
5
+ local key = keySelector(nil, item, i)
6
+ if result[key] ~= nil then
7
+ local ____result_key_0 = result[key]
8
+ ____result_key_0[table.getn(____result_key_0) + 1] = item
9
+ else
10
+ result[key] = {item}
11
+ end
12
+ i = i + 1
13
+ end
14
+ return result
15
+ end
@@ -1446,6 +1446,22 @@ do
1446
1446
  Map[Symbol.species] = Map
1447
1447
  end
1448
1448
 
1449
+ local function __TS__MapGroupBy(items, keySelector)
1450
+ local result = __TS__New(Map)
1451
+ local i = 0
1452
+ for ____, item in __TS__Iterator(items) do
1453
+ local key = keySelector(nil, item, i)
1454
+ if result:has(key) then
1455
+ local ____temp_0 = result:get(key)
1456
+ ____temp_0[table.getn(____temp_0) + 1] = item
1457
+ else
1458
+ result:set(key, {item})
1459
+ end
1460
+ i = i + 1
1461
+ end
1462
+ return result
1463
+ end
1464
+
1449
1465
  local function __TS__StringSlice(self, start, ____end)
1450
1466
  if start == nil or start ~= start then
1451
1467
  start = 0
@@ -1740,6 +1756,22 @@ local function __TS__ObjectFromEntries(entries)
1740
1756
  return obj
1741
1757
  end
1742
1758
 
1759
+ local function __TS__ObjectGroupBy(items, keySelector)
1760
+ local result = {}
1761
+ local i = 0
1762
+ for ____, item in __TS__Iterator(items) do
1763
+ local key = keySelector(nil, item, i)
1764
+ if result[key] ~= nil then
1765
+ local ____result_key_0 = result[key]
1766
+ ____result_key_0[table.getn(____result_key_0) + 1] = item
1767
+ else
1768
+ result[key] = {item}
1769
+ end
1770
+ i = i + 1
1771
+ end
1772
+ return result
1773
+ end
1774
+
1743
1775
  local function __TS__ObjectKeys(obj)
1744
1776
  local result = {}
1745
1777
  local len = 0
@@ -2623,6 +2655,7 @@ return {
2623
2655
  __TS__Iterator = __TS__Iterator,
2624
2656
  __TS__LuaIteratorSpread = __TS__LuaIteratorSpread,
2625
2657
  Map = Map,
2658
+ __TS__MapGroupBy = __TS__MapGroupBy,
2626
2659
  __TS__Match = __TS__Match,
2627
2660
  __TS__MathAtan2 = __TS__MathAtan2,
2628
2661
  __TS__MathModf = __TS__MathModf,
@@ -2642,6 +2675,7 @@ return {
2642
2675
  __TS__ObjectFromEntries = __TS__ObjectFromEntries,
2643
2676
  __TS__ObjectGetOwnPropertyDescriptor = __TS__ObjectGetOwnPropertyDescriptor,
2644
2677
  __TS__ObjectGetOwnPropertyDescriptors = __TS__ObjectGetOwnPropertyDescriptors,
2678
+ __TS__ObjectGroupBy = __TS__ObjectGroupBy,
2645
2679
  __TS__ObjectKeys = __TS__ObjectKeys,
2646
2680
  __TS__ObjectRest = __TS__ObjectRest,
2647
2681
  __TS__ObjectValues = __TS__ObjectValues,
@@ -351,6 +351,16 @@
351
351
  "Iterator"
352
352
  ]
353
353
  },
354
+ "MapGroupBy": {
355
+ "exports": [
356
+ "__TS__MapGroupBy"
357
+ ],
358
+ "dependencies": [
359
+ "Map",
360
+ "New",
361
+ "Iterator"
362
+ ]
363
+ },
354
364
  "Match": {
355
365
  "exports": [
356
366
  "__TS__Match"
@@ -471,6 +481,14 @@
471
481
  "__TS__ObjectGetOwnPropertyDescriptors"
472
482
  ]
473
483
  },
484
+ "ObjectGroupBy": {
485
+ "exports": [
486
+ "__TS__ObjectGroupBy"
487
+ ],
488
+ "dependencies": [
489
+ "Iterator"
490
+ ]
491
+ },
474
492
  "ObjectKeys": {
475
493
  "exports": [
476
494
  "__TS__ObjectKeys"
@@ -0,0 +1,15 @@
1
+ local function __TS__MapGroupBy(items, keySelector)
2
+ local result = __TS__New(Map)
3
+ local i = 0
4
+ for ____, item in __TS__Iterator(items) do
5
+ local key = keySelector(nil, item, i)
6
+ if result:has(key) then
7
+ local ____temp_0 = result:get(key)
8
+ ____temp_0[#____temp_0 + 1] = item
9
+ else
10
+ result:set(key, {item})
11
+ end
12
+ i = i + 1
13
+ end
14
+ return result
15
+ end
@@ -0,0 +1,15 @@
1
+ local function __TS__ObjectGroupBy(items, keySelector)
2
+ local result = {}
3
+ local i = 0
4
+ for ____, item in __TS__Iterator(items) do
5
+ local key = keySelector(nil, item, i)
6
+ if result[key] ~= nil then
7
+ local ____result_key_0 = result[key]
8
+ ____result_key_0[#____result_key_0 + 1] = item
9
+ else
10
+ result[key] = {item}
11
+ end
12
+ i = i + 1
13
+ end
14
+ return result
15
+ end
@@ -1417,6 +1417,22 @@ do
1417
1417
  Map[Symbol.species] = Map
1418
1418
  end
1419
1419
 
1420
+ local function __TS__MapGroupBy(items, keySelector)
1421
+ local result = __TS__New(Map)
1422
+ local i = 0
1423
+ for ____, item in __TS__Iterator(items) do
1424
+ local key = keySelector(nil, item, i)
1425
+ if result:has(key) then
1426
+ local ____temp_0 = result:get(key)
1427
+ ____temp_0[#____temp_0 + 1] = item
1428
+ else
1429
+ result:set(key, {item})
1430
+ end
1431
+ i = i + 1
1432
+ end
1433
+ return result
1434
+ end
1435
+
1420
1436
  local __TS__Match = string.match
1421
1437
 
1422
1438
  local __TS__MathAtan2 = math.atan2 or math.atan
@@ -1671,6 +1687,22 @@ local function __TS__ObjectFromEntries(entries)
1671
1687
  return obj
1672
1688
  end
1673
1689
 
1690
+ local function __TS__ObjectGroupBy(items, keySelector)
1691
+ local result = {}
1692
+ local i = 0
1693
+ for ____, item in __TS__Iterator(items) do
1694
+ local key = keySelector(nil, item, i)
1695
+ if result[key] ~= nil then
1696
+ local ____result_key_0 = result[key]
1697
+ ____result_key_0[#____result_key_0 + 1] = item
1698
+ else
1699
+ result[key] = {item}
1700
+ end
1701
+ i = i + 1
1702
+ end
1703
+ return result
1704
+ end
1705
+
1674
1706
  local function __TS__ObjectKeys(obj)
1675
1707
  local result = {}
1676
1708
  local len = 0
@@ -2563,6 +2595,7 @@ return {
2563
2595
  __TS__Iterator = __TS__Iterator,
2564
2596
  __TS__LuaIteratorSpread = __TS__LuaIteratorSpread,
2565
2597
  Map = Map,
2598
+ __TS__MapGroupBy = __TS__MapGroupBy,
2566
2599
  __TS__Match = __TS__Match,
2567
2600
  __TS__MathAtan2 = __TS__MathAtan2,
2568
2601
  __TS__MathModf = __TS__MathModf,
@@ -2582,6 +2615,7 @@ return {
2582
2615
  __TS__ObjectFromEntries = __TS__ObjectFromEntries,
2583
2616
  __TS__ObjectGetOwnPropertyDescriptor = __TS__ObjectGetOwnPropertyDescriptor,
2584
2617
  __TS__ObjectGetOwnPropertyDescriptors = __TS__ObjectGetOwnPropertyDescriptors,
2618
+ __TS__ObjectGroupBy = __TS__ObjectGroupBy,
2585
2619
  __TS__ObjectKeys = __TS__ObjectKeys,
2586
2620
  __TS__ObjectRest = __TS__ObjectRest,
2587
2621
  __TS__ObjectValues = __TS__ObjectValues,
@@ -361,6 +361,16 @@
361
361
  "Iterator"
362
362
  ]
363
363
  },
364
+ "MapGroupBy": {
365
+ "exports": [
366
+ "__TS__MapGroupBy"
367
+ ],
368
+ "dependencies": [
369
+ "Map",
370
+ "New",
371
+ "Iterator"
372
+ ]
373
+ },
364
374
  "Match": {
365
375
  "exports": [
366
376
  "__TS__Match"
@@ -477,6 +487,14 @@
477
487
  "__TS__ObjectGetOwnPropertyDescriptors"
478
488
  ]
479
489
  },
490
+ "ObjectGroupBy": {
491
+ "exports": [
492
+ "__TS__ObjectGroupBy"
493
+ ],
494
+ "dependencies": [
495
+ "Iterator"
496
+ ]
497
+ },
480
498
  "ObjectKeys": {
481
499
  "exports": [
482
500
  "__TS__ObjectKeys"
@@ -20,6 +20,7 @@ const string_1 = require("./string");
20
20
  const symbol_1 = require("./symbol");
21
21
  const diagnostics_1 = require("../utils/diagnostics");
22
22
  const CompilerOptions_1 = require("../../CompilerOptions");
23
+ const map_1 = require("./map");
23
24
  function transformBuiltinPropertyAccessExpression(context, node) {
24
25
  const ownerType = context.checker.getTypeAtLocation(node.expression);
25
26
  if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
@@ -81,6 +82,9 @@ function tryTransformBuiltinGlobalMethodCall(context, node, calledMethod) {
81
82
  case "Console":
82
83
  result = (0, console_1.transformConsoleCall)(context, node, calledMethod);
83
84
  break;
85
+ case "MapConstructor":
86
+ result = (0, map_1.transformMapConstructorCall)(context, node, calledMethod);
87
+ break;
84
88
  case "Math":
85
89
  result = (0, math_1.transformMathCall)(context, node, calledMethod);
86
90
  break;
@@ -0,0 +1,4 @@
1
+ import * as lua from "../../LuaAST";
2
+ import * as ts from "typescript";
3
+ import { TransformationContext } from "../context";
4
+ export declare function transformMapConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformMapConstructorCall = void 0;
4
+ const diagnostics_1 = require("../utils/diagnostics");
5
+ const call_1 = require("../visitors/call");
6
+ const lualib_1 = require("../utils/lualib");
7
+ function transformMapConstructorCall(context, node, calledMethod) {
8
+ const args = (0, call_1.transformArguments)(context, node.arguments);
9
+ const methodName = calledMethod.name.text;
10
+ switch (methodName) {
11
+ case "groupBy":
12
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.MapGroupBy, node, ...args);
13
+ default:
14
+ context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Map", methodName));
15
+ }
16
+ }
17
+ exports.transformMapConstructorCall = transformMapConstructorCall;
18
+ //# sourceMappingURL=map.js.map
@@ -21,6 +21,8 @@ function transformObjectConstructorCall(context, node, calledMethod) {
21
21
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectGetOwnPropertyDescriptor, node, ...args);
22
22
  case "getOwnPropertyDescriptors":
23
23
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectGetOwnPropertyDescriptors, node, ...args);
24
+ case "groupBy":
25
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectGroupBy, node, ...args);
24
26
  case "keys":
25
27
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectKeys, node, ...args);
26
28
  case "values":
@@ -16,6 +16,7 @@ const call_extension_1 = require("./language-extensions/call-extension");
16
16
  const multi_1 = require("./language-extensions/multi");
17
17
  const optional_chaining_1 = require("./optional-chaining");
18
18
  const typescript_2 = require("typescript");
19
+ const identifier_1 = require("./identifier");
19
20
  function addOneToArrayAccessArgument(context, node, index) {
20
21
  const type = context.checker.getTypeAtLocation(node.expression);
21
22
  const argumentType = context.checker.getTypeAtLocation(node.argumentExpression);
@@ -76,9 +77,14 @@ exports.transformElementAccessExpressionWithCapture = transformElementAccessExpr
76
77
  const transformPropertyAccessExpression = (node, context) => transformPropertyAccessExpressionWithCapture(context, node, undefined).expression;
77
78
  exports.transformPropertyAccessExpression = transformPropertyAccessExpression;
78
79
  function transformPropertyAccessExpressionWithCapture(context, node, thisValueCapture) {
79
- const property = node.name.text;
80
80
  const type = context.checker.getTypeAtLocation(node.expression);
81
81
  const isOptionalLeft = (0, optional_chaining_1.isOptionalContinuation)(node.expression);
82
+ let property = node.name.text;
83
+ const symbol = context.checker.getSymbolAtLocation(node.name);
84
+ const customName = (0, identifier_1.getCustomNameFromSymbol)(symbol);
85
+ if (customName) {
86
+ property = customName;
87
+ }
82
88
  const constEnumValue = (0, enum_1.tryGetConstEnumValue)(context, node);
83
89
  if (constEnumValue) {
84
90
  return { expression: constEnumValue };
@@ -130,9 +136,12 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
130
136
  };
131
137
  }
132
138
  if (node.expression.kind === typescript_2.SyntaxKind.SuperKeyword) {
133
- return {
134
- expression: (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorGet, node, lua.createIdentifier("self"), table, lua.createStringLiteral(property)),
135
- };
139
+ const symbol = context.checker.getSymbolAtLocation(node);
140
+ if (symbol && symbol.flags & ts.SymbolFlags.GetAccessor) {
141
+ return {
142
+ expression: (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorGet, node, lua.createIdentifier("self"), table, lua.createStringLiteral(property)),
143
+ };
144
+ }
136
145
  }
137
146
  return { expression: lua.createTableIndexExpression(table, lua.createStringLiteral(property), node) };
138
147
  }
@@ -57,11 +57,14 @@ lhs, right, rightHasPrecedingStatements, parent) {
57
57
  }
58
58
  if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
59
59
  if (lhs.expression.kind === typescript_1.SyntaxKind.SuperKeyword) {
60
- return [
61
- lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorSet, parent, lua.createIdentifier("self"), context.transformExpression(lhs.expression), ts.isPropertyAccessExpression(lhs)
62
- ? lua.createStringLiteral(lhs.name.text)
63
- : context.transformExpression(lhs.argumentExpression), right)),
64
- ];
60
+ const symbol = context.checker.getSymbolAtLocation(lhs);
61
+ if (symbol && symbol.flags & ts.SymbolFlags.SetAccessor) {
62
+ return [
63
+ lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorSet, parent, lua.createIdentifier("self"), context.transformExpression(lhs.expression), ts.isPropertyAccessExpression(lhs)
64
+ ? lua.createStringLiteral(lhs.name.text)
65
+ : context.transformExpression(lhs.argumentExpression), right)),
66
+ ];
67
+ }
65
68
  }
66
69
  }
67
70
  const symbol = lhs.parent && ts.isShorthandPropertyAssignment(lhs.parent)
@@ -145,7 +145,8 @@ function getSourceDir(program) {
145
145
  if (rootDir && rootDir.length > 0) {
146
146
  return path.isAbsolute(rootDir) ? rootDir : path.resolve(getProjectRoot(program), rootDir);
147
147
  }
148
- return program.getCommonSourceDirectory();
148
+ // If no rootDir is given, source is relative to the project root
149
+ return getProjectRoot(program);
149
150
  }
150
151
  exports.getSourceDir = getSourceDir;
151
152
  function getEmitOutDir(program) {
package/dist/utils.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as ts from "typescript";
2
2
  export declare function castArray<T>(value: T | T[]): T[];
3
3
  export declare function castArray<T>(value: T | readonly T[]): readonly T[];
4
4
  export declare const intersperse: <T>(values: readonly T[], separator: T) => T[];
5
- export declare const union: <T>(...values: Iterable<T>[]) => T[];
6
- export declare const intersection: <T>(first: readonly T[], ...rest: (readonly T[])[]) => T[];
5
+ export declare const union: <T>(...values: Array<Iterable<T>>) => T[];
6
+ export declare const intersection: <T>(first: readonly T[], ...rest: Array<readonly T[]>) => T[];
7
7
  type DiagnosticFactory = (...args: any) => Partial<ts.Diagnostic> & Pick<ts.Diagnostic, "messageText">;
8
8
  export declare const createDiagnosticFactoryWithCode: <T extends DiagnosticFactory>(code: number, create: T) => ((...args: Parameters<T>) => ts.Diagnostic) & {
9
9
  code: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.24.0",
3
+ "version": "1.25.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/",
@@ -42,7 +42,7 @@
42
42
  "node": ">=16.10.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "typescript": "5.3.3"
45
+ "typescript": "5.4.2"
46
46
  },
47
47
  "dependencies": {
48
48
  "@typescript-to-lua/language-extensions": "1.19.0",
@@ -72,6 +72,6 @@
72
72
  "prettier": "^2.8.4",
73
73
  "ts-jest": "^29.1.0",
74
74
  "ts-node": "^10.9.1",
75
- "typescript": "^5.3.3"
75
+ "typescript": "^5.4.2"
76
76
  }
77
77
  }