typescript-to-lua 1.13.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,7 @@ local function __TS__AsyncAwaiter(generator)
4
4
  function(____, resolve, reject)
5
5
  local adopt, fulfilled, step, resolved, asyncCoroutine
6
6
  function adopt(self, value)
7
- local ____temp_0
8
- if __TS__InstanceOf(value, __TS__Promise) then
9
- ____temp_0 = value
10
- else
11
- ____temp_0 = __TS__Promise.resolve(value)
12
- end
13
- return ____temp_0
7
+ return __TS__InstanceOf(value, __TS__Promise) and value or __TS__Promise.resolve(value)
14
8
  end
15
9
  function fulfilled(self, value)
16
10
  local success, resultOrError = coroutine.resume(asyncCoroutine, value)
@@ -27,8 +21,8 @@ local function __TS__AsyncAwaiter(generator)
27
21
  if coroutine.status(asyncCoroutine) == "dead" then
28
22
  resolve(nil, result)
29
23
  else
30
- local ____self_1 = adopt(nil, result)
31
- ____self_1["then"](____self_1, fulfilled, reject)
24
+ local ____self_0 = adopt(nil, result)
25
+ ____self_0["then"](____self_0, fulfilled, reject)
32
26
  end
33
27
  end
34
28
  resolved = false
@@ -37,8 +31,8 @@ local function __TS__AsyncAwaiter(generator)
37
31
  asyncCoroutine,
38
32
  function(____, v)
39
33
  resolved = true
40
- local ____self_2 = adopt(nil, v)
41
- ____self_2["then"](____self_2, resolve, reject)
34
+ local ____self_1 = adopt(nil, v)
35
+ ____self_1["then"](____self_1, resolve, reject)
42
36
  end
43
37
  )
44
38
  if success then
@@ -4,7 +4,7 @@ local function __TS__Decorate(decorators, target, key, desc)
4
4
  local i = table.getn(decorators)
5
5
  while i >= 0 do
6
6
  local decorator = decorators[i + 1]
7
- if decorator then
7
+ if decorator ~= nil then
8
8
  local oldResult = result
9
9
  if key == nil then
10
10
  result = decorator(nil, result)
@@ -26,7 +26,7 @@ do
26
26
  if isClassicLua or caller and caller.func ~= error then
27
27
  return description
28
28
  else
29
- return (tostring(description) .. "\n") .. self.stack
29
+ return (description .. "\n") .. tostring(self.stack)
30
30
  end
31
31
  end
32
32
  end
@@ -37,7 +37,7 @@ do
37
37
  {__call = function(____, _self, message) return __TS__New(Type, message) end}
38
38
  )
39
39
  end
40
- local ____initErrorClass_2 = initErrorClass
40
+ local ____initErrorClass_1 = initErrorClass
41
41
  local ____class_0 = __TS__Class()
42
42
  ____class_0.name = ""
43
43
  function ____class_0.prototype.____constructor(self, message)
@@ -48,34 +48,28 @@ do
48
48
  self.name = "Error"
49
49
  self.stack = getErrorStack(nil, self.constructor.new)
50
50
  local metatable = getmetatable(self)
51
- if not metatable.__errorToStringPatched then
51
+ if metatable and not metatable.__errorToStringPatched then
52
52
  metatable.__errorToStringPatched = true
53
53
  metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
54
54
  end
55
55
  end
56
56
  function ____class_0.prototype.__tostring(self)
57
- local ____temp_1
58
- if self.message ~= "" then
59
- ____temp_1 = (self.name .. ": ") .. self.message
60
- else
61
- ____temp_1 = self.name
62
- end
63
- return ____temp_1
57
+ return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
64
58
  end
65
- Error = ____initErrorClass_2(nil, ____class_0, "Error")
59
+ Error = ____initErrorClass_1(nil, ____class_0, "Error")
66
60
  local function createErrorClass(self, name)
67
- local ____initErrorClass_4 = initErrorClass
68
- local ____class_3 = __TS__Class()
69
- ____class_3.name = ____class_3.name
70
- __TS__ClassExtends(____class_3, Error)
71
- function ____class_3.prototype.____constructor(self, ...)
72
- ____class_3.____super.prototype.____constructor(
61
+ local ____initErrorClass_3 = initErrorClass
62
+ local ____class_2 = __TS__Class()
63
+ ____class_2.name = ____class_2.name
64
+ __TS__ClassExtends(____class_2, Error)
65
+ function ____class_2.prototype.____constructor(self, ...)
66
+ ____class_2.____super.prototype.____constructor(
73
67
  self,
74
68
  unpack(arg)
75
69
  )
76
70
  self.name = name
77
71
  end
78
- return ____initErrorClass_4(nil, ____class_3, name)
72
+ return ____initErrorClass_3(nil, ____class_2, name)
79
73
  end
80
74
  RangeError = createErrorClass(nil, "RangeError")
81
75
  ReferenceError = createErrorClass(nil, "ReferenceError")
@@ -43,13 +43,13 @@ do
43
43
  self.size = self.size - 1
44
44
  local next = self.nextKey[key]
45
45
  local previous = self.previousKey[key]
46
- if next and previous then
46
+ if next ~= nil and previous ~= nil then
47
47
  self.nextKey[previous] = next
48
48
  self.previousKey[next] = previous
49
- elseif next then
49
+ elseif next ~= nil then
50
50
  self.firstKey = next
51
51
  self.previousKey[next] = nil
52
- elseif previous then
52
+ elseif previous ~= nil then
53
53
  self.lastKey = previous
54
54
  self.nextKey[previous] = nil
55
55
  else
@@ -1,10 +1,4 @@
1
1
  local function __TS__MathModf(x)
2
- local ____temp_0
3
- if x > 0 then
4
- ____temp_0 = math.floor(x)
5
- else
6
- ____temp_0 = math.ceil(x)
7
- end
8
- local integral = ____temp_0
2
+ local integral = x > 0 and math.floor(x) or math.ceil(x)
9
3
  return integral, x - integral
10
4
  end
@@ -1,11 +1,5 @@
1
1
  local function __TS__ObjectDefineProperty(target, key, desc)
2
- local ____temp_0
3
- if type(key) == "number" then
4
- ____temp_0 = key + 1
5
- else
6
- ____temp_0 = key
7
- end
8
- local luaKey = ____temp_0
2
+ local luaKey = type(key) == "number" and key + 1 or key
9
3
  local value = rawget(target, luaKey)
10
4
  local hasGetterOrSetter = desc.get ~= nil or desc.set ~= nil
11
5
  local descriptor
@@ -19,39 +13,39 @@ local function __TS__ObjectDefineProperty(target, key, desc)
19
13
  descriptor = desc
20
14
  else
21
15
  local valueExists = value ~= nil
22
- local ____desc_set_5 = desc.set
23
- local ____desc_get_6 = desc.get
24
- local ____temp_1
16
+ local ____desc_set_4 = desc.set
17
+ local ____desc_get_5 = desc.get
18
+ local ____temp_0
25
19
  if desc.configurable ~= nil then
26
- ____temp_1 = desc.configurable
20
+ ____temp_0 = desc.configurable
27
21
  else
28
- ____temp_1 = valueExists
22
+ ____temp_0 = valueExists
29
23
  end
30
- local ____temp_2
24
+ local ____temp_1
31
25
  if desc.enumerable ~= nil then
32
- ____temp_2 = desc.enumerable
26
+ ____temp_1 = desc.enumerable
33
27
  else
34
- ____temp_2 = valueExists
28
+ ____temp_1 = valueExists
35
29
  end
36
- local ____temp_3
30
+ local ____temp_2
37
31
  if desc.writable ~= nil then
38
- ____temp_3 = desc.writable
32
+ ____temp_2 = desc.writable
39
33
  else
40
- ____temp_3 = valueExists
34
+ ____temp_2 = valueExists
41
35
  end
42
- local ____temp_4
36
+ local ____temp_3
43
37
  if desc.value ~= nil then
44
- ____temp_4 = desc.value
38
+ ____temp_3 = desc.value
45
39
  else
46
- ____temp_4 = value
40
+ ____temp_3 = value
47
41
  end
48
42
  descriptor = {
49
- set = ____desc_set_5,
50
- get = ____desc_get_6,
51
- configurable = ____temp_1,
52
- enumerable = ____temp_2,
53
- writable = ____temp_3,
54
- value = ____temp_4
43
+ set = ____desc_set_4,
44
+ get = ____desc_get_5,
45
+ configurable = ____temp_0,
46
+ enumerable = ____temp_1,
47
+ writable = ____temp_2,
48
+ value = ____temp_3
55
49
  }
56
50
  end
57
51
  __TS__SetDescriptor(target, luaKey, descriptor)
@@ -1,13 +1,7 @@
1
1
  local function __TS__ParseFloat(numberString)
2
2
  local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
3
- if infinityMatch then
4
- local ____temp_0
5
- if __TS__StringAccess(infinityMatch, 0) == "-" then
6
- ____temp_0 = -(1 / 0)
7
- else
8
- ____temp_0 = 1 / 0
9
- end
10
- return ____temp_0
3
+ if infinityMatch ~= nil then
4
+ return __TS__StringAccess(infinityMatch, 0) == "-" and -(1 / 0) or 1 / 0
11
5
  end
12
6
  local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
13
7
  return number or 0 / 0
@@ -5,33 +5,21 @@ do
5
5
  if base == nil then
6
6
  base = 10
7
7
  local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
8
- if hexMatch then
8
+ if hexMatch ~= nil then
9
9
  base = 16
10
- local ____TS__Match_result__0_0
11
- if __TS__Match(hexMatch, "-") then
12
- ____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(
13
- numberString,
14
- string.len(hexMatch)
15
- )
16
- else
17
- ____TS__Match_result__0_0 = __TS__StringSubstring(
18
- numberString,
19
- string.len(hexMatch)
20
- )
21
- end
22
- numberString = ____TS__Match_result__0_0
10
+ numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(
11
+ numberString,
12
+ string.len(hexMatch)
13
+ ) or __TS__StringSubstring(
14
+ numberString,
15
+ string.len(hexMatch)
16
+ )
23
17
  end
24
18
  end
25
19
  if base < 2 or base > 36 then
26
20
  return 0 / 0
27
21
  end
28
- local ____temp_1
29
- if base <= 10 then
30
- ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
31
- else
32
- ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
33
- end
34
- local allowedDigits = ____temp_1
22
+ local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
35
23
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
36
24
  local number = tonumber(
37
25
  __TS__Match(numberString, pattern),
@@ -55,13 +55,13 @@ do
55
55
  self.size = self.size - 1
56
56
  local next = self.nextKey[value]
57
57
  local previous = self.previousKey[value]
58
- if next and previous then
58
+ if next ~= nil and previous ~= nil then
59
59
  self.nextKey[previous] = next
60
60
  self.previousKey[next] = previous
61
- elseif next then
61
+ elseif next ~= nil then
62
62
  self.firstKey = next
63
63
  self.previousKey[next] = nil
64
- elseif previous then
64
+ elseif previous ~= nil then
65
65
  self.lastKey = previous
66
66
  self.nextKey[previous] = nil
67
67
  else
@@ -14,7 +14,7 @@ do
14
14
  local descriptors = rawget(metatable, "_descriptors")
15
15
  if descriptors then
16
16
  local descriptor = descriptors[key]
17
- if descriptor then
17
+ if descriptor ~= nil then
18
18
  if descriptor.get then
19
19
  return descriptor.get(self)
20
20
  end
@@ -30,7 +30,7 @@ do
30
30
  local descriptors = rawget(metatable, "_descriptors")
31
31
  if descriptors then
32
32
  local descriptor = descriptors[key]
33
- if descriptor then
33
+ if descriptor ~= nil then
34
34
  if descriptor.set then
35
35
  descriptor.set(self, value)
36
36
  else
@@ -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