typescript-to-lua 1.6.2 → 1.7.1

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.
Files changed (101) hide show
  1. package/dist/CompilerOptions.d.ts +1 -0
  2. package/dist/cli/diagnostics.d.ts +3 -0
  3. package/dist/cli/diagnostics.js +2 -1
  4. package/dist/cli/parse.d.ts +1 -1
  5. package/dist/cli/parse.js +47 -11
  6. package/dist/lualib/ArraySlice.lua +10 -2
  7. package/dist/lualib/ArraySplice.lua +5 -1
  8. package/dist/lualib/Generator.lua +8 -1
  9. package/dist/lualib/ParseFloat.lua +5 -1
  10. package/dist/lualib/SparseArraySpread.lua +5 -1
  11. package/dist/lualib/StringCharCodeAt.lua +5 -1
  12. package/dist/lualib/lualib_bundle.lua +38 -7
  13. package/dist/lualib-build/plugin.js +1 -2
  14. package/dist/measure-performance.d.ts +15 -0
  15. package/dist/measure-performance.js +83 -0
  16. package/dist/transformation/builtins/array.js +2 -1
  17. package/dist/transformation/builtins/function.js +1 -1
  18. package/dist/transformation/builtins/global.d.ts +1 -1
  19. package/dist/transformation/builtins/global.js +13 -12
  20. package/dist/transformation/builtins/index.d.ts +2 -2
  21. package/dist/transformation/builtins/index.js +87 -89
  22. package/dist/transformation/builtins/object.d.ts +1 -1
  23. package/dist/transformation/builtins/object.js +4 -4
  24. package/dist/transformation/builtins/promise.js +4 -2
  25. package/dist/transformation/builtins/string.js +2 -0
  26. package/dist/transformation/context/context.d.ts +15 -0
  27. package/dist/transformation/context/context.js +66 -24
  28. package/dist/transformation/context/visitors.d.ts +1 -1
  29. package/dist/transformation/index.js +6 -5
  30. package/dist/transformation/utils/annotations.d.ts +1 -17
  31. package/dist/transformation/utils/annotations.js +48 -88
  32. package/dist/transformation/utils/assignment-validation.js +27 -23
  33. package/dist/transformation/utils/diagnostics.d.ts +1 -4
  34. package/dist/transformation/utils/diagnostics.js +2 -3
  35. package/dist/transformation/utils/function-context.d.ts +1 -1
  36. package/dist/transformation/utils/function-context.js +57 -51
  37. package/dist/transformation/utils/language-extensions.d.ts +57 -51
  38. package/dist/transformation/utils/language-extensions.js +99 -119
  39. package/dist/transformation/utils/lualib.d.ts +0 -1
  40. package/dist/transformation/utils/lualib.js +2 -8
  41. package/dist/transformation/utils/safe-names.d.ts +1 -1
  42. package/dist/transformation/utils/safe-names.js +3 -6
  43. package/dist/transformation/utils/scope.d.ts +0 -2
  44. package/dist/transformation/utils/scope.js +10 -27
  45. package/dist/transformation/utils/symbols.d.ts +1 -1
  46. package/dist/transformation/utils/symbols.js +7 -20
  47. package/dist/transformation/utils/typescript/index.d.ts +1 -0
  48. package/dist/transformation/utils/typescript/index.js +2 -1
  49. package/dist/transformation/utils/typescript/types.d.ts +2 -5
  50. package/dist/transformation/utils/typescript/types.js +27 -37
  51. package/dist/transformation/visitors/access.js +1 -4
  52. package/dist/transformation/visitors/block.js +4 -4
  53. package/dist/transformation/visitors/call.js +7 -18
  54. package/dist/transformation/visitors/class/index.js +8 -20
  55. package/dist/transformation/visitors/class/members/constructor.js +2 -2
  56. package/dist/transformation/visitors/class/new.js +2 -5
  57. package/dist/transformation/visitors/class/setup.d.ts +1 -1
  58. package/dist/transformation/visitors/class/setup.js +4 -4
  59. package/dist/transformation/visitors/class/utils.d.ts +1 -1
  60. package/dist/transformation/visitors/class/utils.js +2 -9
  61. package/dist/transformation/visitors/conditional.js +4 -4
  62. package/dist/transformation/visitors/function.d.ts +1 -1
  63. package/dist/transformation/visitors/function.js +8 -16
  64. package/dist/transformation/visitors/identifier.d.ts +1 -0
  65. package/dist/transformation/visitors/identifier.js +40 -44
  66. package/dist/transformation/visitors/language-extensions/call-extension.d.ts +10 -0
  67. package/dist/transformation/visitors/language-extensions/call-extension.js +23 -0
  68. package/dist/transformation/visitors/language-extensions/identifier.d.ts +5 -0
  69. package/dist/transformation/visitors/language-extensions/identifier.js +27 -0
  70. package/dist/transformation/visitors/language-extensions/iterable.d.ts +2 -3
  71. package/dist/transformation/visitors/language-extensions/iterable.js +21 -22
  72. package/dist/transformation/visitors/language-extensions/multi.d.ts +0 -1
  73. package/dist/transformation/visitors/language-extensions/multi.js +10 -24
  74. package/dist/transformation/visitors/language-extensions/operators.d.ts +2 -5
  75. package/dist/transformation/visitors/language-extensions/operators.js +89 -96
  76. package/dist/transformation/visitors/language-extensions/range.js +4 -2
  77. package/dist/transformation/visitors/language-extensions/table.d.ts +6 -3
  78. package/dist/transformation/visitors/language-extensions/table.js +46 -75
  79. package/dist/transformation/visitors/language-extensions/vararg.js +7 -3
  80. package/dist/transformation/visitors/literal.js +2 -23
  81. package/dist/transformation/visitors/loops/for-of.js +18 -18
  82. package/dist/transformation/visitors/loops/utils.js +5 -5
  83. package/dist/transformation/visitors/namespace.js +5 -14
  84. package/dist/transformation/visitors/return.js +2 -3
  85. package/dist/transformation/visitors/sourceFile.js +3 -4
  86. package/dist/transformation/visitors/spread.js +0 -5
  87. package/dist/transformation/visitors/switch.js +2 -2
  88. package/dist/transformation/visitors/variable-declaration.js +1 -1
  89. package/dist/transpilation/index.js +4 -8
  90. package/dist/transpilation/plugins.js +3 -0
  91. package/dist/transpilation/resolve.js +144 -161
  92. package/dist/transpilation/transpile.js +10 -0
  93. package/dist/transpilation/transpiler.d.ts +1 -0
  94. package/dist/transpilation/transpiler.js +18 -5
  95. package/dist/tstl.js +23 -4
  96. package/language-extensions/index.d.ts +167 -67
  97. package/package.json +2 -2
  98. package/dist/transformation/visitors/language-extensions/index.d.ts +0 -4
  99. package/dist/transformation/visitors/language-extensions/index.js +0 -17
  100. package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +0 -5
  101. package/dist/transformation/visitors/language-extensions/pairsIterable.js +0 -53
@@ -3,12 +3,24 @@ type AnyTable = Record<any, any>;
3
3
  type AnyNotNil = {};
4
4
 
5
5
  /**
6
- * Indicates a type is a language extension provided by TypescriptToLua.
6
+ * Indicates a type is a language extension provided by TypescriptToLua when used as a value or function call.
7
7
  * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
8
8
  *
9
9
  * @param TBrand A string used to uniquely identify the language extension type
10
10
  */
11
- declare type LuaExtension<TBrand extends string> = { [T in TBrand]: { readonly __luaExtensionSymbol: unique symbol } };
11
+ declare interface LuaExtension<TBrand extends string> {
12
+ readonly __tstlExtension: TBrand;
13
+ }
14
+
15
+ /**
16
+ * Indicates a type is a language extension provided by TypescriptToLua when used in a for-of loop.
17
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
18
+ *
19
+ * @param TBrand A string used to uniquely identify the language extension type
20
+ */
21
+ declare interface LuaIterationExtension<TBrand extends string> {
22
+ readonly __tstlIterable: TBrand;
23
+ }
12
24
 
13
25
  /**
14
26
  * Returns multiple values from a function, by wrapping them in a LuaMultiReturn tuple.
@@ -17,7 +29,7 @@ declare type LuaExtension<TBrand extends string> = { [T in TBrand]: { readonly _
17
29
  * @param T A tuple type with each element type representing a return value's type.
18
30
  * @param values Return values.
19
31
  */
20
- declare const $multi: (<T extends any[]>(...values: T) => LuaMultiReturn<T>) & LuaExtension<"__luaMultiFunctionBrand">;
32
+ declare const $multi: (<T extends any[]>(...values: T) => LuaMultiReturn<T>) & LuaExtension<"MultiFunction">;
21
33
 
22
34
  /**
23
35
  * Represents multiple return values as a tuple.
@@ -25,7 +37,9 @@ declare const $multi: (<T extends any[]>(...values: T) => LuaMultiReturn<T>) & L
25
37
  *
26
38
  * @param T A tuple type with each element type representing a return value's type.
27
39
  */
28
- declare type LuaMultiReturn<T extends any[]> = T & LuaExtension<"__luaMultiReturnBrand">;
40
+ declare type LuaMultiReturn<T extends any[]> = T & {
41
+ readonly __tstlMultiReturn: any;
42
+ };
29
43
 
30
44
  /**
31
45
  * Creates a Lua-style numeric for loop (for i=start,limit,step) when used in for...of. Not valid in any other context.
@@ -36,13 +50,13 @@ declare type LuaMultiReturn<T extends any[]> = T & LuaExtension<"__luaMultiRetur
36
50
  * @param step The amount to increment each iteration.
37
51
  */
38
52
  declare const $range: ((start: number, limit: number, step?: number) => Iterable<number>) &
39
- LuaExtension<"__luaRangeFunctionBrand">;
53
+ LuaExtension<"RangeFunction">;
40
54
 
41
55
  /**
42
56
  * Transpiles to the global vararg (`...`)
43
57
  * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
44
58
  */
45
- declare const $vararg: string[] & LuaExtension<"__luaVarargConstantBrand">;
59
+ declare const $vararg: string[] & LuaExtension<"VarargConstant">;
46
60
 
47
61
  /**
48
62
  * Represents a Lua-style iterator which is returned from a LuaIterable.
@@ -76,7 +90,7 @@ declare type LuaIterator<TValue, TState> = TState extends undefined
76
90
  */
77
91
  declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
78
92
  LuaIterator<TValue, TState> &
79
- LuaExtension<"__luaIterableBrand">;
93
+ LuaIterationExtension<"Iterable">;
80
94
 
81
95
  /**
82
96
  * Represents an object that can be iterated with pairs()
@@ -86,7 +100,14 @@ declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
86
100
  * @param TValue The type of the value returned each iteration.
87
101
  */
88
102
  declare type LuaPairsIterable<TKey extends AnyNotNil, TValue> = Iterable<[TKey, TValue]> &
89
- LuaExtension<"__luaPairsIterableBrand">;
103
+ LuaIterationExtension<"Pairs">;
104
+
105
+ /**
106
+ * Represents an object that can be iterated with pairs(), where only the key value is used.
107
+ *
108
+ * @param TKey The type of the key returned each iteration.
109
+ */
110
+ declare type LuaPairsKeyIterable<TKey extends AnyNotNil> = Iterable<TKey> & LuaIterationExtension<"PairsKey">;
90
111
 
91
112
  /**
92
113
  * Calls to functions with this type are translated to `left + right`.
@@ -96,8 +117,7 @@ declare type LuaPairsIterable<TKey extends AnyNotNil, TValue> = Iterable<[TKey,
96
117
  * @param TRight The type of the right-hand-side of the operation.
97
118
  * @param TReturn The resulting (return) type of the operation.
98
119
  */
99
- declare type LuaAddition<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
100
- LuaExtension<"__luaAdditionBrand">;
120
+ declare type LuaAddition<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"Addition">;
101
121
 
102
122
  /**
103
123
  * Calls to methods with this type are translated to `left + right`, where `left` is the object with the method.
@@ -106,8 +126,7 @@ declare type LuaAddition<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight)
106
126
  * @param TRight The type of the right-hand-side of the operation.
107
127
  * @param TReturn The resulting (return) type of the operation.
108
128
  */
109
- declare type LuaAdditionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
110
- LuaExtension<"__luaAdditionMethodBrand">;
129
+ declare type LuaAdditionMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"AdditionMethod">;
111
130
 
112
131
  /**
113
132
  * Calls to functions with this type are translated to `left - right`.
@@ -118,7 +137,7 @@ declare type LuaAdditionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
118
137
  * @param TReturn The resulting (return) type of the operation.
119
138
  */
120
139
  declare type LuaSubtraction<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
121
- LuaExtension<"__luaSubtractionBrand">;
140
+ LuaExtension<"Subtraction">;
122
141
 
123
142
  /**
124
143
  * Calls to methods with this type are translated to `left - right`, where `left` is the object with the method.
@@ -127,8 +146,7 @@ declare type LuaSubtraction<TLeft, TRight, TReturn> = ((left: TLeft, right: TRig
127
146
  * @param TRight The type of the right-hand-side of the operation.
128
147
  * @param TReturn The resulting (return) type of the operation.
129
148
  */
130
- declare type LuaSubtractionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
131
- LuaExtension<"__luaSubtractionMethodBrand">;
149
+ declare type LuaSubtractionMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"SubtractionMethod">;
132
150
 
133
151
  /**
134
152
  * Calls to functions with this type are translated to `left * right`.
@@ -139,7 +157,7 @@ declare type LuaSubtractionMethod<TRight, TReturn> = ((right: TRight) => TReturn
139
157
  * @param TReturn The resulting (return) type of the operation.
140
158
  */
141
159
  declare type LuaMultiplication<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
142
- LuaExtension<"__luaMultiplicationBrand">;
160
+ LuaExtension<"Multiplication">;
143
161
 
144
162
  /**
145
163
  * Calls to methods with this type are translated to `left * right`, where `left` is the object with the method.
@@ -149,7 +167,7 @@ declare type LuaMultiplication<TLeft, TRight, TReturn> = ((left: TLeft, right: T
149
167
  * @param TReturn The resulting (return) type of the operation.
150
168
  */
151
169
  declare type LuaMultiplicationMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
152
- LuaExtension<"__luaMultiplicationMethodBrand">;
170
+ LuaExtension<"MultiplicationMethod">;
153
171
 
154
172
  /**
155
173
  * Calls to functions with this type are translated to `left / right`.
@@ -159,8 +177,7 @@ declare type LuaMultiplicationMethod<TRight, TReturn> = ((right: TRight) => TRet
159
177
  * @param TRight The type of the right-hand-side of the operation.
160
178
  * @param TReturn The resulting (return) type of the operation.
161
179
  */
162
- declare type LuaDivision<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
163
- LuaExtension<"__luaDivisionBrand">;
180
+ declare type LuaDivision<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"Division">;
164
181
 
165
182
  /**
166
183
  * Calls to methods with this type are translated to `left / right`, where `left` is the object with the method.
@@ -169,8 +186,7 @@ declare type LuaDivision<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight)
169
186
  * @param TRight The type of the right-hand-side of the operation.
170
187
  * @param TReturn The resulting (return) type of the operation.
171
188
  */
172
- declare type LuaDivisionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
173
- LuaExtension<"__luaDivisionMethodBrand">;
189
+ declare type LuaDivisionMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"DivisionMethod">;
174
190
 
175
191
  /**
176
192
  * Calls to functions with this type are translated to `left % right`.
@@ -180,8 +196,7 @@ declare type LuaDivisionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
180
196
  * @param TRight The type of the right-hand-side of the operation.
181
197
  * @param TReturn The resulting (return) type of the operation.
182
198
  */
183
- declare type LuaModulo<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
184
- LuaExtension<"__luaModuloBrand">;
199
+ declare type LuaModulo<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"Modulo">;
185
200
 
186
201
  /**
187
202
  * Calls to methods with this type are translated to `left % right`, where `left` is the object with the method.
@@ -190,7 +205,7 @@ declare type LuaModulo<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) =
190
205
  * @param TRight The type of the right-hand-side of the operation.
191
206
  * @param TReturn The resulting (return) type of the operation.
192
207
  */
193
- declare type LuaModuloMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"__luaModuloMethodBrand">;
208
+ declare type LuaModuloMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"ModuloMethod">;
194
209
 
195
210
  /**
196
211
  * Calls to functions with this type are translated to `left ^ right`.
@@ -200,8 +215,7 @@ declare type LuaModuloMethod<TRight, TReturn> = ((right: TRight) => TReturn) & L
200
215
  * @param TRight The type of the right-hand-side of the operation.
201
216
  * @param TReturn The resulting (return) type of the operation.
202
217
  */
203
- declare type LuaPower<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
204
- LuaExtension<"__luaPowerBrand">;
218
+ declare type LuaPower<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"Power">;
205
219
 
206
220
  /**
207
221
  * Calls to methods with this type are translated to `left ^ right`, where `left` is the object with the method.
@@ -210,7 +224,7 @@ declare type LuaPower<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) =>
210
224
  * @param TRight The type of the right-hand-side of the operation.
211
225
  * @param TReturn The resulting (return) type of the operation.
212
226
  */
213
- declare type LuaPowerMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"__luaPowerMethodBrand">;
227
+ declare type LuaPowerMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"PowerMethod">;
214
228
 
215
229
  /**
216
230
  * Calls to functions with this type are translated to `left // right`.
@@ -221,7 +235,7 @@ declare type LuaPowerMethod<TRight, TReturn> = ((right: TRight) => TReturn) & Lu
221
235
  * @param TReturn The resulting (return) type of the operation.
222
236
  */
223
237
  declare type LuaFloorDivision<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
224
- LuaExtension<"__luaFloorDivisionBrand">;
238
+ LuaExtension<"FloorDivision">;
225
239
 
226
240
  /**
227
241
  * Calls to methods with this type are translated to `left // right`, where `left` is the object with the method.
@@ -231,7 +245,7 @@ declare type LuaFloorDivision<TLeft, TRight, TReturn> = ((left: TLeft, right: TR
231
245
  * @param TReturn The resulting (return) type of the operation.
232
246
  */
233
247
  declare type LuaFloorDivisionMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
234
- LuaExtension<"__luaFloorDivisionMethodBrand">;
248
+ LuaExtension<"FloorDivisionMethod">;
235
249
 
236
250
  /**
237
251
  * Calls to functions with this type are translated to `left & right`.
@@ -242,7 +256,7 @@ declare type LuaFloorDivisionMethod<TRight, TReturn> = ((right: TRight) => TRetu
242
256
  * @param TReturn The resulting (return) type of the operation.
243
257
  */
244
258
  declare type LuaBitwiseAnd<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
245
- LuaExtension<"__luaBitwiseAndBrand">;
259
+ LuaExtension<"BitwiseAnd">;
246
260
 
247
261
  /**
248
262
  * Calls to methods with this type are translated to `left & right`, where `left` is the object with the method.
@@ -251,8 +265,7 @@ declare type LuaBitwiseAnd<TLeft, TRight, TReturn> = ((left: TLeft, right: TRigh
251
265
  * @param TRight The type of the right-hand-side of the operation.
252
266
  * @param TReturn The resulting (return) type of the operation.
253
267
  */
254
- declare type LuaBitwiseAndMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
255
- LuaExtension<"__luaBitwiseAndMethodBrand">;
268
+ declare type LuaBitwiseAndMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"BitwiseAndMethod">;
256
269
 
257
270
  /**
258
271
  * Calls to functions with this type are translated to `left | right`.
@@ -263,7 +276,7 @@ declare type LuaBitwiseAndMethod<TRight, TReturn> = ((right: TRight) => TReturn)
263
276
  * @param TReturn The resulting (return) type of the operation.
264
277
  */
265
278
  declare type LuaBitwiseOr<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
266
- LuaExtension<"__luaBitwiseOrBrand">;
279
+ LuaExtension<"BitwiseOr">;
267
280
 
268
281
  /**
269
282
  * Calls to methods with this type are translated to `left | right`, where `left` is the object with the method.
@@ -272,8 +285,7 @@ declare type LuaBitwiseOr<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight
272
285
  * @param TRight The type of the right-hand-side of the operation.
273
286
  * @param TReturn The resulting (return) type of the operation.
274
287
  */
275
- declare type LuaBitwiseOrMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
276
- LuaExtension<"__luaBitwiseOrMethodBrand">;
288
+ declare type LuaBitwiseOrMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"BitwiseOrMethod">;
277
289
 
278
290
  /**
279
291
  * Calls to functions with this type are translated to `left ~ right`.
@@ -284,7 +296,7 @@ declare type LuaBitwiseOrMethod<TRight, TReturn> = ((right: TRight) => TReturn)
284
296
  * @param TReturn The resulting (return) type of the operation.
285
297
  */
286
298
  declare type LuaBitwiseExclusiveOr<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
287
- LuaExtension<"__luaBitwiseExclusiveOrBrand">;
299
+ LuaExtension<"BitwiseExclusiveOr">;
288
300
 
289
301
  /**
290
302
  * Calls to methods with this type are translated to `left ~ right`, where `left` is the object with the method.
@@ -294,7 +306,7 @@ declare type LuaBitwiseExclusiveOr<TLeft, TRight, TReturn> = ((left: TLeft, righ
294
306
  * @param TReturn The resulting (return) type of the operation.
295
307
  */
296
308
  declare type LuaBitwiseExclusiveOrMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
297
- LuaExtension<"__luaBitwiseExclusiveOrMethodBrand">;
309
+ LuaExtension<"BitwiseExclusiveOrMethod">;
298
310
 
299
311
  /**
300
312
  * Calls to functions with this type are translated to `left << right`.
@@ -305,7 +317,7 @@ declare type LuaBitwiseExclusiveOrMethod<TRight, TReturn> = ((right: TRight) =>
305
317
  * @param TReturn The resulting (return) type of the operation.
306
318
  */
307
319
  declare type LuaBitwiseLeftShift<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
308
- LuaExtension<"__luaBitwiseLeftShiftBrand">;
320
+ LuaExtension<"BitwiseLeftShift">;
309
321
 
310
322
  /**
311
323
  * Calls to methods with this type are translated to `left << right`, where `left` is the object with the method.
@@ -315,7 +327,7 @@ declare type LuaBitwiseLeftShift<TLeft, TRight, TReturn> = ((left: TLeft, right:
315
327
  * @param TReturn The resulting (return) type of the operation.
316
328
  */
317
329
  declare type LuaBitwiseLeftShiftMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
318
- LuaExtension<"__luaBitwiseLeftShiftMethodBrand">;
330
+ LuaExtension<"BitwiseLeftShiftMethod">;
319
331
 
320
332
  /**
321
333
  * Calls to functions with this type are translated to `left >> right`.
@@ -326,7 +338,7 @@ declare type LuaBitwiseLeftShiftMethod<TRight, TReturn> = ((right: TRight) => TR
326
338
  * @param TReturn The resulting (return) type of the operation.
327
339
  */
328
340
  declare type LuaBitwiseRightShift<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
329
- LuaExtension<"__luaBitwiseRightShiftBrand">;
341
+ LuaExtension<"BitwiseRightShift">;
330
342
 
331
343
  /**
332
344
  * Calls to methods with this type are translated to `left >> right`, where `left` is the object with the method.
@@ -336,7 +348,7 @@ declare type LuaBitwiseRightShift<TLeft, TRight, TReturn> = ((left: TLeft, right
336
348
  * @param TReturn The resulting (return) type of the operation.
337
349
  */
338
350
  declare type LuaBitwiseRightShiftMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
339
- LuaExtension<"__luaBitwiseRightShiftMethodBrand">;
351
+ LuaExtension<"BitwiseRightShiftMethod">;
340
352
 
341
353
  /**
342
354
  * Calls to functions with this type are translated to `left .. right`.
@@ -346,8 +358,7 @@ declare type LuaBitwiseRightShiftMethod<TRight, TReturn> = ((right: TRight) => T
346
358
  * @param TRight The type of the right-hand-side of the operation.
347
359
  * @param TReturn The resulting (return) type of the operation.
348
360
  */
349
- declare type LuaConcat<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
350
- LuaExtension<"__luaConcatBrand">;
361
+ declare type LuaConcat<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"Concat">;
351
362
 
352
363
  /**
353
364
  * Calls to methods with this type are translated to `left .. right`, where `left` is the object with the method.
@@ -356,7 +367,7 @@ declare type LuaConcat<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) =
356
367
  * @param TRight The type of the right-hand-side of the operation.
357
368
  * @param TReturn The resulting (return) type of the operation.
358
369
  */
359
- declare type LuaConcatMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"__luaConcatMethodBrand">;
370
+ declare type LuaConcatMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"ConcatMethod">;
360
371
 
361
372
  /**
362
373
  * Calls to functions with this type are translated to `left < right`.
@@ -366,8 +377,7 @@ declare type LuaConcatMethod<TRight, TReturn> = ((right: TRight) => TReturn) & L
366
377
  * @param TRight The type of the right-hand-side of the operation.
367
378
  * @param TReturn The resulting (return) type of the operation.
368
379
  */
369
- declare type LuaLessThan<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
370
- LuaExtension<"__luaLessThanBrand">;
380
+ declare type LuaLessThan<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) & LuaExtension<"LessThan">;
371
381
 
372
382
  /**
373
383
  * Calls to methods with this type are translated to `left < right`, where `left` is the object with the method.
@@ -376,8 +386,7 @@ declare type LuaLessThan<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight)
376
386
  * @param TRight The type of the right-hand-side of the operation.
377
387
  * @param TReturn The resulting (return) type of the operation.
378
388
  */
379
- declare type LuaLessThanMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
380
- LuaExtension<"__luaLessThanMethodBrand">;
389
+ declare type LuaLessThanMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"LessThanMethod">;
381
390
 
382
391
  /**
383
392
  * Calls to functions with this type are translated to `left > right`.
@@ -388,7 +397,7 @@ declare type LuaLessThanMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
388
397
  * @param TReturn The resulting (return) type of the operation.
389
398
  */
390
399
  declare type LuaGreaterThan<TLeft, TRight, TReturn> = ((left: TLeft, right: TRight) => TReturn) &
391
- LuaExtension<"__luaGreaterThanBrand">;
400
+ LuaExtension<"GreaterThan">;
392
401
 
393
402
  /**
394
403
  * Calls to methods with this type are translated to `left > right`, where `left` is the object with the method.
@@ -397,8 +406,7 @@ declare type LuaGreaterThan<TLeft, TRight, TReturn> = ((left: TLeft, right: TRig
397
406
  * @param TRight The type of the right-hand-side of the operation.
398
407
  * @param TReturn The resulting (return) type of the operation.
399
408
  */
400
- declare type LuaGreaterThanMethod<TRight, TReturn> = ((right: TRight) => TReturn) &
401
- LuaExtension<"__luaGreaterThanMethodBrand">;
409
+ declare type LuaGreaterThanMethod<TRight, TReturn> = ((right: TRight) => TReturn) & LuaExtension<"GreaterThanMethod">;
402
410
 
403
411
  /**
404
412
  * Calls to functions with this type are translated to `-operand`.
@@ -407,7 +415,7 @@ declare type LuaGreaterThanMethod<TRight, TReturn> = ((right: TRight) => TReturn
407
415
  * @param TOperand The type of the value in the operation.
408
416
  * @param TReturn The resulting (return) type of the operation.
409
417
  */
410
- declare type LuaNegation<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"__luaNegationBrand">;
418
+ declare type LuaNegation<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"Negation">;
411
419
 
412
420
  /**
413
421
  * Calls to method with this type are translated to `-operand`, where `operand` is the object with the method.
@@ -415,7 +423,7 @@ declare type LuaNegation<TOperand, TReturn> = ((operand: TOperand) => TReturn) &
415
423
  *
416
424
  * @param TReturn The resulting (return) type of the operation.
417
425
  */
418
- declare type LuaNegationMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaNegationMethodBrand">;
426
+ declare type LuaNegationMethod<TReturn> = (() => TReturn) & LuaExtension<"NegationMethod">;
419
427
 
420
428
  /**
421
429
  * Calls to functions with this type are translated to `~operand`.
@@ -424,7 +432,7 @@ declare type LuaNegationMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaN
424
432
  * @param TOperand The type of the value in the operation.
425
433
  * @param TReturn The resulting (return) type of the operation.
426
434
  */
427
- declare type LuaBitwiseNot<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"__luaBitwiseNotBrand">;
435
+ declare type LuaBitwiseNot<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"BitwiseNot">;
428
436
 
429
437
  /**
430
438
  * Calls to method with this type are translated to `~operand`, where `operand` is the object with the method.
@@ -432,7 +440,7 @@ declare type LuaBitwiseNot<TOperand, TReturn> = ((operand: TOperand) => TReturn)
432
440
  *
433
441
  * @param TReturn The resulting (return) type of the operation.
434
442
  */
435
- declare type LuaBitwiseNotMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaBitwiseNotMethodBrand">;
443
+ declare type LuaBitwiseNotMethod<TReturn> = (() => TReturn) & LuaExtension<"BitwiseNotMethod">;
436
444
 
437
445
  /**
438
446
  * Calls to functions with this type are translated to `#operand`.
@@ -441,7 +449,7 @@ declare type LuaBitwiseNotMethod<TReturn> = (() => TReturn) & LuaExtension<"__lu
441
449
  * @param TOperand The type of the value in the operation.
442
450
  * @param TReturn The resulting (return) type of the operation.
443
451
  */
444
- declare type LuaLength<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"__luaLengthBrand">;
452
+ declare type LuaLength<TOperand, TReturn> = ((operand: TOperand) => TReturn) & LuaExtension<"Length">;
445
453
 
446
454
  /**
447
455
  * Calls to method with this type are translated to `#operand`, where `operand` is the object with the method.
@@ -449,7 +457,7 @@ declare type LuaLength<TOperand, TReturn> = ((operand: TOperand) => TReturn) & L
449
457
  *
450
458
  * @param TReturn The resulting (return) type of the operation.
451
459
  */
452
- declare type LuaLengthMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaLengthMethodBrand">;
460
+ declare type LuaLengthMethod<TReturn> = (() => TReturn) & LuaExtension<"LengthMethod">;
453
461
 
454
462
  /**
455
463
  * Calls to functions with this type are translated to `table[key]`.
@@ -463,7 +471,7 @@ declare type LuaTableGet<TTable extends AnyTable, TKey extends AnyNotNil, TValue
463
471
  table: TTable,
464
472
  key: TKey
465
473
  ) => TValue) &
466
- LuaExtension<"__luaTableGetBrand">;
474
+ LuaExtension<"TableGet">;
467
475
 
468
476
  /**
469
477
  * Calls to methods with this type are translated to `table[key]`, where `table` is the object with the method.
@@ -473,7 +481,7 @@ declare type LuaTableGet<TTable extends AnyTable, TKey extends AnyNotNil, TValue
473
481
  * @param TValue The type of the value stored in the table.
474
482
  */
475
483
  declare type LuaTableGetMethod<TKey extends AnyNotNil, TValue> = ((key: TKey) => TValue) &
476
- LuaExtension<"__luaTableGetMethodBrand">;
484
+ LuaExtension<"TableGetMethod">;
477
485
 
478
486
  /**
479
487
  * Calls to functions with this type are translated to `table[key] = value`.
@@ -488,7 +496,7 @@ declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue
488
496
  key: TKey,
489
497
  value: TValue
490
498
  ) => void) &
491
- LuaExtension<"__luaTableSetBrand">;
499
+ LuaExtension<"TableSet">;
492
500
 
493
501
  /**
494
502
  * Calls to methods with this type are translated to `table[key] = value`, where `table` is the object with the method.
@@ -498,7 +506,24 @@ declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue
498
506
  * @param TValue The type of the value to assign to the table.
499
507
  */
500
508
  declare type LuaTableSetMethod<TKey extends AnyNotNil, TValue> = ((key: TKey, value: TValue) => void) &
501
- LuaExtension<"__luaTableSetMethodBrand">;
509
+ LuaExtension<"TableSetMethod">;
510
+
511
+ /**
512
+ * Calls to functions with this type are translated to `table[key] = true`.
513
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
514
+ *
515
+ * @param TTable The type to access as a Lua table.
516
+ * @param TKey The type of the key to use to access the table.
517
+ */
518
+ declare type LuaTableAddKey<TTable extends AnyTable, TKey extends AnyNotNil> = ((table: TTable, key: TKey) => void) &
519
+ LuaExtension<"TableAddKey">;
520
+
521
+ /**
522
+ * Calls to methods with this type are translated to `table[key] = true`, where `table` is the object with the method.
523
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
524
+ * @param TKey The type of the key to use to access the table.
525
+ */
526
+ declare type LuaTableAddKeyMethod<TKey extends AnyNotNil> = ((key: TKey) => void) & LuaExtension<"TableAddKeyMethod">;
502
527
 
503
528
  /**
504
529
  * Calls to functions with this type are translated to `table[key] ~= nil`.
@@ -508,7 +533,7 @@ declare type LuaTableSetMethod<TKey extends AnyNotNil, TValue> = ((key: TKey, va
508
533
  * @param TKey The type of the key to use to access the table.
509
534
  */
510
535
  declare type LuaTableHas<TTable extends AnyTable, TKey extends AnyNotNil> = ((table: TTable, key: TKey) => boolean) &
511
- LuaExtension<"__luaTableHasBrand">;
536
+ LuaExtension<"TableHas">;
512
537
 
513
538
  /**
514
539
  * Calls to methods with this type are translated to `table[key] ~= nil`, where `table` is the object with the method.
@@ -516,8 +541,7 @@ declare type LuaTableHas<TTable extends AnyTable, TKey extends AnyNotNil> = ((ta
516
541
  *
517
542
  * @param TKey The type of the key to use to access the table.
518
543
  */
519
- declare type LuaTableHasMethod<TKey extends AnyNotNil> = ((key: TKey) => boolean) &
520
- LuaExtension<"__luaTableHasMethodBrand">;
544
+ declare type LuaTableHasMethod<TKey extends AnyNotNil> = ((key: TKey) => boolean) & LuaExtension<"TableHasMethod">;
521
545
 
522
546
  /**
523
547
  * Calls to functions with this type are translated to `table[key] = nil`.
@@ -527,7 +551,7 @@ declare type LuaTableHasMethod<TKey extends AnyNotNil> = ((key: TKey) => boolean
527
551
  * @param TKey The type of the key to use to access the table.
528
552
  */
529
553
  declare type LuaTableDelete<TTable extends AnyTable, TKey extends AnyNotNil> = ((table: TTable, key: TKey) => boolean) &
530
- LuaExtension<"__luaTableDeleteBrand">;
554
+ LuaExtension<"TableDelete">;
531
555
 
532
556
  /**
533
557
  * Calls to methods with this type are translated to `table[key] = nil`, where `table` is the object with the method.
@@ -536,7 +560,7 @@ declare type LuaTableDelete<TTable extends AnyTable, TKey extends AnyNotNil> = (
536
560
  * @param TKey The type of the key to use to access the table.
537
561
  */
538
562
  declare type LuaTableDeleteMethod<TKey extends AnyNotNil> = ((key: TKey) => boolean) &
539
- LuaExtension<"__luaTableDeleteMethodBrand">;
563
+ LuaExtension<"TableDeleteMethod">;
540
564
 
541
565
  /**
542
566
  * A convenience type for working directly with a Lua table.
@@ -564,7 +588,7 @@ declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TVa
564
588
  TKey,
565
589
  TValue
566
590
  >) &
567
- LuaExtension<"__luaTableNewBrand">;
591
+ LuaExtension<"TableNew">;
568
592
 
569
593
  /**
570
594
  * A convenience type for working directly with a Lua table.
@@ -574,3 +598,79 @@ declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TVa
574
598
  * @param TValue The type of the values stored in the table.
575
599
  */
576
600
  declare const LuaTable: LuaTableConstructor;
601
+
602
+ /**
603
+ * A convenience type for working directly with a Lua table, used as a map.
604
+ *
605
+ * This differs from LuaTable in that the `get` method may return `nil`.
606
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
607
+ * @param K The type of the keys used to access the table.
608
+ * @param V The type of the values stored in the table.
609
+ */
610
+ declare interface LuaMap<K extends AnyNotNil = AnyNotNil, V = any> extends LuaPairsIterable<K, V> {
611
+ get: LuaTableGetMethod<K, V | undefined>;
612
+ set: LuaTableSetMethod<K, V>;
613
+ has: LuaTableHasMethod<K>;
614
+ delete: LuaTableDeleteMethod<K>;
615
+ }
616
+
617
+ /**
618
+ * A convenience type for working directly with a Lua table, used as a map.
619
+ *
620
+ * This differs from LuaTable in that the `get` method may return `nil`.
621
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
622
+ * @param K The type of the keys used to access the table.
623
+ * @param V The type of the values stored in the table.
624
+ */
625
+ declare const LuaMap: (new <K extends AnyNotNil = AnyNotNil, V = any>() => LuaMap<K, V>) & LuaExtension<"TableNew">;
626
+
627
+ /**
628
+ * Readonly version of {@link LuaMap}.
629
+ *
630
+ * @param K The type of the keys used to access the table.
631
+ * @param V The type of the values stored in the table.
632
+ */
633
+ declare interface ReadonlyLuaMap<K extends AnyNotNil = AnyNotNil, V = any> extends LuaPairsIterable<K, V> {
634
+ get: LuaTableGetMethod<K, V>;
635
+ has: LuaTableHasMethod<K>;
636
+ }
637
+
638
+ /**
639
+ * A convenience type for working directly with a Lua table, used as a set.
640
+ *
641
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
642
+ * @param T The type of the keys used to access the table.
643
+ */
644
+ declare interface LuaSet<T extends AnyNotNil = AnyNotNil> extends LuaPairsKeyIterable<T> {
645
+ add: LuaTableAddKeyMethod<T>;
646
+ has: LuaTableHasMethod<T>;
647
+ delete: LuaTableDeleteMethod<T>;
648
+ }
649
+
650
+ /**
651
+ * A convenience type for working directly with a Lua table, used as a set.
652
+ *
653
+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
654
+ * @param T The type of the keys used to access the table.
655
+ */
656
+ declare const LuaSet: (new <T extends AnyNotNil = AnyNotNil>() => LuaSet<T>) & LuaExtension<"TableNew">;
657
+
658
+ /**
659
+ * Readonly version of {@link LuaSet}.
660
+ *
661
+ * @param T The type of the keys used to access the table.
662
+ */
663
+ declare interface ReadonlyLuaSet<T extends AnyNotNil = AnyNotNil> extends LuaPairsKeyIterable<T> {
664
+ has: LuaTableHasMethod<T>;
665
+ }
666
+
667
+ interface ObjectConstructor {
668
+ /** Returns an array of keys of an object, when iterated with `pairs`. */
669
+ keys<K>(o: LuaPairsIterable<K, any> | LuaPairsKeyIterable<K>): K[];
670
+
671
+ /** Returns an array of values of an object, when iterated with `pairs`. */
672
+ values<V>(o: LuaPairsIterable<any, V>): V[];
673
+
674
+ /** Returns an array of key/values of an object, when iterated with `pairs`. */
675
+ entries<K, V>(o: LuaPairsIterable<K, V>): Array<[K, V]>;
676
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.6.2",
3
+ "version": "1.7.1",
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/",
@@ -65,7 +65,7 @@
65
65
  "javascript-stringify": "^2.0.1",
66
66
  "jest": "^27.3.0",
67
67
  "jest-circus": "^27.3.0",
68
- "lua-types": "2.10.1",
68
+ "lua-types": "^2.11.0",
69
69
  "lua-wasm-bindings": "^0.2.2",
70
70
  "prettier": "^2.3.2",
71
71
  "ts-jest": "^27.1.3",
@@ -1,4 +0,0 @@
1
- import { TransformationContext } from "../../context";
2
- import * as ts from "typescript";
3
- import * as lua from "../../../LuaAST";
4
- export declare function transformLanguageExtensionCallExpression(context: TransformationContext, node: ts.CallExpression, isOptionalCall: boolean): lua.Expression | undefined;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformLanguageExtensionCallExpression = void 0;
4
- const operators_1 = require("./operators");
5
- const table_1 = require("./table");
6
- function transformLanguageExtensionCallExpression(context, node, isOptionalCall) {
7
- const operatorMapping = (0, operators_1.transformOperatorMappingExpression)(context, node, isOptionalCall);
8
- if (operatorMapping) {
9
- return operatorMapping;
10
- }
11
- const tableCall = (0, table_1.transformTableExtensionCall)(context, node, isOptionalCall);
12
- if (tableCall) {
13
- return tableCall;
14
- }
15
- }
16
- exports.transformLanguageExtensionCallExpression = transformLanguageExtensionCallExpression;
17
- //# sourceMappingURL=index.js.map
@@ -1,5 +0,0 @@
1
- import * as ts from "typescript";
2
- import * as lua from "../../../LuaAST";
3
- import { TransformationContext } from "../../context";
4
- export declare function isPairsIterableExpression(context: TransformationContext, expression: ts.Expression): boolean;
5
- export declare function transformForOfPairsIterableStatement(context: TransformationContext, statement: ts.ForOfStatement, block: lua.Block): lua.Statement;