typescript-to-lua 1.13.0 → 1.13.2

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 (38) hide show
  1. package/dist/lualib/5.0/Await.lua +5 -11
  2. package/dist/lualib/5.0/Decorate.lua +1 -1
  3. package/dist/lualib/5.0/Error.lua +12 -18
  4. package/dist/lualib/5.0/Map.lua +3 -3
  5. package/dist/lualib/5.0/MathModf.lua +1 -7
  6. package/dist/lualib/5.0/ObjectDefineProperty.lua +21 -27
  7. package/dist/lualib/5.0/ParseFloat.lua +2 -8
  8. package/dist/lualib/5.0/ParseInt.lua +9 -21
  9. package/dist/lualib/5.0/Set.lua +3 -3
  10. package/dist/lualib/5.0/SetDescriptor.lua +2 -2
  11. package/dist/lualib/5.0/SourceMapTraceBack.lua +4 -4
  12. package/dist/lualib/5.0/StringReplace.lua +1 -7
  13. package/dist/lualib/5.0/SymbolRegistry.lua +1 -0
  14. package/dist/lualib/5.0/lualib_bundle.lua +65 -112
  15. package/dist/lualib/universal/Await.lua +5 -11
  16. package/dist/lualib/universal/Decorate.lua +1 -1
  17. package/dist/lualib/universal/Error.lua +12 -18
  18. package/dist/lualib/universal/Map.lua +3 -3
  19. package/dist/lualib/universal/ObjectDefineProperty.lua +21 -27
  20. package/dist/lualib/universal/ParseFloat.lua +2 -8
  21. package/dist/lualib/universal/ParseInt.lua +3 -15
  22. package/dist/lualib/universal/Set.lua +3 -3
  23. package/dist/lualib/universal/SetDescriptor.lua +2 -2
  24. package/dist/lualib/universal/SourceMapTraceBack.lua +5 -5
  25. package/dist/lualib/universal/StringReplace.lua +1 -7
  26. package/dist/lualib/universal/SymbolRegistry.lua +1 -0
  27. package/dist/lualib/universal/lualib_bundle.lua +59 -100
  28. package/dist/transformation/builtins/array.js +4 -3
  29. package/dist/transformation/builtins/math.js +4 -3
  30. package/dist/transformation/builtins/string.js +7 -4
  31. package/dist/transformation/utils/diagnostics.d.ts +4 -0
  32. package/dist/transformation/utils/diagnostics.js +3 -1
  33. package/dist/transformation/utils/lua-ast.js +10 -8
  34. package/dist/transformation/visitors/binary-expression/assignments.js +10 -4
  35. package/dist/transformation/visitors/language-extensions/multi.js +10 -9
  36. package/dist/transformation/visitors/spread.js +18 -3
  37. package/dist/transpilation/resolve.js +3 -0
  38. package/package.json +7 -7
@@ -9,7 +9,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
9
9
  if thread == nil and message == nil and level == nil then
10
10
  trace = originalTraceback()
11
11
  elseif __TS__StringIncludes(_VERSION, "Lua 5.0") then
12
- trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. message)
12
+ trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. tostring(message))
13
13
  else
14
14
  trace = originalTraceback(thread, message, level)
15
15
  end
@@ -18,12 +18,12 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
18
18
  end
19
19
  local function replacer(____, file, srcFile, line)
20
20
  local fileSourceMap = _G.__TS__sourcemap[file]
21
- if fileSourceMap and fileSourceMap[line] then
21
+ if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
22
22
  local data = fileSourceMap[line]
23
23
  if type(data) == "number" then
24
24
  return (srcFile .. ":") .. tostring(data)
25
25
  end
26
- return (tostring(data.file) .. ":") .. tostring(data.line)
26
+ return (data.file .. ":") .. tostring(data.line)
27
27
  end
28
28
  return (file .. ":") .. line
29
29
  end
@@ -34,14 +34,14 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
34
34
  )
35
35
  local function stringReplacer(____, file, line)
36
36
  local fileSourceMap = _G.__TS__sourcemap[file]
37
- if fileSourceMap and fileSourceMap[line] then
37
+ if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
38
38
  local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
39
39
  local sourceName = string.gsub(chunkName, ".lua$", ".ts")
40
40
  local data = fileSourceMap[line]
41
41
  if type(data) == "number" then
42
42
  return (sourceName .. ":") .. tostring(data)
43
43
  end
44
- return (tostring(data.file) .. ":") .. tostring(data.line)
44
+ return (data.file .. ":") .. tostring(data.line)
45
45
  end
46
46
  return (file .. ":") .. line
47
47
  end
@@ -7,13 +7,7 @@ do
7
7
  return source
8
8
  end
9
9
  local before = sub(source, 1, startPos - 1)
10
- local ____temp_0
11
- if type(replaceValue) == "string" then
12
- ____temp_0 = replaceValue
13
- else
14
- ____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
15
- end
16
- local replacement = ____temp_0
10
+ local replacement = type(replaceValue) == "string" and replaceValue or replaceValue(nil, searchValue, startPos - 1, source)
17
11
  local after = sub(source, endPos + 1)
18
12
  return (before .. replacement) .. after
19
13
  end
@@ -13,5 +13,6 @@ do
13
13
  return key
14
14
  end
15
15
  end
16
+ return nil
16
17
  end
17
18
  end
@@ -762,13 +762,7 @@ local function __TS__AsyncAwaiter(generator)
762
762
  function(____, resolve, reject)
763
763
  local adopt, fulfilled, step, resolved, asyncCoroutine
764
764
  function adopt(self, value)
765
- local ____temp_0
766
- if __TS__InstanceOf(value, __TS__Promise) then
767
- ____temp_0 = value
768
- else
769
- ____temp_0 = __TS__Promise.resolve(value)
770
- end
771
- return ____temp_0
765
+ return __TS__InstanceOf(value, __TS__Promise) and value or __TS__Promise.resolve(value)
772
766
  end
773
767
  function fulfilled(self, value)
774
768
  local success, resultOrError = coroutine.resume(asyncCoroutine, value)
@@ -785,8 +779,8 @@ local function __TS__AsyncAwaiter(generator)
785
779
  if coroutine.status(asyncCoroutine) == "dead" then
786
780
  resolve(nil, result)
787
781
  else
788
- local ____self_1 = adopt(nil, result)
789
- ____self_1["then"](____self_1, fulfilled, reject)
782
+ local ____self_0 = adopt(nil, result)
783
+ ____self_0["then"](____self_0, fulfilled, reject)
790
784
  end
791
785
  end
792
786
  resolved = false
@@ -795,8 +789,8 @@ local function __TS__AsyncAwaiter(generator)
795
789
  asyncCoroutine,
796
790
  function(____, v)
797
791
  resolved = true
798
- local ____self_2 = adopt(nil, v)
799
- ____self_2["then"](____self_2, resolve, reject)
792
+ local ____self_1 = adopt(nil, v)
793
+ ____self_1["then"](____self_1, resolve, reject)
800
794
  end
801
795
  )
802
796
  if success then
@@ -903,7 +897,7 @@ do
903
897
  local descriptors = rawget(metatable, "_descriptors")
904
898
  if descriptors then
905
899
  local descriptor = descriptors[key]
906
- if descriptor then
900
+ if descriptor ~= nil then
907
901
  if descriptor.get then
908
902
  return descriptor.get(self)
909
903
  end
@@ -919,7 +913,7 @@ do
919
913
  local descriptors = rawget(metatable, "_descriptors")
920
914
  if descriptors then
921
915
  local descriptor = descriptors[key]
922
- if descriptor then
916
+ if descriptor ~= nil then
923
917
  if descriptor.set then
924
918
  descriptor.set(self, value)
925
919
  else
@@ -972,7 +966,7 @@ local function __TS__Decorate(decorators, target, key, desc)
972
966
  local i = #decorators
973
967
  while i >= 0 do
974
968
  local decorator = decorators[i + 1]
975
- if decorator then
969
+ if decorator ~= nil then
976
970
  local oldResult = result
977
971
  if key == nil then
978
972
  result = decorator(nil, result)
@@ -1045,7 +1039,7 @@ do
1045
1039
  if isClassicLua or caller and caller.func ~= error then
1046
1040
  return description
1047
1041
  else
1048
- return (tostring(description) .. "\n") .. self.stack
1042
+ return (description .. "\n") .. tostring(self.stack)
1049
1043
  end
1050
1044
  end
1051
1045
  end
@@ -1056,7 +1050,7 @@ do
1056
1050
  {__call = function(____, _self, message) return __TS__New(Type, message) end}
1057
1051
  )
1058
1052
  end
1059
- local ____initErrorClass_2 = initErrorClass
1053
+ local ____initErrorClass_1 = initErrorClass
1060
1054
  local ____class_0 = __TS__Class()
1061
1055
  ____class_0.name = ""
1062
1056
  function ____class_0.prototype.____constructor(self, message)
@@ -1067,31 +1061,25 @@ do
1067
1061
  self.name = "Error"
1068
1062
  self.stack = getErrorStack(nil, self.constructor.new)
1069
1063
  local metatable = getmetatable(self)
1070
- if not metatable.__errorToStringPatched then
1064
+ if metatable and not metatable.__errorToStringPatched then
1071
1065
  metatable.__errorToStringPatched = true
1072
1066
  metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
1073
1067
  end
1074
1068
  end
1075
1069
  function ____class_0.prototype.__tostring(self)
1076
- local ____temp_1
1077
- if self.message ~= "" then
1078
- ____temp_1 = (self.name .. ": ") .. self.message
1079
- else
1080
- ____temp_1 = self.name
1081
- end
1082
- return ____temp_1
1070
+ return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
1083
1071
  end
1084
- Error = ____initErrorClass_2(nil, ____class_0, "Error")
1072
+ Error = ____initErrorClass_1(nil, ____class_0, "Error")
1085
1073
  local function createErrorClass(self, name)
1086
- local ____initErrorClass_4 = initErrorClass
1087
- local ____class_3 = __TS__Class()
1088
- ____class_3.name = ____class_3.name
1089
- __TS__ClassExtends(____class_3, Error)
1090
- function ____class_3.prototype.____constructor(self, ...)
1091
- ____class_3.____super.prototype.____constructor(self, ...)
1074
+ local ____initErrorClass_3 = initErrorClass
1075
+ local ____class_2 = __TS__Class()
1076
+ ____class_2.name = ____class_2.name
1077
+ __TS__ClassExtends(____class_2, Error)
1078
+ function ____class_2.prototype.____constructor(self, ...)
1079
+ ____class_2.____super.prototype.____constructor(self, ...)
1092
1080
  self.name = name
1093
1081
  end
1094
- return ____initErrorClass_4(nil, ____class_3, name)
1082
+ return ____initErrorClass_3(nil, ____class_2, name)
1095
1083
  end
1096
1084
  RangeError = createErrorClass(nil, "RangeError")
1097
1085
  ReferenceError = createErrorClass(nil, "ReferenceError")
@@ -1261,13 +1249,13 @@ do
1261
1249
  self.size = self.size - 1
1262
1250
  local next = self.nextKey[key]
1263
1251
  local previous = self.previousKey[key]
1264
- if next and previous then
1252
+ if next ~= nil and previous ~= nil then
1265
1253
  self.nextKey[previous] = next
1266
1254
  self.previousKey[next] = previous
1267
- elseif next then
1255
+ elseif next ~= nil then
1268
1256
  self.firstKey = next
1269
1257
  self.previousKey[next] = nil
1270
- elseif previous then
1258
+ elseif previous ~= nil then
1271
1259
  self.lastKey = previous
1272
1260
  self.nextKey[previous] = nil
1273
1261
  else
@@ -1453,13 +1441,7 @@ do
1453
1441
  end
1454
1442
 
1455
1443
  local function __TS__ObjectDefineProperty(target, key, desc)
1456
- local ____temp_0
1457
- if type(key) == "number" then
1458
- ____temp_0 = key + 1
1459
- else
1460
- ____temp_0 = key
1461
- end
1462
- local luaKey = ____temp_0
1444
+ local luaKey = type(key) == "number" and key + 1 or key
1463
1445
  local value = rawget(target, luaKey)
1464
1446
  local hasGetterOrSetter = desc.get ~= nil or desc.set ~= nil
1465
1447
  local descriptor
@@ -1473,39 +1455,39 @@ local function __TS__ObjectDefineProperty(target, key, desc)
1473
1455
  descriptor = desc
1474
1456
  else
1475
1457
  local valueExists = value ~= nil
1476
- local ____desc_set_5 = desc.set
1477
- local ____desc_get_6 = desc.get
1478
- local ____temp_1
1458
+ local ____desc_set_4 = desc.set
1459
+ local ____desc_get_5 = desc.get
1460
+ local ____temp_0
1479
1461
  if desc.configurable ~= nil then
1480
- ____temp_1 = desc.configurable
1462
+ ____temp_0 = desc.configurable
1481
1463
  else
1482
- ____temp_1 = valueExists
1464
+ ____temp_0 = valueExists
1483
1465
  end
1484
- local ____temp_2
1466
+ local ____temp_1
1485
1467
  if desc.enumerable ~= nil then
1486
- ____temp_2 = desc.enumerable
1468
+ ____temp_1 = desc.enumerable
1487
1469
  else
1488
- ____temp_2 = valueExists
1470
+ ____temp_1 = valueExists
1489
1471
  end
1490
- local ____temp_3
1472
+ local ____temp_2
1491
1473
  if desc.writable ~= nil then
1492
- ____temp_3 = desc.writable
1474
+ ____temp_2 = desc.writable
1493
1475
  else
1494
- ____temp_3 = valueExists
1476
+ ____temp_2 = valueExists
1495
1477
  end
1496
- local ____temp_4
1478
+ local ____temp_3
1497
1479
  if desc.value ~= nil then
1498
- ____temp_4 = desc.value
1480
+ ____temp_3 = desc.value
1499
1481
  else
1500
- ____temp_4 = value
1482
+ ____temp_3 = value
1501
1483
  end
1502
1484
  descriptor = {
1503
- set = ____desc_set_5,
1504
- get = ____desc_get_6,
1505
- configurable = ____temp_1,
1506
- enumerable = ____temp_2,
1507
- writable = ____temp_3,
1508
- value = ____temp_4
1485
+ set = ____desc_set_4,
1486
+ get = ____desc_get_5,
1487
+ configurable = ____temp_0,
1488
+ enumerable = ____temp_1,
1489
+ writable = ____temp_2,
1490
+ value = ____temp_3
1509
1491
  }
1510
1492
  end
1511
1493
  __TS__SetDescriptor(target, luaKey, descriptor)
@@ -1575,14 +1557,8 @@ end
1575
1557
 
1576
1558
  local function __TS__ParseFloat(numberString)
1577
1559
  local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
1578
- if infinityMatch then
1579
- local ____temp_0
1580
- if __TS__StringAccess(infinityMatch, 0) == "-" then
1581
- ____temp_0 = -math.huge
1582
- else
1583
- ____temp_0 = math.huge
1584
- end
1585
- return ____temp_0
1560
+ if infinityMatch ~= nil then
1561
+ return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
1586
1562
  end
1587
1563
  local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
1588
1564
  return number or 0 / 0
@@ -1613,27 +1589,15 @@ do
1613
1589
  if base == nil then
1614
1590
  base = 10
1615
1591
  local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
1616
- if hexMatch then
1592
+ if hexMatch ~= nil then
1617
1593
  base = 16
1618
- local ____TS__Match_result__0_0
1619
- if __TS__Match(hexMatch, "-") then
1620
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
1621
- else
1622
- ____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
1623
- end
1624
- numberString = ____TS__Match_result__0_0
1594
+ numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
1625
1595
  end
1626
1596
  end
1627
1597
  if base < 2 or base > 36 then
1628
1598
  return 0 / 0
1629
1599
  end
1630
- local ____temp_1
1631
- if base <= 10 then
1632
- ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
1633
- else
1634
- ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1635
- end
1636
- local allowedDigits = ____temp_1
1600
+ local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1637
1601
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
1638
1602
  local number = tonumber(
1639
1603
  __TS__Match(numberString, pattern),
@@ -1872,13 +1836,13 @@ do
1872
1836
  self.size = self.size - 1
1873
1837
  local next = self.nextKey[value]
1874
1838
  local previous = self.previousKey[value]
1875
- if next and previous then
1839
+ if next ~= nil and previous ~= nil then
1876
1840
  self.nextKey[previous] = next
1877
1841
  self.previousKey[next] = previous
1878
- elseif next then
1842
+ elseif next ~= nil then
1879
1843
  self.firstKey = next
1880
1844
  self.previousKey[next] = nil
1881
- elseif previous then
1845
+ elseif previous ~= nil then
1882
1846
  self.lastKey = previous
1883
1847
  self.nextKey[previous] = nil
1884
1848
  else
@@ -2066,7 +2030,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2066
2030
  if thread == nil and message == nil and level == nil then
2067
2031
  trace = originalTraceback()
2068
2032
  elseif __TS__StringIncludes(_VERSION, "Lua 5.0") then
2069
- trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. message)
2033
+ trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. tostring(message))
2070
2034
  else
2071
2035
  trace = originalTraceback(thread, message, level)
2072
2036
  end
@@ -2075,12 +2039,12 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2075
2039
  end
2076
2040
  local function replacer(____, file, srcFile, line)
2077
2041
  local fileSourceMap = _G.__TS__sourcemap[file]
2078
- if fileSourceMap and fileSourceMap[line] then
2042
+ if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
2079
2043
  local data = fileSourceMap[line]
2080
2044
  if type(data) == "number" then
2081
2045
  return (srcFile .. ":") .. tostring(data)
2082
2046
  end
2083
- return (tostring(data.file) .. ":") .. tostring(data.line)
2047
+ return (data.file .. ":") .. tostring(data.line)
2084
2048
  end
2085
2049
  return (file .. ":") .. line
2086
2050
  end
@@ -2091,14 +2055,14 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2091
2055
  )
2092
2056
  local function stringReplacer(____, file, line)
2093
2057
  local fileSourceMap = _G.__TS__sourcemap[file]
2094
- if fileSourceMap and fileSourceMap[line] then
2058
+ if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
2095
2059
  local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
2096
2060
  local sourceName = string.gsub(chunkName, ".lua$", ".ts")
2097
2061
  local data = fileSourceMap[line]
2098
2062
  if type(data) == "number" then
2099
2063
  return (sourceName .. ":") .. tostring(data)
2100
2064
  end
2101
- return (tostring(data.file) .. ":") .. tostring(data.line)
2065
+ return (data.file .. ":") .. tostring(data.line)
2102
2066
  end
2103
2067
  return (file .. ":") .. line
2104
2068
  end
@@ -2218,13 +2182,7 @@ do
2218
2182
  return source
2219
2183
  end
2220
2184
  local before = sub(source, 1, startPos - 1)
2221
- local ____temp_0
2222
- if type(replaceValue) == "string" then
2223
- ____temp_0 = replaceValue
2224
- else
2225
- ____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
2226
- end
2227
- local replacement = ____temp_0
2185
+ local replacement = type(replaceValue) == "string" and replaceValue or replaceValue(nil, searchValue, startPos - 1, source)
2228
2186
  local after = sub(source, endPos + 1)
2229
2187
  return (before .. replacement) .. after
2230
2188
  end
@@ -2379,6 +2337,7 @@ do
2379
2337
  return key
2380
2338
  end
2381
2339
  end
2340
+ return nil
2382
2341
  end
2383
2342
  end
2384
2343
 
@@ -55,6 +55,7 @@ function transformSingleElementArrayPush(context, node, caller, param) {
55
55
  return expressionIsUsed ? lengthExpression : lua.createNilLiteral();
56
56
  }
57
57
  function transformArrayPrototypeCall(context, node, calledMethod) {
58
+ var _a, _b, _c;
58
59
  const signature = context.checker.getResolvedSignature(node);
59
60
  const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
60
61
  const expressionName = calledMethod.name.text;
@@ -65,9 +66,9 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
65
66
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayEntries, node, caller);
66
67
  case "push":
67
68
  if (node.arguments.length === 1) {
68
- const param = params[0];
69
+ const param = (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral();
69
70
  if ((0, lua_ast_1.isUnpackCall)(param)) {
70
- return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, param.params[0]);
71
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayPushArray, node, caller, (_b = param.params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral());
71
72
  }
72
73
  if (!lua.isDotsLiteral(param)) {
73
74
  return transformSingleElementArrayPush(context, node, caller, param);
@@ -116,7 +117,7 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
116
117
  if (elementType &&
117
118
  (0, typescript_1.typeAlwaysHasSomeOfFlags)(context, elementType, ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) {
118
119
  const defaultSeparatorLiteral = lua.createStringLiteral(",");
119
- const param = params[0];
120
+ const param = (_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral();
120
121
  const parameters = [
121
122
  caller,
122
123
  node.arguments.length === 0
@@ -27,6 +27,7 @@ function transformMathProperty(context, node) {
27
27
  }
28
28
  exports.transformMathProperty = transformMathProperty;
29
29
  function transformMathCall(context, node, calledMethod) {
30
+ var _a, _b, _c, _d;
30
31
  const signature = context.checker.getResolvedSignature(node);
31
32
  const params = (0, call_1.transformArguments)(context, node.arguments, signature);
32
33
  const math = lua.createIdentifier("math");
@@ -53,18 +54,18 @@ function transformMathCall(context, node, calledMethod) {
53
54
  case "log1p": {
54
55
  const log = lua.createStringLiteral("log");
55
56
  const one = lua.createNumericLiteral(1);
56
- const add = lua.createBinaryExpression(one, params[0], lua.SyntaxKind.AdditionOperator);
57
+ const add = lua.createBinaryExpression(one, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), lua.SyntaxKind.AdditionOperator);
57
58
  return lua.createCallExpression(lua.createTableIndexExpression(math, log), [add], node);
58
59
  }
59
60
  case "pow": {
60
61
  // Translate to base ^ power
61
- return lua.createBinaryExpression(params[0], params[1], lua.SyntaxKind.PowerOperator, node);
62
+ return lua.createBinaryExpression((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), (_c = params[1]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), lua.SyntaxKind.PowerOperator, node);
62
63
  }
63
64
  // math.floor(x + 0.5)
64
65
  case "round": {
65
66
  const floor = lua.createStringLiteral("floor");
66
67
  const half = lua.createNumericLiteral(0.5);
67
- const add = lua.createBinaryExpression(params[0], half, lua.SyntaxKind.AdditionOperator);
68
+ const add = lua.createBinaryExpression((_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(), half, lua.SyntaxKind.AdditionOperator);
68
69
  return lua.createCallExpression(lua.createTableIndexExpression(math, floor), [add], node);
69
70
  }
70
71
  case "sign": {
@@ -12,6 +12,7 @@ function createStringCall(methodName, tsOriginal, ...params) {
12
12
  return lua.createCallExpression(lua.createTableIndexExpression(stringIdentifier, lua.createStringLiteral(methodName)), params, tsOriginal);
13
13
  }
14
14
  function transformStringPrototypeCall(context, node, calledMethod) {
15
+ var _a, _b, _c, _d;
15
16
  const signature = context.checker.getResolvedSignature(node);
16
17
  const [caller, params] = (0, call_1.transformCallAndArguments)(context, calledMethod.expression, node.arguments, signature);
17
18
  const expressionName = calledMethod.name.text;
@@ -23,7 +24,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
23
24
  case "concat":
24
25
  return lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("table"), lua.createStringLiteral("concat")), [(0, lua_ast_1.wrapInTable)(caller, ...params)], node);
25
26
  case "indexOf": {
26
- const stringExpression = createStringCall("find", node, caller, params[0], params[1]
27
+ const stringExpression = createStringCall("find", node, caller, (_a = params[0]) !== null && _a !== void 0 ? _a : lua.createNilLiteral(), params[1]
27
28
  ? // string.find handles negative indexes by making it relative to string end, but for indexOf it's the same as 0
28
29
  lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("max")), [(0, lua_ast_1.addToNumericExpression)(params[1], 1), lua.createNumericLiteral(1)])
29
30
  : lua.createNilLiteral(), lua.createBooleanLiteral(true));
@@ -73,7 +74,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
73
74
  const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
74
75
  // Inline string.sub call if we know that parameter is pure and isn't negative
75
76
  if (literalValue !== undefined && literalValue >= 0) {
76
- const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)(params[0], 1);
77
+ const firstParamPlusOne = (0, lua_ast_1.addToNumericExpression)((_b = params[0]) !== null && _b !== void 0 ? _b : lua.createNilLiteral(), 1);
77
78
  return createStringCall("sub", node, caller, firstParamPlusOne, firstParamPlusOne);
78
79
  }
79
80
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharAt, node, caller, ...params);
@@ -82,7 +83,7 @@ function transformStringPrototypeCall(context, node, calledMethod) {
82
83
  const literalValue = (0, lua_ast_1.getNumberLiteralValue)(params[0]);
83
84
  // Inline string.sub call if we know that parameter is pure and isn't negative
84
85
  if (literalValue !== undefined && literalValue >= 0) {
85
- return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)(params[0], 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator);
86
+ return lua.createBinaryExpression(createStringCall("byte", node, caller, (0, lua_ast_1.addToNumericExpression)((_c = params[0]) !== null && _c !== void 0 ? _c : lua.createNilLiteral(), 1)), (0, lua_ast_1.createNaN)(), lua.SyntaxKind.OrOperator);
86
87
  }
87
88
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringCharCodeAt, node, caller, ...params);
88
89
  }
@@ -95,7 +96,9 @@ function transformStringPrototypeCall(context, node, calledMethod) {
95
96
  case "repeat":
96
97
  const math = lua.createIdentifier("math");
97
98
  const floor = lua.createStringLiteral("floor");
98
- const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [params[0]]);
99
+ const parameter = lua.createCallExpression(lua.createTableIndexExpression(math, floor), [
100
+ (_d = params[0]) !== null && _d !== void 0 ? _d : lua.createNilLiteral(),
101
+ ]);
99
102
  return createStringCall("rep", node, caller, parameter);
100
103
  case "padStart":
101
104
  return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringPadStart, node, caller, ...params);
@@ -1,4 +1,5 @@
1
1
  import * as ts from "typescript";
2
+ import * as lua from "../../LuaAST";
2
3
  import { LuaTarget, TypeScriptToLuaOptions } from "../../CompilerOptions";
3
4
  import { AnnotationKind } from "./annotations";
4
5
  export declare const unsupportedNodeKind: ((node: ts.Node, kind: ts.SyntaxKind) => ts.Diagnostic) & {
@@ -97,3 +98,6 @@ export declare const invalidMethodCallExtensionUse: ((node: ts.Node, ...args: an
97
98
  export declare const invalidSpreadInCallExtension: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
98
99
  code: number;
99
100
  };
101
+ export declare const cannotAssignToNodeOfKind: ((node: ts.Node, kind: lua.SyntaxKind) => ts.Diagnostic) & {
102
+ code: number;
103
+ };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = 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.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = 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
+ const lua = require("../../LuaAST");
5
6
  const CompilerOptions_1 = require("../../CompilerOptions");
6
7
  const utils_1 = require("../../utils");
7
8
  const createDiagnosticFactory = (category, message) => (0, utils_1.createSerialDiagnosticFactory)((node, ...args) => ({
@@ -61,4 +62,5 @@ exports.unsupportedOptionalCompileMembersOnly = createErrorDiagnosticFactory("Op
61
62
  exports.undefinedInArrayLiteral = createErrorDiagnosticFactory("Array literals may not contain undefined or null.");
62
63
  exports.invalidMethodCallExtensionUse = createErrorDiagnosticFactory("This language extension must be called as a method.");
63
64
  exports.invalidSpreadInCallExtension = createErrorDiagnosticFactory("Spread elements are not supported in call extensions.");
65
+ exports.cannotAssignToNodeOfKind = createErrorDiagnosticFactory((kind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`);
64
66
  //# sourceMappingURL=diagnostics.js.map
@@ -251,15 +251,17 @@ function getJSDocCommentFromTSNode(context, tsOriginal) {
251
251
  // https://stevedonovan.github.io/ldoc/manual/doc.md.html
252
252
  // LDoc comments require that the first line starts with three hyphens.
253
253
  // Thus, need to add a hyphen to the first line.
254
- const firstLine = lines[0];
255
- if (firstLine.startsWith(" @")) {
256
- lines.unshift("-");
257
- }
258
- else {
259
- lines.shift();
260
- lines.unshift("-" + firstLine);
254
+ if (lines.length > 0) {
255
+ const firstLine = lines[0];
256
+ if (firstLine.startsWith(" @")) {
257
+ lines.unshift("-");
258
+ }
259
+ else {
260
+ lines.shift();
261
+ lines.unshift("-" + firstLine);
262
+ }
263
+ return lines;
261
264
  }
262
- return lines;
263
265
  }
264
266
  const createNaN = (tsOriginal) => lua.createBinaryExpression(lua.createNumericLiteral(0), lua.createNumericLiteral(0), lua.SyntaxKind.DivisionOperator, tsOriginal);
265
267
  exports.createNaN = createNaN;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformAssignmentStatement = exports.transformAssignmentExpression = exports.transformAssignmentWithRightPrecedingStatements = exports.transformAssignment = exports.transformAssignmentLeftHandSideExpression = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../../LuaAST");
6
- const utils_1 = require("../../../utils");
7
6
  const assignment_validation_1 = require("../../utils/assignment-validation");
8
7
  const export_1 = require("../../utils/export");
9
8
  const lua_ast_1 = require("../../utils/lua-ast");
@@ -32,9 +31,16 @@ function transformAssignmentLeftHandSideExpression(context, node, rightHasPreced
32
31
  }
33
32
  const symbol = context.checker.getSymbolAtLocation(node);
34
33
  const left = context.transformExpression(node);
35
- return lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol)
36
- ? (0, export_1.createExportedIdentifier)(context, left)
37
- : (0, utils_1.cast)(left, lua.isAssignmentLeftHandSideExpression);
34
+ if (lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol)) {
35
+ return (0, export_1.createExportedIdentifier)(context, left);
36
+ }
37
+ if (lua.isAssignmentLeftHandSideExpression(left)) {
38
+ return left;
39
+ }
40
+ else {
41
+ context.diagnostics.push((0, diagnostics_1.cannotAssignToNodeOfKind)(node, left.kind));
42
+ return lua.createAnonymousIdentifier();
43
+ }
38
44
  }
39
45
  exports.transformAssignmentLeftHandSideExpression = transformAssignmentLeftHandSideExpression;
40
46
  function transformAssignment(context,
@@ -50,35 +50,36 @@ function shouldMultiReturnCallBeWrapped(context, node) {
50
50
  if (!returnsMultiType(context, node)) {
51
51
  return false;
52
52
  }
53
+ const parent = (0, typescript_1.findFirstNonOuterParent)(node);
53
54
  // Variable declaration with destructuring
54
- if (ts.isVariableDeclaration(node.parent) && ts.isArrayBindingPattern(node.parent.name)) {
55
+ if (ts.isVariableDeclaration(parent) && ts.isArrayBindingPattern(parent.name)) {
55
56
  return false;
56
57
  }
57
58
  // Variable assignment with destructuring
58
- if (ts.isBinaryExpression(node.parent) &&
59
- node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
60
- ts.isArrayLiteralExpression(node.parent.left)) {
59
+ if (ts.isBinaryExpression(parent) &&
60
+ parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
61
+ ts.isArrayLiteralExpression(parent.left)) {
61
62
  return false;
62
63
  }
63
64
  // Spread operator
64
- if (ts.isSpreadElement(node.parent)) {
65
+ if (ts.isSpreadElement(parent)) {
65
66
  return false;
66
67
  }
67
68
  // Stand-alone expression
68
- if (ts.isExpressionStatement(node.parent)) {
69
+ if (ts.isExpressionStatement(parent)) {
69
70
  return false;
70
71
  }
71
72
  // Forwarded multi-return call
72
- if ((ts.isReturnStatement(node.parent) || ts.isArrowFunction(node.parent)) && // Body-less arrow func
73
+ if ((ts.isReturnStatement(parent) || ts.isArrowFunction(parent)) && // Body-less arrow func
73
74
  isInMultiReturnFunction(context, node)) {
74
75
  return false;
75
76
  }
76
77
  // Element access expression 'foo()[0]' will be optimized using 'select'
77
- if (ts.isElementAccessExpression(node.parent)) {
78
+ if (ts.isElementAccessExpression(parent)) {
78
79
  return false;
79
80
  }
80
81
  // LuaIterable in for...of
81
- if (ts.isForOfStatement(node.parent) &&
82
+ if (ts.isForOfStatement(parent) &&
82
83
  (0, language_extensions_1.getIterableExtensionKindForNode)(context, node) === language_extensions_1.IterableExtensionKind.Iterable) {
83
84
  return false;
84
85
  }