typescript-to-lua 1.18.0 → 1.19.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
@@ -29,6 +29,10 @@ export declare enum LuaLibFeature {
29
29
  ArrayFlat = "ArrayFlat",
30
30
  ArrayFlatMap = "ArrayFlatMap",
31
31
  ArraySetLength = "ArraySetLength",
32
+ ArrayToReversed = "ArrayToReversed",
33
+ ArrayToSorted = "ArrayToSorted",
34
+ ArrayToSpliced = "ArrayToSpliced",
35
+ ArrayWith = "ArrayWith",
32
36
  Await = "Await",
33
37
  Class = "Class",
34
38
  ClassExtends = "ClassExtends",
@@ -102,7 +106,9 @@ export declare enum LuaLibFeature {
102
106
  Symbol = "Symbol",
103
107
  SymbolRegistry = "SymbolRegistry",
104
108
  TypeOf = "TypeOf",
105
- Unpack = "Unpack"
109
+ Unpack = "Unpack",
110
+ Using = "Using",
111
+ UsingAsync = "UsingAsync"
106
112
  }
107
113
  export interface LuaLibFeatureInfo {
108
114
  dependencies?: LuaLibFeature[];
package/dist/LuaLib.js CHANGED
@@ -34,6 +34,10 @@ var LuaLibFeature;
34
34
  LuaLibFeature["ArrayFlat"] = "ArrayFlat";
35
35
  LuaLibFeature["ArrayFlatMap"] = "ArrayFlatMap";
36
36
  LuaLibFeature["ArraySetLength"] = "ArraySetLength";
37
+ LuaLibFeature["ArrayToReversed"] = "ArrayToReversed";
38
+ LuaLibFeature["ArrayToSorted"] = "ArrayToSorted";
39
+ LuaLibFeature["ArrayToSpliced"] = "ArrayToSpliced";
40
+ LuaLibFeature["ArrayWith"] = "ArrayWith";
37
41
  LuaLibFeature["Await"] = "Await";
38
42
  LuaLibFeature["Class"] = "Class";
39
43
  LuaLibFeature["ClassExtends"] = "ClassExtends";
@@ -108,6 +112,8 @@ var LuaLibFeature;
108
112
  LuaLibFeature["SymbolRegistry"] = "SymbolRegistry";
109
113
  LuaLibFeature["TypeOf"] = "TypeOf";
110
114
  LuaLibFeature["Unpack"] = "Unpack";
115
+ LuaLibFeature["Using"] = "Using";
116
+ LuaLibFeature["UsingAsync"] = "UsingAsync";
111
117
  })(LuaLibFeature || (exports.LuaLibFeature = LuaLibFeature = {}));
112
118
  function resolveLuaLibDir(luaTarget) {
113
119
  const luaLibDir = luaTarget === CompilerOptions_1.LuaTarget.Lua50 ? "5.0" : "universal";
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayToReversed(self)
2
+ local copy = {unpack(self)}
3
+ __TS__ArrayReverse(copy)
4
+ return copy
5
+ end
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayToSorted(self, compareFn)
2
+ local copy = {unpack(self)}
3
+ __TS__ArraySort(copy, compareFn)
4
+ return copy
5
+ end
@@ -0,0 +1,10 @@
1
+ local function __TS__ArrayToSpliced(self, start, deleteCount, ...)
2
+ local copy = {unpack(self)}
3
+ __TS__ArraySplice(
4
+ copy,
5
+ start,
6
+ deleteCount,
7
+ unpack(arg)
8
+ )
9
+ return copy
10
+ end
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayWith(self, index, value)
2
+ local copy = {unpack(self)}
3
+ copy[index + 1] = value
4
+ return copy
5
+ end
@@ -7,6 +7,8 @@ do
7
7
  return setmetatable({description = description}, symbolMetatable)
8
8
  end
9
9
  Symbol = {
10
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
11
+ dispose = __TS__Symbol("Symbol.dispose"),
10
12
  iterator = __TS__Symbol("Symbol.iterator"),
11
13
  hasInstance = __TS__Symbol("Symbol.hasInstance"),
12
14
  species = __TS__Symbol("Symbol.species"),
@@ -0,0 +1,27 @@
1
+ local function __TS__Using(self, cb, ...)
2
+ local args = arg
3
+ local thrownError
4
+ local ok, result = xpcall(
5
+ function() return cb(
6
+ nil,
7
+ unpack(args)
8
+ ) end,
9
+ function(err)
10
+ thrownError = err
11
+ return thrownError
12
+ end
13
+ )
14
+ local argArray = {unpack(args)}
15
+ do
16
+ local i = table.getn(argArray) - 1
17
+ while i >= 0 do
18
+ local ____self_0 = argArray[i + 1]
19
+ ____self_0[Symbol.dispose](____self_0)
20
+ i = i - 1
21
+ end
22
+ end
23
+ if not ok then
24
+ error(thrownError, 0)
25
+ end
26
+ return result
27
+ end
@@ -0,0 +1,35 @@
1
+ local function __TS__UsingAsync(self, cb, ...)
2
+ local args = arg
3
+ return __TS__AsyncAwaiter(function(____awaiter_resolve)
4
+ local thrownError
5
+ local ok, result = xpcall(
6
+ function() return cb(
7
+ nil,
8
+ unpack(args)
9
+ ) end,
10
+ function(err)
11
+ thrownError = err
12
+ return thrownError
13
+ end
14
+ )
15
+ local argArray = {unpack(args)}
16
+ do
17
+ local i = table.getn(argArray) - 1
18
+ while i >= 0 do
19
+ if argArray[i + 1][Symbol.dispose] ~= nil then
20
+ local ____self_0 = argArray[i + 1]
21
+ ____self_0[Symbol.dispose](____self_0)
22
+ end
23
+ if argArray[i + 1][Symbol.asyncDispose] ~= nil then
24
+ local ____self_1 = argArray[i + 1]
25
+ __TS__Await(____self_1[Symbol.asyncDispose](____self_1))
26
+ end
27
+ i = i - 1
28
+ end
29
+ end
30
+ if not ok then
31
+ error(thrownError, 0)
32
+ end
33
+ return ____awaiter_resolve(nil, result)
34
+ end)
35
+ end
@@ -34,6 +34,8 @@ do
34
34
  return setmetatable({description = description}, symbolMetatable)
35
35
  end
36
36
  Symbol = {
37
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
38
+ dispose = __TS__Symbol("Symbol.dispose"),
37
39
  iterator = __TS__Symbol("Symbol.iterator"),
38
40
  hasInstance = __TS__Symbol("Symbol.hasInstance"),
39
41
  species = __TS__Symbol("Symbol.species"),
@@ -534,6 +536,35 @@ local function __TS__ArraySetLength(self, length)
534
536
  return length
535
537
  end
536
538
 
539
+ local function __TS__ArrayToReversed(self)
540
+ local copy = {unpack(self)}
541
+ __TS__ArrayReverse(copy)
542
+ return copy
543
+ end
544
+
545
+ local function __TS__ArrayToSorted(self, compareFn)
546
+ local copy = {unpack(self)}
547
+ __TS__ArraySort(copy, compareFn)
548
+ return copy
549
+ end
550
+
551
+ local function __TS__ArrayToSpliced(self, start, deleteCount, ...)
552
+ local copy = {unpack(self)}
553
+ __TS__ArraySplice(
554
+ copy,
555
+ start,
556
+ deleteCount,
557
+ unpack(arg)
558
+ )
559
+ return copy
560
+ end
561
+
562
+ local function __TS__ArrayWith(self, index, value)
563
+ local copy = {unpack(self)}
564
+ copy[index + 1] = value
565
+ return copy
566
+ end
567
+
537
568
  local function __TS__InstanceOf(obj, classTbl)
538
569
  if type(classTbl) ~= "table" then
539
570
  error("Right-hand side of 'instanceof' is not an object", 0)
@@ -2437,6 +2468,70 @@ local function __TS__TypeOf(value)
2437
2468
  end
2438
2469
  end
2439
2470
 
2471
+ local function __TS__Using(self, cb, ...)
2472
+ local args = arg
2473
+ local thrownError
2474
+ local ok, result = xpcall(
2475
+ function() return cb(
2476
+ nil,
2477
+ unpack(args)
2478
+ ) end,
2479
+ function(err)
2480
+ thrownError = err
2481
+ return thrownError
2482
+ end
2483
+ )
2484
+ local argArray = {unpack(args)}
2485
+ do
2486
+ local i = table.getn(argArray) - 1
2487
+ while i >= 0 do
2488
+ local ____self_0 = argArray[i + 1]
2489
+ ____self_0[Symbol.dispose](____self_0)
2490
+ i = i - 1
2491
+ end
2492
+ end
2493
+ if not ok then
2494
+ error(thrownError, 0)
2495
+ end
2496
+ return result
2497
+ end
2498
+
2499
+ local function __TS__UsingAsync(self, cb, ...)
2500
+ local args = arg
2501
+ return __TS__AsyncAwaiter(function(____awaiter_resolve)
2502
+ local thrownError
2503
+ local ok, result = xpcall(
2504
+ function() return cb(
2505
+ nil,
2506
+ unpack(args)
2507
+ ) end,
2508
+ function(err)
2509
+ thrownError = err
2510
+ return thrownError
2511
+ end
2512
+ )
2513
+ local argArray = {unpack(args)}
2514
+ do
2515
+ local i = table.getn(argArray) - 1
2516
+ while i >= 0 do
2517
+ if argArray[i + 1][Symbol.dispose] ~= nil then
2518
+ local ____self_0 = argArray[i + 1]
2519
+ ____self_0[Symbol.dispose](____self_0)
2520
+ end
2521
+ if argArray[i + 1][Symbol.asyncDispose] ~= nil then
2522
+ local ____self_1 = argArray[i + 1]
2523
+ __TS__Await(____self_1[Symbol.asyncDispose](____self_1))
2524
+ end
2525
+ i = i - 1
2526
+ end
2527
+ end
2528
+ if not ok then
2529
+ error(thrownError, 0)
2530
+ end
2531
+ return ____awaiter_resolve(nil, result)
2532
+ end)
2533
+ end
2534
+
2440
2535
  return {
2441
2536
  __TS__ArrayConcat = __TS__ArrayConcat,
2442
2537
  __TS__ArrayEntries = __TS__ArrayEntries,
@@ -2465,6 +2560,10 @@ return {
2465
2560
  __TS__ArrayFlat = __TS__ArrayFlat,
2466
2561
  __TS__ArrayFlatMap = __TS__ArrayFlatMap,
2467
2562
  __TS__ArraySetLength = __TS__ArraySetLength,
2563
+ __TS__ArrayToReversed = __TS__ArrayToReversed,
2564
+ __TS__ArrayToSorted = __TS__ArrayToSorted,
2565
+ __TS__ArrayToSpliced = __TS__ArrayToSpliced,
2566
+ __TS__ArrayWith = __TS__ArrayWith,
2468
2567
  __TS__AsyncAwaiter = __TS__AsyncAwaiter,
2469
2568
  __TS__Await = __TS__Await,
2470
2569
  __TS__Class = __TS__Class,
@@ -2546,5 +2645,7 @@ return {
2546
2645
  __TS__SymbolRegistryFor = __TS__SymbolRegistryFor,
2547
2646
  __TS__SymbolRegistryKeyFor = __TS__SymbolRegistryKeyFor,
2548
2647
  __TS__TypeOf = __TS__TypeOf,
2549
- __TS__Unpack = __TS__Unpack
2648
+ __TS__Unpack = __TS__Unpack,
2649
+ __TS__Using = __TS__Using,
2650
+ __TS__UsingAsync = __TS__UsingAsync
2550
2651
  }
@@ -159,6 +159,35 @@
159
159
  "__TS__ArraySetLength"
160
160
  ]
161
161
  },
162
+ "ArrayToReversed": {
163
+ "exports": [
164
+ "__TS__ArrayToReversed"
165
+ ],
166
+ "dependencies": [
167
+ "ArrayReverse"
168
+ ]
169
+ },
170
+ "ArrayToSorted": {
171
+ "exports": [
172
+ "__TS__ArrayToSorted"
173
+ ],
174
+ "dependencies": [
175
+ "ArraySort"
176
+ ]
177
+ },
178
+ "ArrayToSpliced": {
179
+ "exports": [
180
+ "__TS__ArrayToSpliced"
181
+ ],
182
+ "dependencies": [
183
+ "ArraySplice"
184
+ ]
185
+ },
186
+ "ArrayWith": {
187
+ "exports": [
188
+ "__TS__ArrayWith"
189
+ ]
190
+ },
162
191
  "Await": {
163
192
  "exports": [
164
193
  "__TS__AsyncAwaiter",
@@ -676,5 +705,22 @@
676
705
  "exports": [
677
706
  "__TS__Unpack"
678
707
  ]
708
+ },
709
+ "Using": {
710
+ "exports": [
711
+ "__TS__Using"
712
+ ],
713
+ "dependencies": [
714
+ "Symbol"
715
+ ]
716
+ },
717
+ "UsingAsync": {
718
+ "exports": [
719
+ "__TS__UsingAsync"
720
+ ],
721
+ "dependencies": [
722
+ "Symbol",
723
+ "Await"
724
+ ]
679
725
  }
680
726
  }
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayToReversed(self)
2
+ local copy = {__TS__Unpack(self)}
3
+ __TS__ArrayReverse(copy)
4
+ return copy
5
+ end
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayToSorted(self, compareFn)
2
+ local copy = {__TS__Unpack(self)}
3
+ __TS__ArraySort(copy, compareFn)
4
+ return copy
5
+ end
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayToSpliced(self, start, deleteCount, ...)
2
+ local copy = {__TS__Unpack(self)}
3
+ __TS__ArraySplice(copy, start, deleteCount, ...)
4
+ return copy
5
+ end
@@ -0,0 +1,5 @@
1
+ local function __TS__ArrayWith(self, index, value)
2
+ local copy = {__TS__Unpack(self)}
3
+ copy[index + 1] = value
4
+ return copy
5
+ end
@@ -7,6 +7,8 @@ do
7
7
  return setmetatable({description = description}, symbolMetatable)
8
8
  end
9
9
  Symbol = {
10
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
11
+ dispose = __TS__Symbol("Symbol.dispose"),
10
12
  iterator = __TS__Symbol("Symbol.iterator"),
11
13
  hasInstance = __TS__Symbol("Symbol.hasInstance"),
12
14
  species = __TS__Symbol("Symbol.species"),
@@ -0,0 +1,27 @@
1
+ local function __TS__Using(self, cb, ...)
2
+ local args = {...}
3
+ local thrownError
4
+ local ok, result = xpcall(
5
+ function() return cb(
6
+ nil,
7
+ __TS__Unpack(args)
8
+ ) end,
9
+ function(err)
10
+ thrownError = err
11
+ return thrownError
12
+ end
13
+ )
14
+ local argArray = {__TS__Unpack(args)}
15
+ do
16
+ local i = #argArray - 1
17
+ while i >= 0 do
18
+ local ____self_0 = argArray[i + 1]
19
+ ____self_0[Symbol.dispose](____self_0)
20
+ i = i - 1
21
+ end
22
+ end
23
+ if not ok then
24
+ error(thrownError, 0)
25
+ end
26
+ return result
27
+ end
@@ -0,0 +1,35 @@
1
+ local function __TS__UsingAsync(self, cb, ...)
2
+ local args = {...}
3
+ return __TS__AsyncAwaiter(function(____awaiter_resolve)
4
+ local thrownError
5
+ local ok, result = xpcall(
6
+ function() return cb(
7
+ nil,
8
+ __TS__Unpack(args)
9
+ ) end,
10
+ function(err)
11
+ thrownError = err
12
+ return thrownError
13
+ end
14
+ )
15
+ local argArray = {__TS__Unpack(args)}
16
+ do
17
+ local i = #argArray - 1
18
+ while i >= 0 do
19
+ if argArray[i + 1][Symbol.dispose] ~= nil then
20
+ local ____self_0 = argArray[i + 1]
21
+ ____self_0[Symbol.dispose](____self_0)
22
+ end
23
+ if argArray[i + 1][Symbol.asyncDispose] ~= nil then
24
+ local ____self_1 = argArray[i + 1]
25
+ __TS__Await(____self_1[Symbol.asyncDispose](____self_1))
26
+ end
27
+ i = i - 1
28
+ end
29
+ end
30
+ if not ok then
31
+ error(thrownError, 0)
32
+ end
33
+ return ____awaiter_resolve(nil, result)
34
+ end)
35
+ end
@@ -34,6 +34,8 @@ do
34
34
  return setmetatable({description = description}, symbolMetatable)
35
35
  end
36
36
  Symbol = {
37
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
38
+ dispose = __TS__Symbol("Symbol.dispose"),
37
39
  iterator = __TS__Symbol("Symbol.iterator"),
38
40
  hasInstance = __TS__Symbol("Symbol.hasInstance"),
39
41
  species = __TS__Symbol("Symbol.species"),
@@ -533,6 +535,32 @@ local function __TS__ArraySetLength(self, length)
533
535
  return length
534
536
  end
535
537
 
538
+ local __TS__Unpack = table.unpack or unpack
539
+
540
+ local function __TS__ArrayToReversed(self)
541
+ local copy = {__TS__Unpack(self)}
542
+ __TS__ArrayReverse(copy)
543
+ return copy
544
+ end
545
+
546
+ local function __TS__ArrayToSorted(self, compareFn)
547
+ local copy = {__TS__Unpack(self)}
548
+ __TS__ArraySort(copy, compareFn)
549
+ return copy
550
+ end
551
+
552
+ local function __TS__ArrayToSpliced(self, start, deleteCount, ...)
553
+ local copy = {__TS__Unpack(self)}
554
+ __TS__ArraySplice(copy, start, deleteCount, ...)
555
+ return copy
556
+ end
557
+
558
+ local function __TS__ArrayWith(self, index, value)
559
+ local copy = {__TS__Unpack(self)}
560
+ copy[index + 1] = value
561
+ return copy
562
+ end
563
+
536
564
  local function __TS__InstanceOf(obj, classTbl)
537
565
  if type(classTbl) ~= "table" then
538
566
  error("Right-hand side of 'instanceof' is not an object", 0)
@@ -565,8 +593,6 @@ local function __TS__Class(self)
565
593
  return c
566
594
  end
567
595
 
568
- local __TS__Unpack = table.unpack or unpack
569
-
570
596
  local function __TS__FunctionBind(fn, ...)
571
597
  local boundArgs = {...}
572
598
  return function(____, ...)
@@ -2382,6 +2408,70 @@ local function __TS__TypeOf(value)
2382
2408
  end
2383
2409
  end
2384
2410
 
2411
+ local function __TS__Using(self, cb, ...)
2412
+ local args = {...}
2413
+ local thrownError
2414
+ local ok, result = xpcall(
2415
+ function() return cb(
2416
+ nil,
2417
+ __TS__Unpack(args)
2418
+ ) end,
2419
+ function(err)
2420
+ thrownError = err
2421
+ return thrownError
2422
+ end
2423
+ )
2424
+ local argArray = {__TS__Unpack(args)}
2425
+ do
2426
+ local i = #argArray - 1
2427
+ while i >= 0 do
2428
+ local ____self_0 = argArray[i + 1]
2429
+ ____self_0[Symbol.dispose](____self_0)
2430
+ i = i - 1
2431
+ end
2432
+ end
2433
+ if not ok then
2434
+ error(thrownError, 0)
2435
+ end
2436
+ return result
2437
+ end
2438
+
2439
+ local function __TS__UsingAsync(self, cb, ...)
2440
+ local args = {...}
2441
+ return __TS__AsyncAwaiter(function(____awaiter_resolve)
2442
+ local thrownError
2443
+ local ok, result = xpcall(
2444
+ function() return cb(
2445
+ nil,
2446
+ __TS__Unpack(args)
2447
+ ) end,
2448
+ function(err)
2449
+ thrownError = err
2450
+ return thrownError
2451
+ end
2452
+ )
2453
+ local argArray = {__TS__Unpack(args)}
2454
+ do
2455
+ local i = #argArray - 1
2456
+ while i >= 0 do
2457
+ if argArray[i + 1][Symbol.dispose] ~= nil then
2458
+ local ____self_0 = argArray[i + 1]
2459
+ ____self_0[Symbol.dispose](____self_0)
2460
+ end
2461
+ if argArray[i + 1][Symbol.asyncDispose] ~= nil then
2462
+ local ____self_1 = argArray[i + 1]
2463
+ __TS__Await(____self_1[Symbol.asyncDispose](____self_1))
2464
+ end
2465
+ i = i - 1
2466
+ end
2467
+ end
2468
+ if not ok then
2469
+ error(thrownError, 0)
2470
+ end
2471
+ return ____awaiter_resolve(nil, result)
2472
+ end)
2473
+ end
2474
+
2385
2475
  return {
2386
2476
  __TS__ArrayConcat = __TS__ArrayConcat,
2387
2477
  __TS__ArrayEntries = __TS__ArrayEntries,
@@ -2410,6 +2500,10 @@ return {
2410
2500
  __TS__ArrayFlat = __TS__ArrayFlat,
2411
2501
  __TS__ArrayFlatMap = __TS__ArrayFlatMap,
2412
2502
  __TS__ArraySetLength = __TS__ArraySetLength,
2503
+ __TS__ArrayToReversed = __TS__ArrayToReversed,
2504
+ __TS__ArrayToSorted = __TS__ArrayToSorted,
2505
+ __TS__ArrayToSpliced = __TS__ArrayToSpliced,
2506
+ __TS__ArrayWith = __TS__ArrayWith,
2413
2507
  __TS__AsyncAwaiter = __TS__AsyncAwaiter,
2414
2508
  __TS__Await = __TS__Await,
2415
2509
  __TS__Class = __TS__Class,
@@ -2491,5 +2585,7 @@ return {
2491
2585
  __TS__SymbolRegistryFor = __TS__SymbolRegistryFor,
2492
2586
  __TS__SymbolRegistryKeyFor = __TS__SymbolRegistryKeyFor,
2493
2587
  __TS__TypeOf = __TS__TypeOf,
2494
- __TS__Unpack = __TS__Unpack
2588
+ __TS__Unpack = __TS__Unpack,
2589
+ __TS__Using = __TS__Using,
2590
+ __TS__UsingAsync = __TS__UsingAsync
2495
2591
  }
@@ -159,6 +159,41 @@
159
159
  "__TS__ArraySetLength"
160
160
  ]
161
161
  },
162
+ "ArrayToReversed": {
163
+ "exports": [
164
+ "__TS__ArrayToReversed"
165
+ ],
166
+ "dependencies": [
167
+ "Unpack",
168
+ "ArrayReverse"
169
+ ]
170
+ },
171
+ "ArrayToSorted": {
172
+ "exports": [
173
+ "__TS__ArrayToSorted"
174
+ ],
175
+ "dependencies": [
176
+ "Unpack",
177
+ "ArraySort"
178
+ ]
179
+ },
180
+ "ArrayToSpliced": {
181
+ "exports": [
182
+ "__TS__ArrayToSpliced"
183
+ ],
184
+ "dependencies": [
185
+ "Unpack",
186
+ "ArraySplice"
187
+ ]
188
+ },
189
+ "ArrayWith": {
190
+ "exports": [
191
+ "__TS__ArrayWith"
192
+ ],
193
+ "dependencies": [
194
+ "Unpack"
195
+ ]
196
+ },
162
197
  "Await": {
163
198
  "exports": [
164
199
  "__TS__AsyncAwaiter",
@@ -674,5 +709,24 @@
674
709
  "exports": [
675
710
  "__TS__Unpack"
676
711
  ]
712
+ },
713
+ "Using": {
714
+ "exports": [
715
+ "__TS__Using"
716
+ ],
717
+ "dependencies": [
718
+ "Unpack",
719
+ "Symbol"
720
+ ]
721
+ },
722
+ "UsingAsync": {
723
+ "exports": [
724
+ "__TS__UsingAsync"
725
+ ],
726
+ "dependencies": [
727
+ "Unpack",
728
+ "Symbol",
729
+ "Await"
730
+ ]
677
731
  }
678
732
  }
@@ -133,6 +133,14 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
133
133
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayFlat, node, caller, ...params);
134
134
  case "flatMap":
135
135
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayFlatMap, node, caller, ...params);
136
+ case "toReversed":
137
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayToReversed, node, caller, ...params);
138
+ case "toSorted":
139
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayToSorted, node, caller, ...params);
140
+ case "toSpliced":
141
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayToSpliced, node, caller, ...params);
142
+ case "with":
143
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayWith, node, caller, ...params);
136
144
  default:
137
145
  context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "array", expressionName));
138
146
  }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformSourceFile = exports.createVisitorMap = void 0;
4
+ const ts = require("typescript");
4
5
  const utils_1 = require("../utils");
5
6
  const context_1 = require("./context");
6
7
  const visitors_1 = require("./visitors");
8
+ const using_transformer_1 = require("./pre-transformers/using-transformer");
7
9
  function createVisitorMap(customVisitors) {
8
10
  const objectVisitorMap = new Map();
9
11
  for (const visitors of [visitors_1.standardVisitors, ...customVisitors]) {
@@ -26,7 +28,11 @@ function createVisitorMap(customVisitors) {
26
28
  exports.createVisitorMap = createVisitorMap;
27
29
  function transformSourceFile(program, sourceFile, visitorMap) {
28
30
  const context = new context_1.TransformationContext(program, sourceFile, visitorMap);
29
- const [file] = context.transformNode(sourceFile);
31
+ // TS -> TS pre-transformation
32
+ const preTransformers = [(0, using_transformer_1.usingTransformer)(context)];
33
+ const result = ts.transform(sourceFile, preTransformers);
34
+ // TS -> Lua transformation
35
+ const [file] = context.transformNode(result.transformed[0]);
30
36
  return { file, diagnostics: context.diagnostics };
31
37
  }
32
38
  exports.transformSourceFile = transformSourceFile;
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ import { TransformationContext } from "../context";
3
+ export declare function usingTransformer(context: TransformationContext): ts.TransformerFactory<ts.SourceFile>;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usingTransformer = void 0;
4
+ const ts = require("typescript");
5
+ const lualib_1 = require("../utils/lualib");
6
+ function usingTransformer(context) {
7
+ return ctx => sourceFile => {
8
+ function visit(node) {
9
+ if (ts.isBlock(node)) {
10
+ const [hasUsings, newStatements] = transformBlockWithUsing(context, node.statements, node);
11
+ if (hasUsings) {
12
+ // Recurse visitor into updated block to find further usings
13
+ const updatedBlock = ts.factory.updateBlock(node, newStatements);
14
+ const result = ts.visitEachChild(updatedBlock, visit, ctx);
15
+ // Set all the synthetic node parents to something that makes sense
16
+ const parent = [updatedBlock];
17
+ function setParent(node2) {
18
+ ts.setParent(node2, parent[parent.length - 1]);
19
+ parent.push(node2);
20
+ ts.visitEachChild(node2, setParent, ctx);
21
+ parent.push();
22
+ return node2;
23
+ }
24
+ ts.visitEachChild(updatedBlock, setParent, ctx);
25
+ ts.setParent(updatedBlock, node.parent);
26
+ return result;
27
+ }
28
+ }
29
+ return ts.visitEachChild(node, visit, ctx);
30
+ }
31
+ return ts.visitEachChild(sourceFile, visit, ctx);
32
+ };
33
+ }
34
+ exports.usingTransformer = usingTransformer;
35
+ function isUsingDeclarationList(node) {
36
+ return ts.isVariableStatement(node) && (node.declarationList.flags & ts.NodeFlags.Using) !== 0;
37
+ }
38
+ function transformBlockWithUsing(context, statements, block) {
39
+ const newStatements = [];
40
+ for (let i = 0; i < statements.length; i++) {
41
+ const statement = statements[i];
42
+ if (isUsingDeclarationList(statement)) {
43
+ const isAwaitUsing = (statement.declarationList.flags & ts.NodeFlags.AwaitContext) !== 0;
44
+ if (isAwaitUsing) {
45
+ (0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.UsingAsync);
46
+ }
47
+ else {
48
+ (0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Using);
49
+ }
50
+ // Make declared using variables callback function parameters
51
+ const variableNames = statement.declarationList.declarations.map(d => ts.factory.createParameterDeclaration(undefined, undefined, d.name));
52
+ // Add this: void as first parameter
53
+ variableNames.unshift(createThisVoidParameter(context.checker));
54
+ // Put all following statements in the callback body
55
+ const followingStatements = statements.slice(i + 1);
56
+ const [followingHasUsings, replacedFollowingStatements] = transformBlockWithUsing(context, followingStatements, block);
57
+ const callbackBody = ts.factory.createBlock(followingHasUsings ? replacedFollowingStatements : followingStatements);
58
+ const callback = ts.factory.createFunctionExpression(undefined, undefined, undefined, undefined, variableNames, undefined, callbackBody);
59
+ // Replace using variable list with call to lualib function with callback and followed by all variable initializers
60
+ const functionIdentifier = ts.factory.createIdentifier(isAwaitUsing ? "__TS__UsingAsync" : "__TS__Using");
61
+ let call = ts.factory.createCallExpression(functionIdentifier, [], [
62
+ callback,
63
+ ...statement.declarationList.declarations.map(d => { var _a; return (_a = d.initializer) !== null && _a !== void 0 ? _a : ts.factory.createIdentifier("unidentified"); }),
64
+ ]);
65
+ // If this is an 'await using ...', add an await statement here
66
+ if (isAwaitUsing) {
67
+ call = ts.factory.createAwaitExpression(call);
68
+ }
69
+ if (ts.isBlock(block.parent) && block.parent.statements[block.parent.statements.length - 1] !== block) {
70
+ // If this is a free-standing block in a function (not the last statement), dont return the value
71
+ newStatements.push(ts.factory.createExpressionStatement(call));
72
+ }
73
+ else {
74
+ newStatements.push(ts.factory.createReturnStatement(call));
75
+ }
76
+ return [true, newStatements];
77
+ }
78
+ else {
79
+ newStatements.push(statement);
80
+ }
81
+ }
82
+ return [false];
83
+ }
84
+ function createThisVoidParameter(checker) {
85
+ const voidType = checker.typeToTypeNode(checker.getVoidType(), undefined, undefined);
86
+ return ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier("this"), undefined, voidType);
87
+ }
88
+ //# sourceMappingURL=using-transformer.js.map
@@ -161,10 +161,16 @@ function transformParameters(context, parameters, functionContext) {
161
161
  }
162
162
  exports.transformParameters = transformParameters;
163
163
  function transformFunctionToExpression(context, node) {
164
+ var _a;
164
165
  (0, utils_1.assert)(node.body);
165
166
  const type = context.checker.getTypeAtLocation(node);
166
167
  let functionContext;
167
- if ((0, function_context_1.getFunctionContextType)(context, type) !== function_context_1.ContextType.Void) {
168
+ const firstParam = node.parameters[0];
169
+ const hasThisVoidParameter = firstParam &&
170
+ ts.isIdentifier(firstParam.name) &&
171
+ ts.identifierToKeywordKind(firstParam.name) === ts.SyntaxKind.ThisKeyword &&
172
+ ((_a = firstParam.type) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.VoidKeyword;
173
+ if (!hasThisVoidParameter && (0, function_context_1.getFunctionContextType)(context, type) !== function_context_1.ContextType.Void) {
168
174
  if (ts.isArrowFunction(node)) {
169
175
  // dummy context for arrow functions with parameters
170
176
  if (node.parameters.length > 0) {
@@ -206,8 +206,8 @@ function transformVariableDeclaration(context, statement) {
206
206
  }
207
207
  exports.transformVariableDeclaration = transformVariableDeclaration;
208
208
  function checkVariableDeclarationList(context, node) {
209
- if ((node.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) === 0) {
210
- const token = node.getFirstToken();
209
+ if ((node.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const | ts.NodeFlags.Using | ts.NodeFlags.AwaitUsing)) === 0) {
210
+ const token = ts.getOriginalNode(node).getFirstToken();
211
211
  (0, utils_1.assert)(token);
212
212
  context.diagnostics.push((0, diagnostics_1.unsupportedVarDeclaration)(token));
213
213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.18.0",
3
+ "version": "1.19.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/",