typescript-to-lua 1.8.2 → 1.10.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/CompilerOptions.d.ts +1 -0
- package/dist/CompilerOptions.js +1 -0
- package/dist/LuaAST.d.ts +43 -37
- package/dist/LuaAST.js +48 -38
- package/dist/LuaLib.d.ts +12 -6
- package/dist/LuaLib.js +31 -21
- package/dist/LuaPrinter.d.ts +1 -0
- package/dist/LuaPrinter.js +10 -4
- package/dist/lualib/5.0/ArrayConcat.lua +22 -0
- package/dist/lualib/{ArrayEntries.lua → 5.0/ArrayEntries.lua} +0 -0
- package/dist/lualib/5.0/ArrayEvery.lua +8 -0
- package/dist/lualib/5.0/ArrayFilter.lua +11 -0
- package/dist/lualib/5.0/ArrayFind.lua +9 -0
- package/dist/lualib/5.0/ArrayFindIndex.lua +8 -0
- package/dist/lualib/5.0/ArrayFlat.lua +27 -0
- package/dist/lualib/5.0/ArrayFlatMap.lua +17 -0
- package/dist/lualib/5.0/ArrayForEach.lua +5 -0
- package/dist/lualib/5.0/ArrayFrom.lua +29 -0
- package/dist/lualib/5.0/ArrayIncludes.lua +19 -0
- package/dist/lualib/5.0/ArrayIndexOf.lua +24 -0
- package/dist/lualib/{ArrayIsArray.lua → 5.0/ArrayIsArray.lua} +0 -0
- package/dist/lualib/5.0/ArrayJoin.lua +10 -0
- package/dist/lualib/5.0/ArrayMap.lua +7 -0
- package/dist/lualib/5.0/ArrayPush.lua +9 -0
- package/dist/lualib/5.0/ArrayPushArray.lua +8 -0
- package/dist/lualib/5.0/ArrayReduce.lua +23 -0
- package/dist/lualib/5.0/ArrayReduceRight.lua +23 -0
- package/dist/lualib/5.0/ArrayReverse.lua +12 -0
- package/dist/lualib/5.0/ArraySetLength.lua +12 -0
- package/dist/lualib/5.0/ArraySlice.lua +43 -0
- package/dist/lualib/5.0/ArraySome.lua +8 -0
- package/dist/lualib/{ArraySort.lua → 5.0/ArraySort.lua} +0 -0
- package/dist/lualib/5.0/ArraySplice.lua +77 -0
- package/dist/lualib/5.0/ArrayToObject.lua +7 -0
- package/dist/lualib/5.0/ArrayUnshift.lua +14 -0
- package/dist/lualib/{Await.lua → 5.0/Await.lua} +0 -0
- package/dist/lualib/{Class.lua → 5.0/Class.lua} +0 -0
- package/dist/lualib/{ClassExtends.lua → 5.0/ClassExtends.lua} +0 -0
- package/dist/lualib/{CloneDescriptor.lua → 5.0/CloneDescriptor.lua} +0 -0
- package/dist/lualib/5.0/CountVarargs.lua +4 -0
- package/dist/lualib/5.0/Decorate.lua +36 -0
- package/dist/lualib/{DecorateParam.lua → 5.0/DecorateParam.lua} +0 -0
- package/dist/lualib/5.0/DelegatedYield.lua +34 -0
- package/dist/lualib/{Delete.lua → 5.0/Delete.lua} +0 -0
- package/dist/lualib/5.0/Error.lua +85 -0
- package/dist/lualib/5.0/FunctionBind.lua +11 -0
- package/dist/lualib/5.0/Generator.lua +34 -0
- package/dist/lualib/{InstanceOf.lua → 5.0/InstanceOf.lua} +0 -0
- package/dist/lualib/{InstanceOfObject.lua → 5.0/InstanceOfObject.lua} +0 -0
- package/dist/lualib/5.0/Iterator.lua +40 -0
- package/dist/lualib/5.0/LuaIteratorSpread.lua +9 -0
- package/dist/lualib/{Map.lua → 5.0/Map.lua} +0 -0
- package/dist/lualib/5.0/Match.lua +13 -0
- package/dist/lualib/{MathAtan2.lua → 5.0/MathAtan2.lua} +0 -0
- package/dist/lualib/5.0/MathModf.lua +10 -0
- package/dist/lualib/{MathSign.lua → 5.0/MathSign.lua} +0 -0
- package/dist/lualib/5.0/Modulo50.lua +3 -0
- package/dist/lualib/5.0/New.lua +5 -0
- package/dist/lualib/5.0/Number.lua +26 -0
- package/dist/lualib/5.0/NumberIsFinite.lua +3 -0
- package/dist/lualib/{NumberIsNaN.lua → 5.0/NumberIsNaN.lua} +0 -0
- package/dist/lualib/5.0/NumberToString.lua +47 -0
- package/dist/lualib/5.0/ObjectAssign.lua +10 -0
- package/dist/lualib/{ObjectDefineProperty.lua → 5.0/ObjectDefineProperty.lua} +0 -0
- package/dist/lualib/{ObjectEntries.lua → 5.0/ObjectEntries.lua} +0 -0
- package/dist/lualib/{ObjectFromEntries.lua → 5.0/ObjectFromEntries.lua} +0 -0
- package/dist/lualib/{ObjectGetOwnPropertyDescriptor.lua → 5.0/ObjectGetOwnPropertyDescriptor.lua} +0 -0
- package/dist/lualib/{ObjectGetOwnPropertyDescriptors.lua → 5.0/ObjectGetOwnPropertyDescriptors.lua} +0 -0
- package/dist/lualib/{ObjectKeys.lua → 5.0/ObjectKeys.lua} +0 -0
- package/dist/lualib/{ObjectRest.lua → 5.0/ObjectRest.lua} +0 -0
- package/dist/lualib/{ObjectValues.lua → 5.0/ObjectValues.lua} +0 -0
- package/dist/lualib/5.0/ParseFloat.lua +18 -0
- package/dist/lualib/5.0/ParseInt.lua +49 -0
- package/dist/lualib/5.0/Promise.lua +176 -0
- package/dist/lualib/{PromiseAll.lua → 5.0/PromiseAll.lua} +0 -0
- package/dist/lualib/{PromiseAllSettled.lua → 5.0/PromiseAllSettled.lua} +0 -0
- package/dist/lualib/5.0/PromiseAny.lua +41 -0
- package/dist/lualib/5.0/PromiseRace.lua +28 -0
- package/dist/lualib/{Set.lua → 5.0/Set.lua} +0 -0
- package/dist/lualib/{SetDescriptor.lua → 5.0/SetDescriptor.lua} +0 -0
- package/dist/lualib/5.0/SourceMapTraceBack.lua +56 -0
- package/dist/lualib/5.0/SparseArrayNew.lua +5 -0
- package/dist/lualib/5.0/SparseArrayPush.lua +9 -0
- package/dist/lualib/5.0/SparseArraySpread.lua +3 -0
- package/dist/lualib/5.0/Spread.lua +15 -0
- package/dist/lualib/5.0/StringAccess.lua +5 -0
- package/dist/lualib/{StringCharAt.lua → 5.0/StringCharAt.lua} +0 -0
- package/dist/lualib/{StringCharCodeAt.lua → 5.0/StringCharCodeAt.lua} +0 -0
- package/dist/lualib/5.0/StringEndsWith.lua +10 -0
- package/dist/lualib/{StringIncludes.lua → 5.0/StringIncludes.lua} +0 -0
- package/dist/lualib/5.0/StringPadEnd.lua +26 -0
- package/dist/lualib/5.0/StringPadStart.lua +26 -0
- package/dist/lualib/{StringReplace.lua → 5.0/StringReplace.lua} +0 -0
- package/dist/lualib/5.0/StringReplaceAll.lua +42 -0
- package/dist/lualib/{StringSlice.lua → 5.0/StringSlice.lua} +0 -0
- package/dist/lualib/5.0/StringSplit.lua +36 -0
- package/dist/lualib/5.0/StringStartsWith.lua +10 -0
- package/dist/lualib/{StringSubstr.lua → 5.0/StringSubstr.lua} +0 -0
- package/dist/lualib/{StringSubstring.lua → 5.0/StringSubstring.lua} +0 -0
- package/dist/lualib/{StringTrim.lua → 5.0/StringTrim.lua} +0 -0
- package/dist/lualib/{StringTrimEnd.lua → 5.0/StringTrimEnd.lua} +0 -0
- package/dist/lualib/{StringTrimStart.lua → 5.0/StringTrimStart.lua} +0 -0
- package/dist/lualib/{Symbol.lua → 5.0/Symbol.lua} +0 -0
- package/dist/lualib/{SymbolRegistry.lua → 5.0/SymbolRegistry.lua} +0 -0
- package/dist/lualib/{TypeOf.lua → 5.0/TypeOf.lua} +0 -0
- package/dist/lualib/5.0/Unpack.lua +1 -0
- package/dist/lualib/{WeakMap.lua → 5.0/WeakMap.lua} +0 -0
- package/dist/lualib/{WeakSet.lua → 5.0/WeakSet.lua} +0 -0
- package/dist/lualib/5.0/lualib_bundle.lua +2574 -0
- package/dist/lualib/5.0/lualib_module_info.json +672 -0
- package/dist/lualib/{ArrayConcat.lua → universal/ArrayConcat.lua} +0 -0
- package/dist/lualib/universal/ArrayEntries.lua +13 -0
- package/dist/lualib/{ArrayEvery.lua → universal/ArrayEvery.lua} +0 -0
- package/dist/lualib/{ArrayFilter.lua → universal/ArrayFilter.lua} +0 -0
- package/dist/lualib/{ArrayFind.lua → universal/ArrayFind.lua} +0 -0
- package/dist/lualib/{ArrayFindIndex.lua → universal/ArrayFindIndex.lua} +0 -0
- package/dist/lualib/{ArrayFlat.lua → universal/ArrayFlat.lua} +0 -0
- package/dist/lualib/{ArrayFlatMap.lua → universal/ArrayFlatMap.lua} +0 -0
- package/dist/lualib/{ArrayForEach.lua → universal/ArrayForEach.lua} +0 -0
- package/dist/lualib/{ArrayFrom.lua → universal/ArrayFrom.lua} +0 -0
- package/dist/lualib/{ArrayIncludes.lua → universal/ArrayIncludes.lua} +0 -0
- package/dist/lualib/{ArrayIndexOf.lua → universal/ArrayIndexOf.lua} +0 -0
- package/dist/lualib/universal/ArrayIsArray.lua +3 -0
- package/dist/lualib/{ArrayJoin.lua → universal/ArrayJoin.lua} +0 -0
- package/dist/lualib/{ArrayMap.lua → universal/ArrayMap.lua} +0 -0
- package/dist/lualib/{ArrayPush.lua → universal/ArrayPush.lua} +0 -0
- package/dist/lualib/{ArrayPushArray.lua → universal/ArrayPushArray.lua} +0 -0
- package/dist/lualib/{ArrayReduce.lua → universal/ArrayReduce.lua} +1 -1
- package/dist/lualib/{ArrayReduceRight.lua → universal/ArrayReduceRight.lua} +1 -1
- package/dist/lualib/{ArrayReverse.lua → universal/ArrayReverse.lua} +0 -0
- package/dist/lualib/{ArraySetLength.lua → universal/ArraySetLength.lua} +0 -0
- package/dist/lualib/{ArraySlice.lua → universal/ArraySlice.lua} +0 -0
- package/dist/lualib/{ArraySome.lua → universal/ArraySome.lua} +0 -0
- package/dist/lualib/universal/ArraySort.lua +11 -0
- package/dist/lualib/{ArraySplice.lua → universal/ArraySplice.lua} +1 -1
- package/dist/lualib/{ArrayToObject.lua → universal/ArrayToObject.lua} +0 -0
- package/dist/lualib/{ArrayUnshift.lua → universal/ArrayUnshift.lua} +0 -0
- package/dist/lualib/universal/Await.lua +54 -0
- package/dist/lualib/universal/Class.lua +6 -0
- package/dist/lualib/universal/ClassExtends.lua +24 -0
- package/dist/lualib/universal/CloneDescriptor.lua +28 -0
- package/dist/lualib/universal/CountVarargs.lua +3 -0
- package/dist/lualib/{Decorate.lua → universal/Decorate.lua} +0 -0
- package/dist/lualib/universal/DecorateParam.lua +3 -0
- package/dist/lualib/{DelegatedYield.lua → universal/DelegatedYield.lua} +0 -0
- package/dist/lualib/universal/Delete.lua +19 -0
- package/dist/lualib/{Error.lua → universal/Error.lua} +7 -2
- package/dist/lualib/{FunctionBind.lua → universal/FunctionBind.lua} +0 -0
- package/dist/lualib/{Generator.lua → universal/Generator.lua} +2 -9
- package/dist/lualib/universal/InstanceOf.lua +18 -0
- package/dist/lualib/universal/InstanceOfObject.lua +4 -0
- package/dist/lualib/{Iterator.lua → universal/Iterator.lua} +0 -0
- package/dist/lualib/{LuaIteratorSpread.lua → universal/LuaIteratorSpread.lua} +0 -0
- package/dist/lualib/universal/Map.lua +140 -0
- package/dist/lualib/universal/Match.lua +1 -0
- package/dist/lualib/universal/MathAtan2.lua +1 -0
- package/dist/lualib/universal/MathModf.lua +1 -0
- package/dist/lualib/universal/MathSign.lua +8 -0
- package/dist/lualib/universal/Modulo50.lua +3 -0
- package/dist/lualib/{New.lua → universal/New.lua} +0 -0
- package/dist/lualib/{Number.lua → universal/Number.lua} +0 -0
- package/dist/lualib/{NumberIsFinite.lua → universal/NumberIsFinite.lua} +0 -0
- package/dist/lualib/universal/NumberIsNaN.lua +3 -0
- package/dist/lualib/{NumberToString.lua → universal/NumberToString.lua} +1 -1
- package/dist/lualib/{ObjectAssign.lua → universal/ObjectAssign.lua} +0 -0
- package/dist/lualib/universal/ObjectDefineProperty.lua +59 -0
- package/dist/lualib/universal/ObjectEntries.lua +9 -0
- package/dist/lualib/universal/ObjectFromEntries.lua +20 -0
- package/dist/lualib/universal/ObjectGetOwnPropertyDescriptor.lua +10 -0
- package/dist/lualib/universal/ObjectGetOwnPropertyDescriptors.lua +7 -0
- package/dist/lualib/universal/ObjectKeys.lua +9 -0
- package/dist/lualib/universal/ObjectRest.lua +9 -0
- package/dist/lualib/universal/ObjectValues.lua +9 -0
- package/dist/lualib/{ParseFloat.lua → universal/ParseFloat.lua} +2 -2
- package/dist/lualib/{ParseInt.lua → universal/ParseInt.lua} +7 -7
- package/dist/lualib/{Promise.lua → universal/Promise.lua} +0 -0
- package/dist/lualib/universal/PromiseAll.lua +44 -0
- package/dist/lualib/universal/PromiseAllSettled.lua +48 -0
- package/dist/lualib/{PromiseAny.lua → universal/PromiseAny.lua} +0 -0
- package/dist/lualib/{PromiseRace.lua → universal/PromiseRace.lua} +0 -0
- package/dist/lualib/universal/Set.lua +130 -0
- package/dist/lualib/universal/SetDescriptor.lua +79 -0
- package/dist/lualib/{SourceMapTraceBack.lua → universal/SourceMapTraceBack.lua} +3 -1
- package/dist/lualib/{SparseArrayNew.lua → universal/SparseArrayNew.lua} +1 -1
- package/dist/lualib/{SparseArrayPush.lua → universal/SparseArrayPush.lua} +1 -1
- package/dist/lualib/{SparseArraySpread.lua → universal/SparseArraySpread.lua} +0 -0
- package/dist/lualib/{Spread.lua → universal/Spread.lua} +0 -0
- package/dist/lualib/{StringAccess.lua → universal/StringAccess.lua} +0 -0
- package/dist/lualib/universal/StringCharAt.lua +9 -0
- package/dist/lualib/universal/StringCharCodeAt.lua +13 -0
- package/dist/lualib/{StringEndsWith.lua → universal/StringEndsWith.lua} +0 -0
- package/dist/lualib/universal/StringIncludes.lua +9 -0
- package/dist/lualib/{StringPadEnd.lua → universal/StringPadEnd.lua} +0 -0
- package/dist/lualib/{StringPadStart.lua → universal/StringPadStart.lua} +0 -0
- package/dist/lualib/universal/StringReplace.lua +20 -0
- package/dist/lualib/{StringReplaceAll.lua → universal/StringReplaceAll.lua} +0 -0
- package/dist/lualib/universal/StringSlice.lua +15 -0
- package/dist/lualib/{StringSplit.lua → universal/StringSplit.lua} +0 -0
- package/dist/lualib/{StringStartsWith.lua → universal/StringStartsWith.lua} +0 -0
- package/dist/lualib/universal/StringSubstr.lua +15 -0
- package/dist/lualib/universal/StringSubstring.lua +17 -0
- package/dist/lualib/universal/StringTrim.lua +4 -0
- package/dist/lualib/universal/StringTrimEnd.lua +4 -0
- package/dist/lualib/universal/StringTrimStart.lua +4 -0
- package/dist/lualib/universal/Symbol.lua +15 -0
- package/dist/lualib/universal/SymbolRegistry.lua +17 -0
- package/dist/lualib/universal/TypeOf.lua +10 -0
- package/dist/lualib/{Unpack.lua → universal/Unpack.lua} +0 -0
- package/dist/lualib/universal/WeakMap.lua +45 -0
- package/dist/lualib/universal/WeakSet.lua +41 -0
- package/dist/lualib/{lualib_bundle.lua → universal/lualib_bundle.lua} +53 -37
- package/dist/lualib/{lualib_module_info.json → universal/lualib_module_info.json} +49 -4
- package/dist/lualib-build/plugin.js +12 -2
- package/dist/transformation/builtins/array.d.ts +1 -1
- package/dist/transformation/builtins/array.js +12 -2
- package/dist/transformation/builtins/function.js +4 -2
- package/dist/transformation/builtins/index.js +11 -3
- package/dist/transformation/builtins/string.d.ts +1 -1
- package/dist/transformation/builtins/string.js +8 -1
- package/dist/transformation/utils/diagnostics.d.ts +5 -4
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/lua-ast.js +3 -1
- package/dist/transformation/utils/typescript/index.js +2 -2
- package/dist/transformation/visitors/access.js +11 -0
- package/dist/transformation/visitors/binary-expression/bit.js +4 -2
- package/dist/transformation/visitors/binary-expression/index.js +4 -0
- package/dist/transformation/visitors/break-continue.js +4 -2
- package/dist/transformation/visitors/class/index.js +9 -4
- package/dist/transformation/visitors/class/members/fields.js +6 -2
- package/dist/transformation/visitors/class/members/method.js +4 -2
- package/dist/transformation/visitors/conditional.d.ts +1 -0
- package/dist/transformation/visitors/conditional.js +12 -1
- package/dist/transformation/visitors/errors.js +4 -2
- package/dist/transformation/visitors/function.js +2 -1
- package/dist/transformation/visitors/identifier.js +4 -1
- package/dist/transformation/visitors/language-extensions/operators.js +2 -1
- package/dist/transformation/visitors/literal.js +12 -4
- package/dist/transformation/visitors/loops/do-while.js +5 -0
- package/dist/transformation/visitors/modules/export.js +1 -1
- package/dist/transformation/visitors/spread.js +4 -1
- package/dist/transformation/visitors/typescript.js +1 -0
- package/dist/transpilation/bundle.js +15 -6
- package/dist/transpilation/resolve.js +3 -3
- package/dist/transpilation/transpiler.js +3 -1
- package/package.json +18 -18
- package/language-extensions/index.d.ts +0 -676
|
@@ -255,11 +255,15 @@ local function __TS__ArrayPushArray(self, items)
|
|
|
255
255
|
return len
|
|
256
256
|
end
|
|
257
257
|
|
|
258
|
+
local function __TS__CountVarargs(...)
|
|
259
|
+
return select("#", ...)
|
|
260
|
+
end
|
|
261
|
+
|
|
258
262
|
local function __TS__ArrayReduce(self, callbackFn, ...)
|
|
259
263
|
local len = #self
|
|
260
264
|
local k = 0
|
|
261
265
|
local accumulator = nil
|
|
262
|
-
if
|
|
266
|
+
if __TS__CountVarargs(...) ~= 0 then
|
|
263
267
|
accumulator = ...
|
|
264
268
|
elseif len > 0 then
|
|
265
269
|
accumulator = self[1]
|
|
@@ -283,7 +287,7 @@ local function __TS__ArrayReduceRight(self, callbackFn, ...)
|
|
|
283
287
|
local len = #self
|
|
284
288
|
local k = len - 1
|
|
285
289
|
local accumulator = nil
|
|
286
|
-
if
|
|
290
|
+
if __TS__CountVarargs(...) ~= 0 then
|
|
287
291
|
accumulator = ...
|
|
288
292
|
elseif len > 0 then
|
|
289
293
|
accumulator = self[k + 1]
|
|
@@ -399,7 +403,7 @@ end
|
|
|
399
403
|
local function __TS__ArraySplice(self, ...)
|
|
400
404
|
local args = {...}
|
|
401
405
|
local len = #self
|
|
402
|
-
local actualArgumentCount =
|
|
406
|
+
local actualArgumentCount = __TS__CountVarargs(...)
|
|
403
407
|
local start = args[1]
|
|
404
408
|
local deleteCount = args[2]
|
|
405
409
|
if start < 0 then
|
|
@@ -1016,6 +1020,16 @@ local function __TS__DecorateParam(paramIndex, decorator)
|
|
|
1016
1020
|
return function(____, target, key) return decorator(nil, target, key, paramIndex) end
|
|
1017
1021
|
end
|
|
1018
1022
|
|
|
1023
|
+
local function __TS__StringIncludes(self, searchString, position)
|
|
1024
|
+
if not position then
|
|
1025
|
+
position = 1
|
|
1026
|
+
else
|
|
1027
|
+
position = position + 1
|
|
1028
|
+
end
|
|
1029
|
+
local index = string.find(self, searchString, position, true)
|
|
1030
|
+
return index ~= nil
|
|
1031
|
+
end
|
|
1032
|
+
|
|
1019
1033
|
local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
|
1020
1034
|
do
|
|
1021
1035
|
local function getErrorStack(self, constructor)
|
|
@@ -1030,13 +1044,18 @@ do
|
|
|
1030
1044
|
break
|
|
1031
1045
|
end
|
|
1032
1046
|
end
|
|
1033
|
-
|
|
1047
|
+
if __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
|
1048
|
+
return debug.traceback(("[Level " .. tostring(level)) .. "]")
|
|
1049
|
+
else
|
|
1050
|
+
return debug.traceback(nil, level)
|
|
1051
|
+
end
|
|
1034
1052
|
end
|
|
1035
1053
|
local function wrapErrorToString(self, getDescription)
|
|
1036
1054
|
return function(self)
|
|
1037
1055
|
local description = getDescription(self)
|
|
1038
1056
|
local caller = debug.getinfo(3, "f")
|
|
1039
|
-
|
|
1057
|
+
local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
|
|
1058
|
+
if isClassicLua or caller and caller.func ~= error then
|
|
1040
1059
|
return description
|
|
1041
1060
|
else
|
|
1042
1061
|
return (tostring(description) .. "\n") .. self.stack
|
|
@@ -1185,16 +1204,9 @@ do
|
|
|
1185
1204
|
function __TS__Generator(fn)
|
|
1186
1205
|
return function(...)
|
|
1187
1206
|
local args = {...}
|
|
1188
|
-
local argsLength =
|
|
1207
|
+
local argsLength = __TS__CountVarargs(...)
|
|
1189
1208
|
return {
|
|
1190
|
-
____coroutine = coroutine.create(function()
|
|
1191
|
-
local ____fn_1 = fn
|
|
1192
|
-
local ____unpack_0 = unpack
|
|
1193
|
-
if ____unpack_0 == nil then
|
|
1194
|
-
____unpack_0 = table.unpack
|
|
1195
|
-
end
|
|
1196
|
-
return ____fn_1(____unpack_0(args, 1, argsLength))
|
|
1197
|
-
end),
|
|
1209
|
+
____coroutine = coroutine.create(function() return fn(__TS__Unpack(args, 1, argsLength)) end),
|
|
1198
1210
|
[Symbol.iterator] = generatorIterator,
|
|
1199
1211
|
next = generatorNext
|
|
1200
1212
|
}
|
|
@@ -1358,8 +1370,12 @@ do
|
|
|
1358
1370
|
Map[Symbol.species] = Map
|
|
1359
1371
|
end
|
|
1360
1372
|
|
|
1373
|
+
local __TS__Match = string.match
|
|
1374
|
+
|
|
1361
1375
|
local __TS__MathAtan2 = math.atan2 or math.atan
|
|
1362
1376
|
|
|
1377
|
+
local __TS__MathModf = math.modf
|
|
1378
|
+
|
|
1363
1379
|
local function __TS__MathSign(val)
|
|
1364
1380
|
if val > 0 then
|
|
1365
1381
|
return 1
|
|
@@ -1369,6 +1385,10 @@ local function __TS__MathSign(val)
|
|
|
1369
1385
|
return 0
|
|
1370
1386
|
end
|
|
1371
1387
|
|
|
1388
|
+
local function __TS__Modulo50(a, b)
|
|
1389
|
+
return a - math.floor(a / b) * b
|
|
1390
|
+
end
|
|
1391
|
+
|
|
1372
1392
|
local function __TS__Number(value)
|
|
1373
1393
|
local valueType = type(value)
|
|
1374
1394
|
if valueType == "number" then
|
|
@@ -1415,7 +1435,7 @@ do
|
|
|
1415
1435
|
if radix < 2 or radix > 36 then
|
|
1416
1436
|
error("toString() radix argument must be between 2 and 36", 0)
|
|
1417
1437
|
end
|
|
1418
|
-
local integer, fraction =
|
|
1438
|
+
local integer, fraction = __TS__MathModf(math.abs(self))
|
|
1419
1439
|
local result = ""
|
|
1420
1440
|
if radix == 8 then
|
|
1421
1441
|
result = string.format("%o", integer)
|
|
@@ -1571,7 +1591,7 @@ local function __TS__ObjectValues(obj)
|
|
|
1571
1591
|
end
|
|
1572
1592
|
|
|
1573
1593
|
local function __TS__ParseFloat(numberString)
|
|
1574
|
-
local infinityMatch =
|
|
1594
|
+
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1575
1595
|
if infinityMatch then
|
|
1576
1596
|
local ____temp_0
|
|
1577
1597
|
if __TS__StringAccess(infinityMatch, 0) == "-" then
|
|
@@ -1581,7 +1601,7 @@ local function __TS__ParseFloat(numberString)
|
|
|
1581
1601
|
end
|
|
1582
1602
|
return ____temp_0
|
|
1583
1603
|
end
|
|
1584
|
-
local number = tonumber(
|
|
1604
|
+
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1585
1605
|
local ____number_1 = number
|
|
1586
1606
|
if ____number_1 == nil then
|
|
1587
1607
|
____number_1 = 0 / 0
|
|
@@ -1629,16 +1649,16 @@ do
|
|
|
1629
1649
|
function __TS__ParseInt(numberString, base)
|
|
1630
1650
|
if base == nil then
|
|
1631
1651
|
base = 10
|
|
1632
|
-
local hexMatch =
|
|
1652
|
+
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1633
1653
|
if hexMatch then
|
|
1634
1654
|
base = 16
|
|
1635
|
-
local
|
|
1636
|
-
if
|
|
1637
|
-
|
|
1655
|
+
local ____TS__Match_result__0_0
|
|
1656
|
+
if __TS__Match(hexMatch, "-") then
|
|
1657
|
+
____TS__Match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
|
|
1638
1658
|
else
|
|
1639
|
-
|
|
1659
|
+
____TS__Match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
|
|
1640
1660
|
end
|
|
1641
|
-
numberString =
|
|
1661
|
+
numberString = ____TS__Match_result__0_0
|
|
1642
1662
|
end
|
|
1643
1663
|
end
|
|
1644
1664
|
if base < 2 or base > 36 then
|
|
@@ -1653,7 +1673,7 @@ do
|
|
|
1653
1673
|
local allowedDigits = ____temp_1
|
|
1654
1674
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1655
1675
|
local number = tonumber(
|
|
1656
|
-
|
|
1676
|
+
__TS__Match(numberString, pattern),
|
|
1657
1677
|
base
|
|
1658
1678
|
)
|
|
1659
1679
|
if number == nil then
|
|
@@ -1965,13 +1985,13 @@ end
|
|
|
1965
1985
|
|
|
1966
1986
|
local function __TS__SparseArrayNew(...)
|
|
1967
1987
|
local sparseArray = {...}
|
|
1968
|
-
sparseArray.sparseLength =
|
|
1988
|
+
sparseArray.sparseLength = __TS__CountVarargs(...)
|
|
1969
1989
|
return sparseArray
|
|
1970
1990
|
end
|
|
1971
1991
|
|
|
1972
1992
|
local function __TS__SparseArrayPush(sparseArray, ...)
|
|
1973
1993
|
local args = {...}
|
|
1974
|
-
local argsLen =
|
|
1994
|
+
local argsLen = __TS__CountVarargs(...)
|
|
1975
1995
|
local listLen = sparseArray.sparseLength
|
|
1976
1996
|
for i = 1, argsLen do
|
|
1977
1997
|
sparseArray[listLen + i] = args[i]
|
|
@@ -2086,6 +2106,8 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2086
2106
|
local trace
|
|
2087
2107
|
if thread == nil and message == nil and level == nil then
|
|
2088
2108
|
trace = originalTraceback()
|
|
2109
|
+
elseif __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
|
2110
|
+
trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. message)
|
|
2089
2111
|
else
|
|
2090
2112
|
trace = originalTraceback(thread, message, level)
|
|
2091
2113
|
end
|
|
@@ -2111,7 +2133,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2111
2133
|
local function stringReplacer(____, file, line)
|
|
2112
2134
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2113
2135
|
if fileSourceMap and fileSourceMap[line] then
|
|
2114
|
-
local chunkName =
|
|
2136
|
+
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
2115
2137
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
2116
2138
|
local data = fileSourceMap[line]
|
|
2117
2139
|
if type(data) == "number" then
|
|
@@ -2178,16 +2200,6 @@ local function __TS__StringEndsWith(self, searchString, endPosition)
|
|
|
2178
2200
|
return string.sub(self, endPosition - #searchString + 1, endPosition) == searchString
|
|
2179
2201
|
end
|
|
2180
2202
|
|
|
2181
|
-
local function __TS__StringIncludes(self, searchString, position)
|
|
2182
|
-
if not position then
|
|
2183
|
-
position = 1
|
|
2184
|
-
else
|
|
2185
|
-
position = position + 1
|
|
2186
|
-
end
|
|
2187
|
-
local index = string.find(self, searchString, position, true)
|
|
2188
|
-
return index ~= nil
|
|
2189
|
-
end
|
|
2190
|
-
|
|
2191
2203
|
local function __TS__StringPadEnd(self, maxLength, fillString)
|
|
2192
2204
|
if fillString == nil then
|
|
2193
2205
|
fillString = " "
|
|
@@ -2443,6 +2455,7 @@ return {
|
|
|
2443
2455
|
__TS__Class = __TS__Class,
|
|
2444
2456
|
__TS__ClassExtends = __TS__ClassExtends,
|
|
2445
2457
|
__TS__CloneDescriptor = __TS__CloneDescriptor,
|
|
2458
|
+
__TS__CountVarargs = __TS__CountVarargs,
|
|
2446
2459
|
__TS__Decorate = __TS__Decorate,
|
|
2447
2460
|
__TS__DecorateParam = __TS__DecorateParam,
|
|
2448
2461
|
__TS__Delete = __TS__Delete,
|
|
@@ -2460,8 +2473,11 @@ return {
|
|
|
2460
2473
|
__TS__Iterator = __TS__Iterator,
|
|
2461
2474
|
__TS__LuaIteratorSpread = __TS__LuaIteratorSpread,
|
|
2462
2475
|
Map = Map,
|
|
2476
|
+
__TS__Match = __TS__Match,
|
|
2463
2477
|
__TS__MathAtan2 = __TS__MathAtan2,
|
|
2478
|
+
__TS__MathModf = __TS__MathModf,
|
|
2464
2479
|
__TS__MathSign = __TS__MathSign,
|
|
2480
|
+
__TS__Modulo50 = __TS__Modulo50,
|
|
2465
2481
|
__TS__New = __TS__New,
|
|
2466
2482
|
__TS__Number = __TS__Number,
|
|
2467
2483
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
@@ -86,11 +86,17 @@
|
|
|
86
86
|
"ArrayReduce": {
|
|
87
87
|
"exports": [
|
|
88
88
|
"__TS__ArrayReduce"
|
|
89
|
+
],
|
|
90
|
+
"dependencies": [
|
|
91
|
+
"CountVarargs"
|
|
89
92
|
]
|
|
90
93
|
},
|
|
91
94
|
"ArrayReduceRight": {
|
|
92
95
|
"exports": [
|
|
93
96
|
"__TS__ArrayReduceRight"
|
|
97
|
+
],
|
|
98
|
+
"dependencies": [
|
|
99
|
+
"CountVarargs"
|
|
94
100
|
]
|
|
95
101
|
},
|
|
96
102
|
"ArrayReverse": {
|
|
@@ -121,6 +127,9 @@
|
|
|
121
127
|
"ArraySplice": {
|
|
122
128
|
"exports": [
|
|
123
129
|
"__TS__ArraySplice"
|
|
130
|
+
],
|
|
131
|
+
"dependencies": [
|
|
132
|
+
"CountVarargs"
|
|
124
133
|
]
|
|
125
134
|
},
|
|
126
135
|
"ArrayToObject": {
|
|
@@ -176,6 +185,11 @@
|
|
|
176
185
|
"__TS__CloneDescriptor"
|
|
177
186
|
]
|
|
178
187
|
},
|
|
188
|
+
"CountVarargs": {
|
|
189
|
+
"exports": [
|
|
190
|
+
"__TS__CountVarargs"
|
|
191
|
+
]
|
|
192
|
+
},
|
|
179
193
|
"Decorate": {
|
|
180
194
|
"exports": [
|
|
181
195
|
"__TS__Decorate"
|
|
@@ -220,6 +234,7 @@
|
|
|
220
234
|
"URIError"
|
|
221
235
|
],
|
|
222
236
|
"dependencies": [
|
|
237
|
+
"StringIncludes",
|
|
223
238
|
"New",
|
|
224
239
|
"Error",
|
|
225
240
|
"Class",
|
|
@@ -240,7 +255,9 @@
|
|
|
240
255
|
"__TS__Generator"
|
|
241
256
|
],
|
|
242
257
|
"dependencies": [
|
|
243
|
-
"Symbol"
|
|
258
|
+
"Symbol",
|
|
259
|
+
"CountVarargs",
|
|
260
|
+
"Unpack"
|
|
244
261
|
]
|
|
245
262
|
},
|
|
246
263
|
"InstanceOf": {
|
|
@@ -282,16 +299,31 @@
|
|
|
282
299
|
"Iterator"
|
|
283
300
|
]
|
|
284
301
|
},
|
|
302
|
+
"Match": {
|
|
303
|
+
"exports": [
|
|
304
|
+
"__TS__Match"
|
|
305
|
+
]
|
|
306
|
+
},
|
|
285
307
|
"MathAtan2": {
|
|
286
308
|
"exports": [
|
|
287
309
|
"__TS__MathAtan2"
|
|
288
310
|
]
|
|
289
311
|
},
|
|
312
|
+
"MathModf": {
|
|
313
|
+
"exports": [
|
|
314
|
+
"__TS__MathModf"
|
|
315
|
+
]
|
|
316
|
+
},
|
|
290
317
|
"MathSign": {
|
|
291
318
|
"exports": [
|
|
292
319
|
"__TS__MathSign"
|
|
293
320
|
]
|
|
294
321
|
},
|
|
322
|
+
"Modulo50": {
|
|
323
|
+
"exports": [
|
|
324
|
+
"__TS__Modulo50"
|
|
325
|
+
]
|
|
326
|
+
},
|
|
295
327
|
"New": {
|
|
296
328
|
"exports": [
|
|
297
329
|
"__TS__New"
|
|
@@ -317,7 +349,8 @@
|
|
|
317
349
|
"__TS__NumberToString"
|
|
318
350
|
],
|
|
319
351
|
"dependencies": [
|
|
320
|
-
"StringAccess"
|
|
352
|
+
"StringAccess",
|
|
353
|
+
"MathModf"
|
|
321
354
|
]
|
|
322
355
|
},
|
|
323
356
|
"ObjectAssign": {
|
|
@@ -376,7 +409,8 @@
|
|
|
376
409
|
"__TS__ParseFloat"
|
|
377
410
|
],
|
|
378
411
|
"dependencies": [
|
|
379
|
-
"StringAccess"
|
|
412
|
+
"StringAccess",
|
|
413
|
+
"Match"
|
|
380
414
|
]
|
|
381
415
|
},
|
|
382
416
|
"ParseInt": {
|
|
@@ -385,7 +419,8 @@
|
|
|
385
419
|
],
|
|
386
420
|
"dependencies": [
|
|
387
421
|
"StringSubstr",
|
|
388
|
-
"StringSubstring"
|
|
422
|
+
"StringSubstring",
|
|
423
|
+
"Match"
|
|
389
424
|
]
|
|
390
425
|
},
|
|
391
426
|
"Promise": {
|
|
@@ -465,11 +500,17 @@
|
|
|
465
500
|
"SparseArrayNew": {
|
|
466
501
|
"exports": [
|
|
467
502
|
"__TS__SparseArrayNew"
|
|
503
|
+
],
|
|
504
|
+
"dependencies": [
|
|
505
|
+
"CountVarargs"
|
|
468
506
|
]
|
|
469
507
|
},
|
|
470
508
|
"SparseArrayPush": {
|
|
471
509
|
"exports": [
|
|
472
510
|
"__TS__SparseArrayPush"
|
|
511
|
+
],
|
|
512
|
+
"dependencies": [
|
|
513
|
+
"CountVarargs"
|
|
473
514
|
]
|
|
474
515
|
},
|
|
475
516
|
"SparseArraySpread": {
|
|
@@ -498,6 +539,10 @@
|
|
|
498
539
|
"SourceMapTraceBack": {
|
|
499
540
|
"exports": [
|
|
500
541
|
"__TS__SourceMapTraceBack"
|
|
542
|
+
],
|
|
543
|
+
"dependencies": [
|
|
544
|
+
"StringIncludes",
|
|
545
|
+
"Match"
|
|
501
546
|
]
|
|
502
547
|
},
|
|
503
548
|
"Spread": {
|
|
@@ -25,17 +25,27 @@ class LuaLibPlugin {
|
|
|
25
25
|
this.featureDependencies = new Map();
|
|
26
26
|
}
|
|
27
27
|
afterPrint(program, options, emitHost, result) {
|
|
28
|
-
var _a;
|
|
28
|
+
var _a, _b;
|
|
29
29
|
void options;
|
|
30
30
|
// Write lualib dependency json
|
|
31
31
|
const { result: luaLibModuleInfo, diagnostics } = this.createLuaLibModulesInfo();
|
|
32
32
|
const emitBOM = (_a = options.emitBOM) !== null && _a !== void 0 ? _a : false;
|
|
33
33
|
emitHost.writeFile(path.join(tstl.getEmitOutDir(program), LuaLib_1.luaLibModulesInfoFileName), JSON.stringify(luaLibModuleInfo, null, 2), emitBOM);
|
|
34
|
+
// Flatten the output folder structure; we do not want to keep the target-specific directories
|
|
35
|
+
for (const file of result) {
|
|
36
|
+
let outPath = file.fileName;
|
|
37
|
+
while (outPath.includes("lualib") && path.basename(path.dirname(outPath)) !== "lualib") {
|
|
38
|
+
const upOne = path.join(path.dirname(outPath), "..", path.basename(outPath));
|
|
39
|
+
outPath = path.normalize(upOne);
|
|
40
|
+
}
|
|
41
|
+
file.fileName = outPath;
|
|
42
|
+
}
|
|
34
43
|
// Create map of result files keyed by their 'lualib name'
|
|
35
44
|
const exportedLualibFeatures = new Map(result.map(f => [path.basename(f.fileName).split(".")[0], f.code]));
|
|
36
45
|
// Figure out the order required in the bundle by recursively resolving all dependency features
|
|
37
46
|
const allFeatures = Object.values(LuaLib_1.LuaLibFeature);
|
|
38
|
-
const
|
|
47
|
+
const luaTarget = (_b = options.luaTarget) !== null && _b !== void 0 ? _b : tstl.LuaTarget.Universal;
|
|
48
|
+
const orderedFeatures = (0, LuaLib_1.resolveRecursiveLualibFeatures)(allFeatures, luaTarget, emitHost, luaLibModuleInfo);
|
|
39
49
|
// Concatenate lualib files into bundle with exports table and add lualib_bundle.lua to results
|
|
40
50
|
let lualibBundle = orderedFeatures.map(f => exportedLualibFeatures.get(LuaLib_1.LuaLibFeature[f])).join("\n");
|
|
41
51
|
const exports = allFeatures.flatMap(feature => luaLibModuleInfo[feature].exports);
|
|
@@ -3,4 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformArrayConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
5
|
export declare function transformArrayPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
6
|
-
export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.
|
|
6
|
+
export declare function transformArrayProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformArrayProperty = exports.transformArrayPrototypeCall = exports.transformArrayConstructorCall = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
5
6
|
const lua = require("../../LuaAST");
|
|
6
7
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
7
8
|
const lualib_1 = require("../utils/lualib");
|
|
@@ -25,6 +26,15 @@ function transformArrayConstructorCall(context, node, calledMethod) {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
exports.transformArrayConstructorCall = transformArrayConstructorCall;
|
|
29
|
+
function createTableLengthExpression(context, expression, node) {
|
|
30
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
31
|
+
const tableGetn = lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("getn"));
|
|
32
|
+
return lua.createCallExpression(tableGetn, [expression], node);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return lua.createUnaryExpression(expression, lua.SyntaxKind.LengthOperator, node);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
28
38
|
/**
|
|
29
39
|
* Optimized single element Array.push
|
|
30
40
|
*
|
|
@@ -35,7 +45,7 @@ function transformSingleElementArrayPush(context, node, caller, param) {
|
|
|
35
45
|
const expressionIsUsed = !ts.isExpressionStatement((0, typescript_1.findFirstNonOuterParent)(node));
|
|
36
46
|
const arrayIdentifier = lua.isIdentifier(caller) ? caller : (0, expression_list_1.moveToPrecedingTemp)(context, caller);
|
|
37
47
|
// #array + 1
|
|
38
|
-
let lengthExpression = lua.createBinaryExpression(
|
|
48
|
+
let lengthExpression = lua.createBinaryExpression(createTableLengthExpression(context, arrayIdentifier), lua.createNumericLiteral(1), lua.SyntaxKind.AdditionOperator);
|
|
39
49
|
if (expressionIsUsed) {
|
|
40
50
|
// store length in a temp
|
|
41
51
|
lengthExpression = (0, expression_list_1.moveToPrecedingTemp)(context, lengthExpression);
|
|
@@ -131,7 +141,7 @@ function transformArrayProperty(context, node) {
|
|
|
131
141
|
switch (node.name.text) {
|
|
132
142
|
case "length":
|
|
133
143
|
const expression = context.transformExpression(node.expression);
|
|
134
|
-
return
|
|
144
|
+
return createTableLengthExpression(context, expression, node);
|
|
135
145
|
default:
|
|
136
146
|
return undefined;
|
|
137
147
|
}
|
|
@@ -32,8 +32,10 @@ exports.transformFunctionPrototypeCall = transformFunctionPrototypeCall;
|
|
|
32
32
|
function transformFunctionProperty(context, node) {
|
|
33
33
|
switch (node.name.text) {
|
|
34
34
|
case "length":
|
|
35
|
-
if (context.luaTarget === CompilerOptions_1.LuaTarget.
|
|
36
|
-
context.
|
|
35
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
36
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
37
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Universal) {
|
|
38
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "function.length", context.luaTarget));
|
|
37
39
|
}
|
|
38
40
|
// debug.getinfo(fn)
|
|
39
41
|
const getInfoCall = lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("debug"), lua.createStringLiteral("getinfo")), [context.transformExpression(node.expression)]);
|
|
@@ -19,6 +19,7 @@ const promise_1 = require("./promise");
|
|
|
19
19
|
const string_1 = require("./string");
|
|
20
20
|
const symbol_1 = require("./symbol");
|
|
21
21
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
22
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
22
23
|
function transformBuiltinPropertyAccessExpression(context, node) {
|
|
23
24
|
const ownerType = context.checker.getTypeAtLocation(node.expression);
|
|
24
25
|
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
|
|
@@ -130,9 +131,16 @@ function transformBuiltinIdentifierExpression(context, node, symbol) {
|
|
|
130
131
|
case "NaN":
|
|
131
132
|
return (0, lua_ast_1.createNaN)(node);
|
|
132
133
|
case "Infinity":
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
135
|
+
const one = lua.createNumericLiteral(1);
|
|
136
|
+
const zero = lua.createNumericLiteral(0);
|
|
137
|
+
return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const math = lua.createIdentifier("math");
|
|
141
|
+
const huge = lua.createStringLiteral("huge");
|
|
142
|
+
return lua.createTableIndexExpression(math, huge, node);
|
|
143
|
+
}
|
|
136
144
|
case "globalThis":
|
|
137
145
|
return lua.createIdentifier("_G", node, (0, symbols_1.getIdentifierSymbolId)(context, node, symbol), "globalThis");
|
|
138
146
|
}
|
|
@@ -3,4 +3,4 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformStringPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
5
|
export declare function transformStringConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
6
|
-
export declare function transformStringProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.
|
|
6
|
+
export declare function transformStringProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformStringProperty = exports.transformStringConstructorCall = exports.transformStringPrototypeCall = void 0;
|
|
4
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
4
5
|
const lua = require("../../LuaAST");
|
|
5
6
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
@@ -123,7 +124,13 @@ function transformStringProperty(context, node) {
|
|
|
123
124
|
switch (node.name.text) {
|
|
124
125
|
case "length":
|
|
125
126
|
const expression = context.transformExpression(node.expression);
|
|
126
|
-
|
|
127
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
128
|
+
const stringLen = lua.createTableIndexExpression(lua.createIdentifier("string"), lua.createStringLiteral("len"));
|
|
129
|
+
return lua.createCallExpression(stringLen, [expression], node);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return lua.createUnaryExpression(expression, lua.SyntaxKind.LengthOperator, node);
|
|
133
|
+
}
|
|
127
134
|
default:
|
|
128
135
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "string", node.name.text));
|
|
129
136
|
}
|
|
@@ -43,11 +43,10 @@ export declare const unsupportedAccessorInObjectLiteral: ((node: ts.Node, ...arg
|
|
|
43
43
|
export declare const unsupportedRightShiftOperator: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
44
44
|
code: number;
|
|
45
45
|
};
|
|
46
|
-
declare
|
|
47
|
-
export declare const unsupportedForTarget: ((node: ts.Node, functionality: string, version: NonUniversalTarget) => ts.Diagnostic) & {
|
|
46
|
+
export declare const unsupportedForTarget: ((node: ts.Node, functionality: string, version: LuaTarget) => ts.Diagnostic) & {
|
|
48
47
|
code: number;
|
|
49
48
|
};
|
|
50
|
-
export declare const unsupportedForTargetButOverrideAvailable: ((node: ts.Node, functionality: string, version:
|
|
49
|
+
export declare const unsupportedForTargetButOverrideAvailable: ((node: ts.Node, functionality: string, version: LuaTarget, optionName: keyof TypeScriptToLuaOptions) => ts.Diagnostic) & {
|
|
51
50
|
code: number;
|
|
52
51
|
};
|
|
53
52
|
export declare const unsupportedProperty: ((node: ts.Node, parentName: string, property: string) => ts.Diagnostic) & {
|
|
@@ -83,6 +82,9 @@ export declare const annotationRemoved: ((node: ts.Node, kind: AnnotationKind) =
|
|
|
83
82
|
export declare const annotationDeprecated: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
|
|
84
83
|
code: number;
|
|
85
84
|
};
|
|
85
|
+
export declare const truthyOnlyConditionalValue: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
86
|
+
code: number;
|
|
87
|
+
};
|
|
86
88
|
export declare const notAllowedOptionalAssignment: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
87
89
|
code: number;
|
|
88
90
|
};
|
|
@@ -98,4 +100,3 @@ export declare const unsupportedOptionalCompileMembersOnly: ((node: ts.Node, ...
|
|
|
98
100
|
export declare const undefinedInArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
99
101
|
code: number;
|
|
100
102
|
};
|
|
101
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = 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;
|
|
3
|
+
exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.annotationRemoved = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = exports.invalidMultiTypeToNonArrayLiteral = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = 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");
|
|
@@ -57,6 +57,7 @@ exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' h
|
|
|
57
57
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
58
58
|
exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
|
|
59
59
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
60
|
+
exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Numbers and strings will always evaluate to true in Lua. Explicitly check the value with ===.");
|
|
60
61
|
exports.notAllowedOptionalAssignment = createErrorDiagnosticFactory("The left-hand side of an assignment expression may not be an optional property access.");
|
|
61
62
|
exports.awaitMustBeInAsyncFunction = createErrorDiagnosticFactory("Await can only be used inside async functions.");
|
|
62
63
|
exports.unsupportedBuiltinOptionalCall = createErrorDiagnosticFactory("Optional calls are not supported for builtin or language extension functions.");
|
|
@@ -59,7 +59,9 @@ function createUnpackCall(context, expression, tsOriginal) {
|
|
|
59
59
|
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal) {
|
|
60
60
|
return (0, lualib_1.transformLuaLibFunction)(context, LuaLib_1.LuaLibFeature.Unpack, tsOriginal, expression);
|
|
61
61
|
}
|
|
62
|
-
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.
|
|
62
|
+
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.Lua50 ||
|
|
63
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
64
|
+
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT
|
|
63
65
|
? lua.createIdentifier("unpack")
|
|
64
66
|
: lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("unpack"));
|
|
65
67
|
return lua.setNodeFlags(lua.createCallExpression(unpack, [expression], tsOriginal), lua.NodeFlags.TableUnpackCall);
|
|
@@ -97,7 +97,7 @@ function isExpressionWithEvaluationEffect(node) {
|
|
|
97
97
|
exports.isExpressionWithEvaluationEffect = isExpressionWithEvaluationEffect;
|
|
98
98
|
function getFunctionTypeForCall(context, node) {
|
|
99
99
|
const signature = context.checker.getResolvedSignature(node);
|
|
100
|
-
if (!signature ||
|
|
100
|
+
if (!(signature === null || signature === void 0 ? void 0 : signature.declaration)) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
const typeDeclaration = findFirstNodeAbove(signature.declaration, ts.isTypeAliasDeclaration);
|
|
@@ -116,7 +116,7 @@ function isConstIdentifier(context, node) {
|
|
|
116
116
|
return false;
|
|
117
117
|
}
|
|
118
118
|
const symbol = context.checker.getSymbolAtLocation(identifier);
|
|
119
|
-
if (!symbol ||
|
|
119
|
+
if (!(symbol === null || symbol === void 0 ? void 0 : symbol.declarations)) {
|
|
120
120
|
return false;
|
|
121
121
|
}
|
|
122
122
|
return symbol.declarations.some(d => ts.isVariableDeclarationList(d.parent) && (d.parent.flags & ts.NodeFlags.Const) !== 0);
|
|
@@ -6,11 +6,13 @@ const lua = require("../../LuaAST");
|
|
|
6
6
|
const builtins_1 = require("../builtins");
|
|
7
7
|
const annotations_1 = require("../utils/annotations");
|
|
8
8
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
9
|
+
const language_extensions_1 = require("../utils/language-extensions");
|
|
9
10
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
10
11
|
const lualib_1 = require("../utils/lualib");
|
|
11
12
|
const typescript_1 = require("../utils/typescript");
|
|
12
13
|
const enum_1 = require("./enum");
|
|
13
14
|
const expression_list_1 = require("./expression-list");
|
|
15
|
+
const call_extension_1 = require("./language-extensions/call-extension");
|
|
14
16
|
const multi_1 = require("./language-extensions/multi");
|
|
15
17
|
const optional_chaining_1 = require("./optional-chaining");
|
|
16
18
|
function addOneToArrayAccessArgument(context, node, index) {
|
|
@@ -108,6 +110,15 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
|
|
|
108
110
|
// If this assumption is no longer true, this may need to be updated.
|
|
109
111
|
return { expression: builtinResult };
|
|
110
112
|
}
|
|
113
|
+
if (ts.isIdentifier(node.expression) &&
|
|
114
|
+
node.parent &&
|
|
115
|
+
(!ts.isCallExpression(node.parent) || node.parent.expression !== node)) {
|
|
116
|
+
// Check if this is a method call extension that is not used as a call
|
|
117
|
+
const extensionType = (0, language_extensions_1.getExtensionKindForNode)(context, node);
|
|
118
|
+
if (extensionType && call_extension_1.callExtensions.has(extensionType)) {
|
|
119
|
+
context.diagnostics.push((0, diagnostics_1.invalidCallExtensionUse)(node));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
111
122
|
const table = context.transformExpression(node.expression);
|
|
112
123
|
if (thisValueCapture) {
|
|
113
124
|
const thisValue = (0, optional_chaining_1.captureThisValue)(context, table, thisValueCapture, node.expression);
|