typescript-to-lua 1.2.0 → 1.3.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/CHANGELOG.md +12 -0
- package/dist/LuaLib.js +1 -1
- package/dist/LuaPrinter.js +4 -4
- package/dist/lualib/Await.lua +7 -3
- package/dist/lualib/CloneDescriptor.lua +6 -6
- package/dist/lualib/Promise.lua +10 -2
- package/dist/lualib/lualib_bundle.lua +217 -205
- package/dist/transformation/builtins/function.js +5 -2
- package/dist/transformation/builtins/index.js +2 -2
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/language-extensions.d.ts +2 -0
- package/dist/transformation/utils/language-extensions.js +7 -1
- package/dist/transformation/utils/lua-ast.js +5 -5
- package/dist/transformation/utils/safe-names.d.ts +4 -2
- package/dist/transformation/utils/safe-names.js +11 -5
- package/dist/transformation/utils/scope.d.ts +2 -1
- package/dist/transformation/utils/scope.js +1 -0
- package/dist/transformation/utils/typescript/types.d.ts +3 -1
- package/dist/transformation/utils/typescript/types.js +40 -13
- package/dist/transformation/visitors/binary-expression/index.js +1 -3
- package/dist/transformation/visitors/call.js +1 -1
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/conditional.js +2 -23
- package/dist/transformation/visitors/errors.js +11 -9
- package/dist/transformation/visitors/function.d.ts +2 -0
- package/dist/transformation/visitors/function.js +53 -4
- package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
- package/dist/transformation/visitors/loops/for-of.js +4 -0
- package/dist/transformation/visitors/loops/utils.js +6 -1
- package/dist/transformation/visitors/namespace.js +1 -1
- package/dist/transformation/visitors/spread.js +14 -7
- package/dist/transformation/visitors/variable-declaration.js +10 -1
- package/language-extensions/index.d.ts +11 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
- Added `LuaPairsIterable` language extension to mark objects as iterable with Lua's `pairs`.
|
|
6
|
+
- Added support for properties on functions.
|
|
7
|
+
- Unicode is no longer escaped and used as-is for `"luaTarget": "JIT"`.
|
|
8
|
+
- Fixed some bugs related to destructuring in loops and function parameters.
|
|
9
|
+
- Fixed incorrect global being generated for some `try` statements.
|
|
10
|
+
- Fixed some incorrect behavior for `??` and `? :` when generic types were involved.
|
|
11
|
+
- Added missing `...` optimization in cases where casts or parentheses are used.
|
|
12
|
+
- Fixed a bug for `Promise` when resolving with another Promise. This also fixes some unexpected behavior with `async` which is built with Promises.
|
|
13
|
+
- Fixed `async` functions not aborting after returning from a `catch` block.
|
|
14
|
+
|
|
3
15
|
## 1.2.0
|
|
4
16
|
|
|
5
17
|
- Upgraded to TypeScript 4.5.x.
|
package/dist/LuaLib.js
CHANGED
|
@@ -104,7 +104,7 @@ const luaLibDependencies = {
|
|
|
104
104
|
ArrayConcat: [LuaLibFeature.ArrayIsArray],
|
|
105
105
|
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
|
|
106
106
|
ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
|
|
107
|
-
Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New],
|
|
107
|
+
Await: [LuaLibFeature.InstanceOf, LuaLibFeature.New, LuaLibFeature.Promise],
|
|
108
108
|
Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
|
|
109
109
|
DelegatedYield: [LuaLibFeature.StringAccess],
|
|
110
110
|
Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors, LuaLibFeature.Error, LuaLibFeature.New],
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -32,7 +32,7 @@ exports.tstlHeader = "--[[ Generated with https://github.com/TypeScriptToLua/Typ
|
|
|
32
32
|
* `foo.bar` => passes (`function foo.bar()` is valid)
|
|
33
33
|
* `getFoo().bar` => fails (`function getFoo().bar()` would be illegal)
|
|
34
34
|
*/
|
|
35
|
-
const isValidLuaFunctionDeclarationName = (str) => /^[a-zA-Z0-9_.]
|
|
35
|
+
const isValidLuaFunctionDeclarationName = (str, options) => ((0, safe_names_1.shouldAllowUnicode)(options) ? /^[a-zA-Z0-9_\u00FF-\uFFFD.]+$/ : /^[a-zA-Z0-9_.]+$/).test(str);
|
|
36
36
|
/**
|
|
37
37
|
* Returns true if expression contains no function calls.
|
|
38
38
|
*/
|
|
@@ -294,7 +294,7 @@ class LuaPrinter {
|
|
|
294
294
|
(statement.right[0].flags & lua.FunctionExpressionFlags.Declaration) !== 0) {
|
|
295
295
|
// Use `function foo()` instead of `foo = function()`
|
|
296
296
|
const name = this.printExpression(statement.left[0]);
|
|
297
|
-
if (isValidLuaFunctionDeclarationName(name.toString())) {
|
|
297
|
+
if (isValidLuaFunctionDeclarationName(name.toString(), this.options)) {
|
|
298
298
|
chunks.push(this.printFunctionDefinition(statement));
|
|
299
299
|
return this.createSourceNode(statement, chunks);
|
|
300
300
|
}
|
|
@@ -494,7 +494,7 @@ class LuaPrinter {
|
|
|
494
494
|
const chunks = [];
|
|
495
495
|
const value = this.printExpression(expression.value);
|
|
496
496
|
if (expression.key) {
|
|
497
|
-
if (lua.isStringLiteral(expression.key) && (0, safe_names_1.isValidLuaIdentifier)(expression.key.value)) {
|
|
497
|
+
if (lua.isStringLiteral(expression.key) && (0, safe_names_1.isValidLuaIdentifier)(expression.key.value, this.options)) {
|
|
498
498
|
chunks.push(expression.key.value, " = ", value);
|
|
499
499
|
}
|
|
500
500
|
else {
|
|
@@ -566,7 +566,7 @@ class LuaPrinter {
|
|
|
566
566
|
printTableIndexExpression(expression) {
|
|
567
567
|
const chunks = [];
|
|
568
568
|
chunks.push(this.printExpressionInParenthesesIfNeeded(expression.table));
|
|
569
|
-
if (lua.isStringLiteral(expression.index) && (0, safe_names_1.isValidLuaIdentifier)(expression.index.value)) {
|
|
569
|
+
if (lua.isStringLiteral(expression.index) && (0, safe_names_1.isValidLuaIdentifier)(expression.index.value, this.options)) {
|
|
570
570
|
chunks.push(".", this.createSourceNode(expression.index, expression.index.value));
|
|
571
571
|
}
|
|
572
572
|
else {
|
package/dist/lualib/Await.lua
CHANGED
|
@@ -23,11 +23,15 @@ function __TS__AsyncAwaiter(generator)
|
|
|
23
23
|
function rejected(self, handler)
|
|
24
24
|
if handler then
|
|
25
25
|
return function(____, value)
|
|
26
|
-
local success,
|
|
26
|
+
local success, hasReturnedOrError, returnedValue = pcall(handler, value)
|
|
27
27
|
if success then
|
|
28
|
-
|
|
28
|
+
if hasReturnedOrError then
|
|
29
|
+
resolve(_G, returnedValue)
|
|
30
|
+
else
|
|
31
|
+
step(_G, hasReturnedOrError, handler)
|
|
32
|
+
end
|
|
29
33
|
else
|
|
30
|
-
reject(_G,
|
|
34
|
+
reject(_G, hasReturnedOrError)
|
|
31
35
|
end
|
|
32
36
|
end
|
|
33
37
|
else
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
local value
|
|
2
|
-
local writable
|
|
3
|
-
local set
|
|
4
|
-
local get
|
|
5
|
-
local configurable
|
|
6
|
-
local enumerable
|
|
7
1
|
function __TS__CloneDescriptor(____bindingPattern0)
|
|
2
|
+
local value
|
|
3
|
+
local writable
|
|
4
|
+
local set
|
|
5
|
+
local get
|
|
6
|
+
local configurable
|
|
7
|
+
local enumerable
|
|
8
8
|
enumerable = ____bindingPattern0.enumerable
|
|
9
9
|
configurable = ____bindingPattern0.configurable
|
|
10
10
|
get = ____bindingPattern0.get
|
package/dist/lualib/Promise.lua
CHANGED
|
@@ -39,7 +39,7 @@ function __TS__Promise.prototype.____constructor(self, executor)
|
|
|
39
39
|
)
|
|
40
40
|
end)
|
|
41
41
|
if not ____try then
|
|
42
|
-
|
|
42
|
+
____catch(____hasReturned)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -110,6 +110,14 @@ function __TS__Promise.prototype.finally(self, onFinally)
|
|
|
110
110
|
return self
|
|
111
111
|
end
|
|
112
112
|
function __TS__Promise.prototype.resolve(self, data)
|
|
113
|
+
if __TS__InstanceOf(data, __TS__Promise) then
|
|
114
|
+
data["then"](
|
|
115
|
+
data,
|
|
116
|
+
function(____, v) return self:resolve(v) end,
|
|
117
|
+
function(____, err) return self:reject(err) end
|
|
118
|
+
)
|
|
119
|
+
return
|
|
120
|
+
end
|
|
113
121
|
if self.state == __TS__PromiseState.Pending then
|
|
114
122
|
self.state = __TS__PromiseState.Fulfilled
|
|
115
123
|
self.value = data
|
|
@@ -147,7 +155,7 @@ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve
|
|
|
147
155
|
)
|
|
148
156
|
end)
|
|
149
157
|
if not ____try then
|
|
150
|
-
|
|
158
|
+
____catch(____hasReturned)
|
|
151
159
|
end
|
|
152
160
|
end
|
|
153
161
|
end
|
|
@@ -504,6 +504,210 @@ function __TS__New(target, ...)
|
|
|
504
504
|
return instance
|
|
505
505
|
end
|
|
506
506
|
|
|
507
|
+
function __TS__Class(self)
|
|
508
|
+
local c = {prototype = {}}
|
|
509
|
+
c.prototype.__index = c.prototype
|
|
510
|
+
c.prototype.constructor = c
|
|
511
|
+
return c
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
__TS__Unpack = table.unpack or unpack
|
|
515
|
+
|
|
516
|
+
function __TS__FunctionBind(fn, thisArg, ...)
|
|
517
|
+
local boundArgs = {...}
|
|
518
|
+
return function(____, ...)
|
|
519
|
+
local args = {...}
|
|
520
|
+
do
|
|
521
|
+
local i = 0
|
|
522
|
+
while i < #boundArgs do
|
|
523
|
+
table.insert(args, i + 1, boundArgs[i + 1])
|
|
524
|
+
i = i + 1
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
return fn(
|
|
528
|
+
thisArg,
|
|
529
|
+
__TS__Unpack(args)
|
|
530
|
+
)
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
__TS__PromiseState = __TS__PromiseState or ({})
|
|
535
|
+
__TS__PromiseState.Pending = 0
|
|
536
|
+
__TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
|
|
537
|
+
__TS__PromiseState.Fulfilled = 1
|
|
538
|
+
__TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
|
|
539
|
+
__TS__PromiseState.Rejected = 2
|
|
540
|
+
__TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
|
|
541
|
+
function __TS__PromiseDeferred(self)
|
|
542
|
+
local resolve
|
|
543
|
+
local reject
|
|
544
|
+
local promise = __TS__New(
|
|
545
|
+
__TS__Promise,
|
|
546
|
+
function(____, res, rej)
|
|
547
|
+
resolve = res
|
|
548
|
+
reject = rej
|
|
549
|
+
end
|
|
550
|
+
)
|
|
551
|
+
return {promise = promise, resolve = resolve, reject = reject}
|
|
552
|
+
end
|
|
553
|
+
function __TS__IsPromiseLike(self, thing)
|
|
554
|
+
return __TS__InstanceOf(thing, __TS__Promise)
|
|
555
|
+
end
|
|
556
|
+
__TS__Promise = __TS__Class()
|
|
557
|
+
__TS__Promise.name = "__TS__Promise"
|
|
558
|
+
function __TS__Promise.prototype.____constructor(self, executor)
|
|
559
|
+
self.state = __TS__PromiseState.Pending
|
|
560
|
+
self.fulfilledCallbacks = {}
|
|
561
|
+
self.rejectedCallbacks = {}
|
|
562
|
+
self.finallyCallbacks = {}
|
|
563
|
+
do
|
|
564
|
+
local function ____catch(e)
|
|
565
|
+
self:reject(e)
|
|
566
|
+
end
|
|
567
|
+
local ____try, ____hasReturned = pcall(function()
|
|
568
|
+
executor(
|
|
569
|
+
_G,
|
|
570
|
+
__TS__FunctionBind(self.resolve, self),
|
|
571
|
+
__TS__FunctionBind(self.reject, self)
|
|
572
|
+
)
|
|
573
|
+
end)
|
|
574
|
+
if not ____try then
|
|
575
|
+
____catch(____hasReturned)
|
|
576
|
+
end
|
|
577
|
+
end
|
|
578
|
+
end
|
|
579
|
+
function __TS__Promise.resolve(data)
|
|
580
|
+
local promise = __TS__New(
|
|
581
|
+
__TS__Promise,
|
|
582
|
+
function()
|
|
583
|
+
end
|
|
584
|
+
)
|
|
585
|
+
promise.state = __TS__PromiseState.Fulfilled
|
|
586
|
+
promise.value = data
|
|
587
|
+
return promise
|
|
588
|
+
end
|
|
589
|
+
function __TS__Promise.reject(reason)
|
|
590
|
+
local promise = __TS__New(
|
|
591
|
+
__TS__Promise,
|
|
592
|
+
function()
|
|
593
|
+
end
|
|
594
|
+
)
|
|
595
|
+
promise.state = __TS__PromiseState.Rejected
|
|
596
|
+
promise.rejectionReason = reason
|
|
597
|
+
return promise
|
|
598
|
+
end
|
|
599
|
+
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
600
|
+
local ____TS__PromiseDeferred_result_0 = __TS__PromiseDeferred(_G)
|
|
601
|
+
local promise = ____TS__PromiseDeferred_result_0.promise
|
|
602
|
+
local resolve = ____TS__PromiseDeferred_result_0.resolve
|
|
603
|
+
local reject = ____TS__PromiseDeferred_result_0.reject
|
|
604
|
+
local isFulfilled = self.state == __TS__PromiseState.Fulfilled
|
|
605
|
+
local isRejected = self.state == __TS__PromiseState.Rejected
|
|
606
|
+
if onFulfilled then
|
|
607
|
+
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
608
|
+
__TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
|
|
609
|
+
if isFulfilled then
|
|
610
|
+
internalCallback(_G, self.value)
|
|
611
|
+
end
|
|
612
|
+
else
|
|
613
|
+
__TS__ArrayPush(
|
|
614
|
+
self.fulfilledCallbacks,
|
|
615
|
+
function() return resolve(_G, nil) end
|
|
616
|
+
)
|
|
617
|
+
end
|
|
618
|
+
if onRejected then
|
|
619
|
+
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
620
|
+
__TS__ArrayPush(self.rejectedCallbacks, internalCallback)
|
|
621
|
+
if isRejected then
|
|
622
|
+
internalCallback(_G, self.rejectionReason)
|
|
623
|
+
end
|
|
624
|
+
end
|
|
625
|
+
if isFulfilled then
|
|
626
|
+
resolve(_G, self.value)
|
|
627
|
+
end
|
|
628
|
+
if isRejected then
|
|
629
|
+
reject(_G, self.rejectionReason)
|
|
630
|
+
end
|
|
631
|
+
return promise
|
|
632
|
+
end
|
|
633
|
+
function __TS__Promise.prototype.catch(self, onRejected)
|
|
634
|
+
return self["then"](self, nil, onRejected)
|
|
635
|
+
end
|
|
636
|
+
function __TS__Promise.prototype.finally(self, onFinally)
|
|
637
|
+
if onFinally then
|
|
638
|
+
__TS__ArrayPush(self.finallyCallbacks, onFinally)
|
|
639
|
+
if self.state ~= __TS__PromiseState.Pending then
|
|
640
|
+
onFinally(_G)
|
|
641
|
+
end
|
|
642
|
+
end
|
|
643
|
+
return self
|
|
644
|
+
end
|
|
645
|
+
function __TS__Promise.prototype.resolve(self, data)
|
|
646
|
+
if __TS__InstanceOf(data, __TS__Promise) then
|
|
647
|
+
data["then"](
|
|
648
|
+
data,
|
|
649
|
+
function(____, v) return self:resolve(v) end,
|
|
650
|
+
function(____, err) return self:reject(err) end
|
|
651
|
+
)
|
|
652
|
+
return
|
|
653
|
+
end
|
|
654
|
+
if self.state == __TS__PromiseState.Pending then
|
|
655
|
+
self.state = __TS__PromiseState.Fulfilled
|
|
656
|
+
self.value = data
|
|
657
|
+
for ____, callback in ipairs(self.fulfilledCallbacks) do
|
|
658
|
+
callback(_G, data)
|
|
659
|
+
end
|
|
660
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
661
|
+
callback(_G)
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
end
|
|
665
|
+
function __TS__Promise.prototype.reject(self, reason)
|
|
666
|
+
if self.state == __TS__PromiseState.Pending then
|
|
667
|
+
self.state = __TS__PromiseState.Rejected
|
|
668
|
+
self.rejectionReason = reason
|
|
669
|
+
for ____, callback in ipairs(self.rejectedCallbacks) do
|
|
670
|
+
callback(_G, reason)
|
|
671
|
+
end
|
|
672
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
673
|
+
callback(_G)
|
|
674
|
+
end
|
|
675
|
+
end
|
|
676
|
+
end
|
|
677
|
+
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
678
|
+
return function(____, value)
|
|
679
|
+
do
|
|
680
|
+
local function ____catch(e)
|
|
681
|
+
reject(_G, e)
|
|
682
|
+
end
|
|
683
|
+
local ____try, ____hasReturned = pcall(function()
|
|
684
|
+
self:handleCallbackData(
|
|
685
|
+
f(_G, value),
|
|
686
|
+
resolve,
|
|
687
|
+
reject
|
|
688
|
+
)
|
|
689
|
+
end)
|
|
690
|
+
if not ____try then
|
|
691
|
+
____catch(____hasReturned)
|
|
692
|
+
end
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
|
|
697
|
+
if __TS__IsPromiseLike(_G, data) then
|
|
698
|
+
local nextpromise = data
|
|
699
|
+
if nextpromise.state == __TS__PromiseState.Fulfilled then
|
|
700
|
+
resolve(_G, nextpromise.value)
|
|
701
|
+
elseif nextpromise.state == __TS__PromiseState.Rejected then
|
|
702
|
+
reject(_G, nextpromise.rejectionReason)
|
|
703
|
+
else
|
|
704
|
+
data["then"](data, resolve, reject)
|
|
705
|
+
end
|
|
706
|
+
else
|
|
707
|
+
resolve(_G, data)
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
|
|
507
711
|
function __TS__AsyncAwaiter(generator)
|
|
508
712
|
return __TS__New(
|
|
509
713
|
__TS__Promise,
|
|
@@ -529,11 +733,15 @@ function __TS__AsyncAwaiter(generator)
|
|
|
529
733
|
function rejected(self, handler)
|
|
530
734
|
if handler then
|
|
531
735
|
return function(____, value)
|
|
532
|
-
local success,
|
|
736
|
+
local success, hasReturnedOrError, returnedValue = pcall(handler, value)
|
|
533
737
|
if success then
|
|
534
|
-
|
|
738
|
+
if hasReturnedOrError then
|
|
739
|
+
resolve(_G, returnedValue)
|
|
740
|
+
else
|
|
741
|
+
step(_G, hasReturnedOrError, handler)
|
|
742
|
+
end
|
|
535
743
|
else
|
|
536
|
-
reject(_G,
|
|
744
|
+
reject(_G, hasReturnedOrError)
|
|
537
745
|
end
|
|
538
746
|
end
|
|
539
747
|
else
|
|
@@ -568,13 +776,6 @@ function __TS__Await(errorHandler, thing)
|
|
|
568
776
|
return coroutine.yield(errorHandler, thing)
|
|
569
777
|
end
|
|
570
778
|
|
|
571
|
-
function __TS__Class(self)
|
|
572
|
-
local c = {prototype = {}}
|
|
573
|
-
c.prototype.__index = c.prototype
|
|
574
|
-
c.prototype.constructor = c
|
|
575
|
-
return c
|
|
576
|
-
end
|
|
577
|
-
|
|
578
779
|
function __TS__ClassExtends(target, base)
|
|
579
780
|
target.____super = base
|
|
580
781
|
local staticMetatable = setmetatable({__index = base}, base)
|
|
@@ -600,13 +801,13 @@ function __TS__ClassExtends(target, base)
|
|
|
600
801
|
end
|
|
601
802
|
end
|
|
602
803
|
|
|
603
|
-
local value
|
|
604
|
-
local writable
|
|
605
|
-
local set
|
|
606
|
-
local get
|
|
607
|
-
local configurable
|
|
608
|
-
local enumerable
|
|
609
804
|
function __TS__CloneDescriptor(____bindingPattern0)
|
|
805
|
+
local value
|
|
806
|
+
local writable
|
|
807
|
+
local set
|
|
808
|
+
local get
|
|
809
|
+
local configurable
|
|
810
|
+
local enumerable
|
|
610
811
|
enumerable = ____bindingPattern0.enumerable
|
|
611
812
|
configurable = ____bindingPattern0.configurable
|
|
612
813
|
get = ____bindingPattern0.get
|
|
@@ -919,26 +1120,6 @@ function __TS__DelegatedYield(iterable)
|
|
|
919
1120
|
end
|
|
920
1121
|
end
|
|
921
1122
|
|
|
922
|
-
__TS__Unpack = table.unpack or unpack
|
|
923
|
-
|
|
924
|
-
function __TS__FunctionBind(fn, thisArg, ...)
|
|
925
|
-
local boundArgs = {...}
|
|
926
|
-
return function(____, ...)
|
|
927
|
-
local args = {...}
|
|
928
|
-
do
|
|
929
|
-
local i = 0
|
|
930
|
-
while i < #boundArgs do
|
|
931
|
-
table.insert(args, i + 1, boundArgs[i + 1])
|
|
932
|
-
i = i + 1
|
|
933
|
-
end
|
|
934
|
-
end
|
|
935
|
-
return fn(
|
|
936
|
-
thisArg,
|
|
937
|
-
__TS__Unpack(args)
|
|
938
|
-
)
|
|
939
|
-
end
|
|
940
|
-
end
|
|
941
|
-
|
|
942
1123
|
function __TS__GeneratorIterator(self)
|
|
943
1124
|
return self
|
|
944
1125
|
end
|
|
@@ -1436,175 +1617,6 @@ function __TS__ParseInt(numberString, base)
|
|
|
1436
1617
|
end
|
|
1437
1618
|
end
|
|
1438
1619
|
|
|
1439
|
-
__TS__PromiseState = __TS__PromiseState or ({})
|
|
1440
|
-
__TS__PromiseState.Pending = 0
|
|
1441
|
-
__TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
|
|
1442
|
-
__TS__PromiseState.Fulfilled = 1
|
|
1443
|
-
__TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
|
|
1444
|
-
__TS__PromiseState.Rejected = 2
|
|
1445
|
-
__TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
|
|
1446
|
-
function __TS__PromiseDeferred(self)
|
|
1447
|
-
local resolve
|
|
1448
|
-
local reject
|
|
1449
|
-
local promise = __TS__New(
|
|
1450
|
-
__TS__Promise,
|
|
1451
|
-
function(____, res, rej)
|
|
1452
|
-
resolve = res
|
|
1453
|
-
reject = rej
|
|
1454
|
-
end
|
|
1455
|
-
)
|
|
1456
|
-
return {promise = promise, resolve = resolve, reject = reject}
|
|
1457
|
-
end
|
|
1458
|
-
function __TS__IsPromiseLike(self, thing)
|
|
1459
|
-
return __TS__InstanceOf(thing, __TS__Promise)
|
|
1460
|
-
end
|
|
1461
|
-
__TS__Promise = __TS__Class()
|
|
1462
|
-
__TS__Promise.name = "__TS__Promise"
|
|
1463
|
-
function __TS__Promise.prototype.____constructor(self, executor)
|
|
1464
|
-
self.state = __TS__PromiseState.Pending
|
|
1465
|
-
self.fulfilledCallbacks = {}
|
|
1466
|
-
self.rejectedCallbacks = {}
|
|
1467
|
-
self.finallyCallbacks = {}
|
|
1468
|
-
do
|
|
1469
|
-
local function ____catch(e)
|
|
1470
|
-
self:reject(e)
|
|
1471
|
-
end
|
|
1472
|
-
local ____try, ____hasReturned = pcall(function()
|
|
1473
|
-
executor(
|
|
1474
|
-
_G,
|
|
1475
|
-
__TS__FunctionBind(self.resolve, self),
|
|
1476
|
-
__TS__FunctionBind(self.reject, self)
|
|
1477
|
-
)
|
|
1478
|
-
end)
|
|
1479
|
-
if not ____try then
|
|
1480
|
-
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
|
1481
|
-
end
|
|
1482
|
-
end
|
|
1483
|
-
end
|
|
1484
|
-
function __TS__Promise.resolve(data)
|
|
1485
|
-
local promise = __TS__New(
|
|
1486
|
-
__TS__Promise,
|
|
1487
|
-
function()
|
|
1488
|
-
end
|
|
1489
|
-
)
|
|
1490
|
-
promise.state = __TS__PromiseState.Fulfilled
|
|
1491
|
-
promise.value = data
|
|
1492
|
-
return promise
|
|
1493
|
-
end
|
|
1494
|
-
function __TS__Promise.reject(reason)
|
|
1495
|
-
local promise = __TS__New(
|
|
1496
|
-
__TS__Promise,
|
|
1497
|
-
function()
|
|
1498
|
-
end
|
|
1499
|
-
)
|
|
1500
|
-
promise.state = __TS__PromiseState.Rejected
|
|
1501
|
-
promise.rejectionReason = reason
|
|
1502
|
-
return promise
|
|
1503
|
-
end
|
|
1504
|
-
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
1505
|
-
local ____TS__PromiseDeferred_result_0 = __TS__PromiseDeferred(_G)
|
|
1506
|
-
local promise = ____TS__PromiseDeferred_result_0.promise
|
|
1507
|
-
local resolve = ____TS__PromiseDeferred_result_0.resolve
|
|
1508
|
-
local reject = ____TS__PromiseDeferred_result_0.reject
|
|
1509
|
-
local isFulfilled = self.state == __TS__PromiseState.Fulfilled
|
|
1510
|
-
local isRejected = self.state == __TS__PromiseState.Rejected
|
|
1511
|
-
if onFulfilled then
|
|
1512
|
-
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
1513
|
-
__TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
|
|
1514
|
-
if isFulfilled then
|
|
1515
|
-
internalCallback(_G, self.value)
|
|
1516
|
-
end
|
|
1517
|
-
else
|
|
1518
|
-
__TS__ArrayPush(
|
|
1519
|
-
self.fulfilledCallbacks,
|
|
1520
|
-
function() return resolve(_G, nil) end
|
|
1521
|
-
)
|
|
1522
|
-
end
|
|
1523
|
-
if onRejected then
|
|
1524
|
-
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
1525
|
-
__TS__ArrayPush(self.rejectedCallbacks, internalCallback)
|
|
1526
|
-
if isRejected then
|
|
1527
|
-
internalCallback(_G, self.rejectionReason)
|
|
1528
|
-
end
|
|
1529
|
-
end
|
|
1530
|
-
if isFulfilled then
|
|
1531
|
-
resolve(_G, self.value)
|
|
1532
|
-
end
|
|
1533
|
-
if isRejected then
|
|
1534
|
-
reject(_G, self.rejectionReason)
|
|
1535
|
-
end
|
|
1536
|
-
return promise
|
|
1537
|
-
end
|
|
1538
|
-
function __TS__Promise.prototype.catch(self, onRejected)
|
|
1539
|
-
return self["then"](self, nil, onRejected)
|
|
1540
|
-
end
|
|
1541
|
-
function __TS__Promise.prototype.finally(self, onFinally)
|
|
1542
|
-
if onFinally then
|
|
1543
|
-
__TS__ArrayPush(self.finallyCallbacks, onFinally)
|
|
1544
|
-
if self.state ~= __TS__PromiseState.Pending then
|
|
1545
|
-
onFinally(_G)
|
|
1546
|
-
end
|
|
1547
|
-
end
|
|
1548
|
-
return self
|
|
1549
|
-
end
|
|
1550
|
-
function __TS__Promise.prototype.resolve(self, data)
|
|
1551
|
-
if self.state == __TS__PromiseState.Pending then
|
|
1552
|
-
self.state = __TS__PromiseState.Fulfilled
|
|
1553
|
-
self.value = data
|
|
1554
|
-
for ____, callback in ipairs(self.fulfilledCallbacks) do
|
|
1555
|
-
callback(_G, data)
|
|
1556
|
-
end
|
|
1557
|
-
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1558
|
-
callback(_G)
|
|
1559
|
-
end
|
|
1560
|
-
end
|
|
1561
|
-
end
|
|
1562
|
-
function __TS__Promise.prototype.reject(self, reason)
|
|
1563
|
-
if self.state == __TS__PromiseState.Pending then
|
|
1564
|
-
self.state = __TS__PromiseState.Rejected
|
|
1565
|
-
self.rejectionReason = reason
|
|
1566
|
-
for ____, callback in ipairs(self.rejectedCallbacks) do
|
|
1567
|
-
callback(_G, reason)
|
|
1568
|
-
end
|
|
1569
|
-
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1570
|
-
callback(_G)
|
|
1571
|
-
end
|
|
1572
|
-
end
|
|
1573
|
-
end
|
|
1574
|
-
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
1575
|
-
return function(____, value)
|
|
1576
|
-
do
|
|
1577
|
-
local function ____catch(e)
|
|
1578
|
-
reject(_G, e)
|
|
1579
|
-
end
|
|
1580
|
-
local ____try, ____hasReturned = pcall(function()
|
|
1581
|
-
self:handleCallbackData(
|
|
1582
|
-
f(_G, value),
|
|
1583
|
-
resolve,
|
|
1584
|
-
reject
|
|
1585
|
-
)
|
|
1586
|
-
end)
|
|
1587
|
-
if not ____try then
|
|
1588
|
-
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
|
1589
|
-
end
|
|
1590
|
-
end
|
|
1591
|
-
end
|
|
1592
|
-
end
|
|
1593
|
-
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
|
|
1594
|
-
if __TS__IsPromiseLike(_G, data) then
|
|
1595
|
-
local nextpromise = data
|
|
1596
|
-
if nextpromise.state == __TS__PromiseState.Fulfilled then
|
|
1597
|
-
resolve(_G, nextpromise.value)
|
|
1598
|
-
elseif nextpromise.state == __TS__PromiseState.Rejected then
|
|
1599
|
-
reject(_G, nextpromise.rejectionReason)
|
|
1600
|
-
else
|
|
1601
|
-
data["then"](data, resolve, reject)
|
|
1602
|
-
end
|
|
1603
|
-
else
|
|
1604
|
-
resolve(_G, data)
|
|
1605
|
-
end
|
|
1606
|
-
end
|
|
1607
|
-
|
|
1608
1620
|
function __TS__PromiseAll(iterable)
|
|
1609
1621
|
local results = {}
|
|
1610
1622
|
local toResolve = {}
|
|
@@ -24,7 +24,7 @@ function transformFunctionPrototypeCall(context, node) {
|
|
|
24
24
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.FunctionBind, node, caller, ...params);
|
|
25
25
|
case "call":
|
|
26
26
|
return lua.createCallExpression(caller, params, node);
|
|
27
|
-
|
|
27
|
+
case "toString":
|
|
28
28
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(expression.name, "function", expressionName));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -42,7 +42,10 @@ function transformFunctionProperty(context, node) {
|
|
|
42
42
|
return contextType === function_context_1.ContextType.NonVoid
|
|
43
43
|
? lua.createBinaryExpression(nparams, lua.createNumericLiteral(1), lua.SyntaxKind.SubtractionOperator)
|
|
44
44
|
: nparams;
|
|
45
|
-
|
|
45
|
+
case "arguments":
|
|
46
|
+
case "caller":
|
|
47
|
+
case "displayName":
|
|
48
|
+
case "name":
|
|
46
49
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "function", node.name.text));
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -28,7 +28,7 @@ function transformBuiltinPropertyAccessExpression(context, node) {
|
|
|
28
28
|
if ((0, typescript_1.isArrayType)(context, ownerType)) {
|
|
29
29
|
return (0, array_1.transformArrayProperty)(context, node);
|
|
30
30
|
}
|
|
31
|
-
if ((0, typescript_1.isFunctionType)(
|
|
31
|
+
if ((0, typescript_1.isFunctionType)(ownerType)) {
|
|
32
32
|
return (0, function_1.transformFunctionProperty)(context, node);
|
|
33
33
|
}
|
|
34
34
|
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
|
|
@@ -115,7 +115,7 @@ function transformBuiltinCallExpression(context, node, isOptionalCall) {
|
|
|
115
115
|
return unsupportedOptionalCall();
|
|
116
116
|
return (0, array_1.transformArrayPrototypeCall)(context, node);
|
|
117
117
|
}
|
|
118
|
-
if ((0, typescript_1.isFunctionType)(
|
|
118
|
+
if ((0, typescript_1.isFunctionType)(ownerType) && (0, typescript_1.hasStandardLibrarySignature)(context, node)) {
|
|
119
119
|
if (isOptionalCall)
|
|
120
120
|
return unsupportedOptionalCall();
|
|
121
121
|
return (0, function_1.transformFunctionPrototypeCall)(context, node);
|
|
@@ -34,6 +34,9 @@ export declare const invalidRangeControlVariable: ((node: ts.Node, ...args: any[
|
|
|
34
34
|
export declare const invalidMultiIterableWithoutDestructuring: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
35
35
|
code: number;
|
|
36
36
|
};
|
|
37
|
+
export declare const invalidPairsIterableWithoutDestructuring: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
38
|
+
code: number;
|
|
39
|
+
};
|
|
37
40
|
export declare const unsupportedAccessorInObjectLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
38
41
|
code: number;
|
|
39
42
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableSetExpression = exports.invalidTableDeleteExpression = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
3
|
+
exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidTableSetExpression = exports.invalidTableDeleteExpression = exports.invalidTableExtensionUse = exports.invalidOperatorMappingUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
@@ -36,6 +36,7 @@ exports.invalidRangeUse = createErrorDiagnosticFactory("$range can only be used
|
|
|
36
36
|
exports.invalidVarargUse = createErrorDiagnosticFactory("$vararg can only be used in a spread element ('...$vararg') in global scope.");
|
|
37
37
|
exports.invalidRangeControlVariable = createErrorDiagnosticFactory("For loop using $range must declare a single control variable.");
|
|
38
38
|
exports.invalidMultiIterableWithoutDestructuring = createErrorDiagnosticFactory("LuaIterable with a LuaMultiReturn return value type must be destructured.");
|
|
39
|
+
exports.invalidPairsIterableWithoutDestructuring = createErrorDiagnosticFactory("LuaPairsIterable type must be destructured in a for...of statement.");
|
|
39
40
|
exports.unsupportedAccessorInObjectLiteral = createErrorDiagnosticFactory("Accessors in object literal are not supported.");
|
|
40
41
|
exports.unsupportedRightShiftOperator = createErrorDiagnosticFactory("Right shift operator is not supported for target Lua 5.3. Use `>>>` instead.");
|
|
41
42
|
const getLuaTargetName = (version) => (version === CompilerOptions_1.LuaTarget.LuaJIT ? "LuaJIT" : `Lua ${version}`);
|
|
@@ -6,6 +6,7 @@ export declare enum ExtensionKind {
|
|
|
6
6
|
RangeFunction = "RangeFunction",
|
|
7
7
|
VarargConstant = "VarargConstant",
|
|
8
8
|
IterableType = "IterableType",
|
|
9
|
+
PairsIterableType = "PairsIterableType",
|
|
9
10
|
AdditionOperatorType = "AdditionOperatorType",
|
|
10
11
|
AdditionOperatorMethodType = "AdditionOperatorMethodType",
|
|
11
12
|
SubtractionOperatorType = "SubtractionOperatorType",
|
|
@@ -53,4 +54,5 @@ export declare enum ExtensionKind {
|
|
|
53
54
|
TableSetMethodType = "TableSetMethodType"
|
|
54
55
|
}
|
|
55
56
|
export declare function isExtensionType(type: ts.Type, extensionKind: ExtensionKind): boolean;
|
|
57
|
+
export declare function getExtensionKinds(type: ts.Type): ExtensionKind[];
|
|
56
58
|
export declare function isExtensionValue(context: TransformationContext, symbol: ts.Symbol, extensionKind: ExtensionKind): boolean;
|