typescript-to-lua 0.42.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/CompilerOptions.d.ts +4 -3
  3. package/dist/LuaAST.js +4 -4
  4. package/dist/LuaLib.d.ts +7 -0
  5. package/dist/LuaLib.js +32 -1
  6. package/dist/LuaPrinter.d.ts +6 -2
  7. package/dist/LuaPrinter.js +25 -16
  8. package/dist/cli/diagnostics.js +2 -2
  9. package/dist/cli/parse.d.ts +1 -1
  10. package/dist/cli/parse.js +14 -0
  11. package/dist/cli/report.js +1 -1
  12. package/dist/cli/tsconfig.js +4 -4
  13. package/dist/lualib/Await.lua +59 -0
  14. package/dist/lualib/OptionalMethodCall.lua +3 -1
  15. package/dist/lualib/Promise.lua +172 -0
  16. package/dist/lualib/PromiseAll.lua +44 -0
  17. package/dist/lualib/PromiseAllSettled.lua +48 -0
  18. package/dist/lualib/PromiseAny.lua +41 -0
  19. package/dist/lualib/PromiseRace.lua +28 -0
  20. package/dist/lualib/SourceMapTraceBack.lua +20 -10
  21. package/dist/lualib/StringReplace.lua +8 -13
  22. package/dist/lualib/StringReplaceAll.lua +35 -0
  23. package/dist/lualib/lualib_bundle.lua +503 -62
  24. package/dist/transformation/builtins/array.js +29 -29
  25. package/dist/transformation/builtins/console.js +2 -2
  26. package/dist/transformation/builtins/function.js +9 -9
  27. package/dist/transformation/builtins/global.js +8 -8
  28. package/dist/transformation/builtins/index.js +35 -32
  29. package/dist/transformation/builtins/math.js +4 -4
  30. package/dist/transformation/builtins/number.js +7 -7
  31. package/dist/transformation/builtins/object.js +11 -11
  32. package/dist/transformation/builtins/promise.d.ts +7 -0
  33. package/dist/transformation/builtins/promise.js +46 -0
  34. package/dist/transformation/builtins/string.js +32 -30
  35. package/dist/transformation/builtins/symbol.js +3 -3
  36. package/dist/transformation/context/context.js +5 -5
  37. package/dist/transformation/index.js +1 -1
  38. package/dist/transformation/utils/annotations.d.ts +1 -4
  39. package/dist/transformation/utils/annotations.js +2 -39
  40. package/dist/transformation/utils/assignment-validation.js +8 -7
  41. package/dist/transformation/utils/diagnostics.d.ts +3 -0
  42. package/dist/transformation/utils/diagnostics.js +6 -5
  43. package/dist/transformation/utils/export.d.ts +3 -2
  44. package/dist/transformation/utils/export.js +14 -7
  45. package/dist/transformation/utils/function-context.js +19 -13
  46. package/dist/transformation/utils/lua-ast.js +18 -19
  47. package/dist/transformation/utils/lualib.js +1 -1
  48. package/dist/transformation/utils/safe-names.js +5 -5
  49. package/dist/transformation/utils/scope.d.ts +6 -0
  50. package/dist/transformation/utils/scope.js +70 -40
  51. package/dist/transformation/utils/symbols.js +6 -6
  52. package/dist/transformation/utils/transform.js +3 -3
  53. package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
  54. package/dist/transformation/utils/typescript/nodes.js +21 -1
  55. package/dist/transformation/visitors/access.js +16 -16
  56. package/dist/transformation/visitors/async-await.d.ts +6 -0
  57. package/dist/transformation/visitors/async-await.js +38 -0
  58. package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
  59. package/dist/transformation/visitors/binary-expression/bit.js +4 -4
  60. package/dist/transformation/visitors/binary-expression/compound.js +18 -18
  61. package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
  62. package/dist/transformation/visitors/binary-expression/index.js +21 -21
  63. package/dist/transformation/visitors/block.js +6 -6
  64. package/dist/transformation/visitors/break-continue.js +4 -9
  65. package/dist/transformation/visitors/call.js +38 -33
  66. package/dist/transformation/visitors/class/decorators.js +3 -3
  67. package/dist/transformation/visitors/class/index.js +41 -34
  68. package/dist/transformation/visitors/class/members/accessors.js +6 -6
  69. package/dist/transformation/visitors/class/members/constructor.js +7 -7
  70. package/dist/transformation/visitors/class/members/fields.js +6 -6
  71. package/dist/transformation/visitors/class/members/method.js +6 -6
  72. package/dist/transformation/visitors/class/new.js +13 -13
  73. package/dist/transformation/visitors/class/setup.js +11 -11
  74. package/dist/transformation/visitors/class/utils.js +2 -2
  75. package/dist/transformation/visitors/conditional.js +6 -6
  76. package/dist/transformation/visitors/delete.js +4 -4
  77. package/dist/transformation/visitors/enum.js +8 -8
  78. package/dist/transformation/visitors/errors.js +30 -31
  79. package/dist/transformation/visitors/expression-statement.js +10 -6
  80. package/dist/transformation/visitors/function.js +33 -21
  81. package/dist/transformation/visitors/identifier.js +25 -19
  82. package/dist/transformation/visitors/index.js +4 -2
  83. package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
  84. package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
  85. package/dist/transformation/visitors/language-extensions/multi.js +5 -7
  86. package/dist/transformation/visitors/language-extensions/operators.js +6 -6
  87. package/dist/transformation/visitors/language-extensions/range.js +6 -6
  88. package/dist/transformation/visitors/language-extensions/table.js +5 -5
  89. package/dist/transformation/visitors/literal.d.ts +1 -2
  90. package/dist/transformation/visitors/literal.js +19 -42
  91. package/dist/transformation/visitors/loops/do-while.js +2 -2
  92. package/dist/transformation/visitors/loops/for-in.js +4 -4
  93. package/dist/transformation/visitors/loops/for-of.js +13 -13
  94. package/dist/transformation/visitors/loops/for.js +3 -3
  95. package/dist/transformation/visitors/loops/utils.js +9 -9
  96. package/dist/transformation/visitors/modules/export.js +13 -14
  97. package/dist/transformation/visitors/modules/import.js +10 -10
  98. package/dist/transformation/visitors/namespace.js +13 -13
  99. package/dist/transformation/visitors/return.d.ts +1 -0
  100. package/dist/transformation/visitors/return.js +41 -49
  101. package/dist/transformation/visitors/sourceFile.js +8 -8
  102. package/dist/transformation/visitors/spread.js +16 -11
  103. package/dist/transformation/visitors/switch.js +132 -30
  104. package/dist/transformation/visitors/template.js +5 -5
  105. package/dist/transformation/visitors/typeof.js +2 -2
  106. package/dist/transformation/visitors/typescript.js +1 -1
  107. package/dist/transformation/visitors/unary-expression.js +9 -9
  108. package/dist/transformation/visitors/variable-declaration.js +28 -28
  109. package/dist/transformation/visitors/void.d.ts +6 -0
  110. package/dist/transformation/visitors/void.js +23 -0
  111. package/dist/transpilation/bundle.d.ts +3 -0
  112. package/dist/transpilation/bundle.js +56 -13
  113. package/dist/transpilation/diagnostics.js +3 -3
  114. package/dist/transpilation/index.js +2 -2
  115. package/dist/transpilation/output-collector.js +2 -2
  116. package/dist/transpilation/plugins.js +1 -1
  117. package/dist/transpilation/resolve.js +28 -15
  118. package/dist/transpilation/transformers.d.ts +1 -0
  119. package/dist/transpilation/transformers.js +61 -25
  120. package/dist/transpilation/transpile.js +7 -7
  121. package/dist/transpilation/transpiler.js +8 -8
  122. package/dist/transpilation/utils.js +3 -2
  123. package/dist/tstl.js +8 -8
  124. package/dist/utils.js +2 -2
  125. package/package.json +15 -12
  126. package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
  127. package/dist/transformation/visitors/jsx/jsx.js +0 -237
  128. package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
  129. package/dist/transformation/visitors/jsx/xhtml.js +0 -260
@@ -0,0 +1,172 @@
1
+ __TS__PromiseState = __TS__PromiseState or ({})
2
+ __TS__PromiseState.Pending = 0
3
+ __TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
4
+ __TS__PromiseState.Fulfilled = 1
5
+ __TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
6
+ __TS__PromiseState.Rejected = 2
7
+ __TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
8
+ function __TS__PromiseDeferred(self)
9
+ local resolve
10
+ local reject
11
+ local promise = __TS__New(
12
+ __TS__Promise,
13
+ function(____, res, rej)
14
+ resolve = res
15
+ reject = rej
16
+ end
17
+ )
18
+ return {promise = promise, resolve = resolve, reject = reject}
19
+ end
20
+ function __TS__IsPromiseLike(self, thing)
21
+ return __TS__InstanceOf(thing, __TS__Promise)
22
+ end
23
+ __TS__Promise = __TS__Class()
24
+ __TS__Promise.name = "__TS__Promise"
25
+ function __TS__Promise.prototype.____constructor(self, executor)
26
+ self.state = __TS__PromiseState.Pending
27
+ self.fulfilledCallbacks = {}
28
+ self.rejectedCallbacks = {}
29
+ self.finallyCallbacks = {}
30
+ do
31
+ local function ____catch(e)
32
+ self:reject(e)
33
+ end
34
+ local ____try, ____hasReturned = pcall(
35
+ function()
36
+ executor(
37
+ _G,
38
+ __TS__FunctionBind(self.resolve, self),
39
+ __TS__FunctionBind(self.reject, self)
40
+ )
41
+ end
42
+ )
43
+ if not ____try then
44
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
45
+ end
46
+ end
47
+ end
48
+ function __TS__Promise.resolve(data)
49
+ local promise = __TS__New(
50
+ __TS__Promise,
51
+ function()
52
+ end
53
+ )
54
+ promise.state = __TS__PromiseState.Fulfilled
55
+ promise.value = data
56
+ return promise
57
+ end
58
+ function __TS__Promise.reject(reason)
59
+ local promise = __TS__New(
60
+ __TS__Promise,
61
+ function()
62
+ end
63
+ )
64
+ promise.state = __TS__PromiseState.Rejected
65
+ promise.rejectionReason = reason
66
+ return promise
67
+ end
68
+ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
69
+ local ____ = __TS__PromiseDeferred(_G)
70
+ local promise = ____.promise
71
+ local resolve = ____.resolve
72
+ local reject = ____.reject
73
+ local isFulfilled = self.state == __TS__PromiseState.Fulfilled
74
+ local isRejected = self.state == __TS__PromiseState.Rejected
75
+ if onFulfilled then
76
+ local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
77
+ __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
78
+ if isFulfilled then
79
+ internalCallback(_G, self.value)
80
+ end
81
+ else
82
+ __TS__ArrayPush(
83
+ self.fulfilledCallbacks,
84
+ function() return resolve(_G, nil) end
85
+ )
86
+ end
87
+ if onRejected then
88
+ local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
89
+ __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
90
+ if isRejected then
91
+ internalCallback(_G, self.rejectionReason)
92
+ end
93
+ end
94
+ if isFulfilled then
95
+ resolve(_G, self.value)
96
+ end
97
+ if isRejected then
98
+ reject(_G, self.rejectionReason)
99
+ end
100
+ return promise
101
+ end
102
+ function __TS__Promise.prototype.catch(self, onRejected)
103
+ return self["then"](self, nil, onRejected)
104
+ end
105
+ function __TS__Promise.prototype.finally(self, onFinally)
106
+ if onFinally then
107
+ __TS__ArrayPush(self.finallyCallbacks, onFinally)
108
+ if self.state ~= __TS__PromiseState.Pending then
109
+ onFinally(_G)
110
+ end
111
+ end
112
+ return self
113
+ end
114
+ function __TS__Promise.prototype.resolve(self, data)
115
+ if self.state == __TS__PromiseState.Pending then
116
+ self.state = __TS__PromiseState.Fulfilled
117
+ self.value = data
118
+ for ____, callback in ipairs(self.fulfilledCallbacks) do
119
+ callback(_G, data)
120
+ end
121
+ for ____, callback in ipairs(self.finallyCallbacks) do
122
+ callback(_G)
123
+ end
124
+ end
125
+ end
126
+ function __TS__Promise.prototype.reject(self, reason)
127
+ if self.state == __TS__PromiseState.Pending then
128
+ self.state = __TS__PromiseState.Rejected
129
+ self.rejectionReason = reason
130
+ for ____, callback in ipairs(self.rejectedCallbacks) do
131
+ callback(_G, reason)
132
+ end
133
+ for ____, callback in ipairs(self.finallyCallbacks) do
134
+ callback(_G)
135
+ end
136
+ end
137
+ end
138
+ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
139
+ return function(____, value)
140
+ do
141
+ local function ____catch(e)
142
+ reject(_G, e)
143
+ end
144
+ local ____try, ____hasReturned = pcall(
145
+ function()
146
+ self:handleCallbackData(
147
+ f(_G, value),
148
+ resolve,
149
+ reject
150
+ )
151
+ end
152
+ )
153
+ if not ____try then
154
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
155
+ end
156
+ end
157
+ end
158
+ end
159
+ function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
160
+ if __TS__IsPromiseLike(_G, data) then
161
+ local nextpromise = data
162
+ if nextpromise.state == __TS__PromiseState.Fulfilled then
163
+ resolve(_G, nextpromise.value)
164
+ elseif nextpromise.state == __TS__PromiseState.Rejected then
165
+ reject(_G, nextpromise.rejectionReason)
166
+ else
167
+ data["then"](data, resolve, reject)
168
+ end
169
+ else
170
+ resolve(_G, data)
171
+ end
172
+ end
@@ -0,0 +1,44 @@
1
+ function __TS__PromiseAll(iterable)
2
+ local results = {}
3
+ local toResolve = {}
4
+ local numToResolve = 0
5
+ local i = 0
6
+ for ____, item in __TS__Iterator(iterable) do
7
+ if __TS__InstanceOf(item, __TS__Promise) then
8
+ if item.state == __TS__PromiseState.Fulfilled then
9
+ results[i + 1] = item.value
10
+ elseif item.state == __TS__PromiseState.Rejected then
11
+ return __TS__Promise.reject(item.rejectionReason)
12
+ else
13
+ numToResolve = numToResolve + 1
14
+ toResolve[i] = item
15
+ end
16
+ else
17
+ results[i + 1] = item
18
+ end
19
+ i = i + 1
20
+ end
21
+ if numToResolve == 0 then
22
+ return __TS__Promise.resolve(results)
23
+ end
24
+ return __TS__New(
25
+ __TS__Promise,
26
+ function(____, resolve, reject)
27
+ for index, promise in pairs(toResolve) do
28
+ promise["then"](
29
+ promise,
30
+ function(____, data)
31
+ results[index + 1] = data
32
+ numToResolve = numToResolve - 1
33
+ if numToResolve == 0 then
34
+ resolve(_G, results)
35
+ end
36
+ end,
37
+ function(____, reason)
38
+ reject(_G, reason)
39
+ end
40
+ )
41
+ end
42
+ end
43
+ )
44
+ end
@@ -0,0 +1,48 @@
1
+ function __TS__PromiseAllSettled(iterable)
2
+ local results = {}
3
+ local toResolve = {}
4
+ local numToResolve = 0
5
+ local i = 0
6
+ for ____, item in __TS__Iterator(iterable) do
7
+ if __TS__InstanceOf(item, __TS__Promise) then
8
+ if item.state == __TS__PromiseState.Fulfilled then
9
+ results[i + 1] = {status = "fulfilled", value = item.value}
10
+ elseif item.state == __TS__PromiseState.Rejected then
11
+ results[i + 1] = {status = "rejected", reason = item.rejectionReason}
12
+ else
13
+ numToResolve = numToResolve + 1
14
+ toResolve[i] = item
15
+ end
16
+ else
17
+ results[i + 1] = {status = "fulfilled", value = item}
18
+ end
19
+ i = i + 1
20
+ end
21
+ if numToResolve == 0 then
22
+ return __TS__Promise.resolve(results)
23
+ end
24
+ return __TS__New(
25
+ __TS__Promise,
26
+ function(____, resolve)
27
+ for index, promise in pairs(toResolve) do
28
+ promise["then"](
29
+ promise,
30
+ function(____, data)
31
+ results[index + 1] = {status = "fulfilled", value = data}
32
+ numToResolve = numToResolve - 1
33
+ if numToResolve == 0 then
34
+ resolve(_G, results)
35
+ end
36
+ end,
37
+ function(____, reason)
38
+ results[index + 1] = {status = "rejected", reason = reason}
39
+ numToResolve = numToResolve - 1
40
+ if numToResolve == 0 then
41
+ resolve(_G, results)
42
+ end
43
+ end
44
+ )
45
+ end
46
+ end
47
+ )
48
+ end
@@ -0,0 +1,41 @@
1
+ function __TS__PromiseAny(iterable)
2
+ local rejections = {}
3
+ local pending = {}
4
+ for ____, item in __TS__Iterator(iterable) do
5
+ if __TS__InstanceOf(item, __TS__Promise) then
6
+ if item.state == __TS__PromiseState.Fulfilled then
7
+ return __TS__Promise.resolve(item.value)
8
+ elseif item.state == __TS__PromiseState.Rejected then
9
+ __TS__ArrayPush(rejections, item.rejectionReason)
10
+ else
11
+ __TS__ArrayPush(pending, item)
12
+ end
13
+ else
14
+ return __TS__Promise.resolve(item)
15
+ end
16
+ end
17
+ if #pending == 0 then
18
+ return __TS__Promise.reject("No promises to resolve with .any()")
19
+ end
20
+ local numResolved = 0
21
+ return __TS__New(
22
+ __TS__Promise,
23
+ function(____, resolve, reject)
24
+ for ____, promise in ipairs(pending) do
25
+ promise["then"](
26
+ promise,
27
+ function(____, data)
28
+ resolve(_G, data)
29
+ end,
30
+ function(____, reason)
31
+ __TS__ArrayPush(rejections, reason)
32
+ numResolved = numResolved + 1
33
+ if numResolved == #pending then
34
+ reject(_G, {name = "AggregateError", message = "All Promises rejected", errors = rejections})
35
+ end
36
+ end
37
+ )
38
+ end
39
+ end
40
+ )
41
+ end
@@ -0,0 +1,28 @@
1
+ function __TS__PromiseRace(iterable)
2
+ local pending = {}
3
+ for ____, item in __TS__Iterator(iterable) do
4
+ if __TS__InstanceOf(item, __TS__Promise) then
5
+ if item.state == __TS__PromiseState.Fulfilled then
6
+ return __TS__Promise.resolve(item.value)
7
+ elseif item.state == __TS__PromiseState.Rejected then
8
+ return __TS__Promise.reject(item.rejectionReason)
9
+ else
10
+ __TS__ArrayPush(pending, item)
11
+ end
12
+ else
13
+ return __TS__Promise.resolve(item)
14
+ end
15
+ end
16
+ return __TS__New(
17
+ __TS__Promise,
18
+ function(____, resolve, reject)
19
+ for ____, promise in ipairs(pending) do
20
+ promise["then"](
21
+ promise,
22
+ function(____, value) return resolve(_G, value) end,
23
+ function(____, reason) return reject(_G, reason) end
24
+ )
25
+ end
26
+ end
27
+ )
28
+ end
@@ -6,23 +6,33 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
6
6
  debug.traceback = function(thread, message, level)
7
7
  local trace
8
8
  if ((thread == nil) and (message == nil)) and (level == nil) then
9
- trace = _G:__TS__originalTraceback()
9
+ trace = _G.__TS__originalTraceback()
10
10
  else
11
- trace = _G:__TS__originalTraceback(thread, message, level)
11
+ trace = _G.__TS__originalTraceback(thread, message, level)
12
12
  end
13
13
  if type(trace) ~= "string" then
14
14
  return trace
15
15
  end
16
- local result = string.gsub(
17
- trace,
18
- "(%S+).lua:(%d+)",
19
- function(file, line)
20
- local fileSourceMap = _G.__TS__sourcemap[file .. ".lua"]
21
- if fileSourceMap and fileSourceMap[line] then
22
- return (file .. ".ts:") .. tostring(fileSourceMap[line])
16
+ local function replacer(____, file, srcFile, line)
17
+ local fileSourceMap = _G.__TS__sourcemap[file]
18
+ if fileSourceMap and fileSourceMap[line] then
19
+ local data = fileSourceMap[line]
20
+ if type(data) == "number" then
21
+ return (srcFile .. ":") .. tostring(data)
23
22
  end
24
- return (file .. ".lua:") .. line
23
+ return (tostring(data.file) .. ":") .. tostring(data.line)
25
24
  end
25
+ return (file .. ":") .. line
26
+ end
27
+ local result = string.gsub(
28
+ trace,
29
+ "(%S+)%.lua:(%d+)",
30
+ function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
31
+ )
32
+ result = string.gsub(
33
+ result,
34
+ "(%[string \"[^\"]+\"%]):(%d+)",
35
+ function(file, line) return replacer(_G, file, "unknown", line) end
26
36
  )
27
37
  return result
28
38
  end
@@ -1,16 +1,11 @@
1
1
  function __TS__StringReplace(source, searchValue, replaceValue)
2
- searchValue = string.gsub(searchValue, "[%%%(%)%.%+%-%*%?%[%^%$]", "%%%1")
3
- if type(replaceValue) == "string" then
4
- replaceValue = string.gsub(replaceValue, "%%", "%%%%")
5
- local result = string.gsub(source, searchValue, replaceValue, 1)
6
- return result
7
- else
8
- local result = string.gsub(
9
- source,
10
- searchValue,
11
- function(match) return replaceValue(_G, match) end,
12
- 1
13
- )
14
- return result
2
+ local startPos, endPos = string.find(source, searchValue, nil, true)
3
+ if not startPos then
4
+ return source
15
5
  end
6
+ local sub = string.sub
7
+ local before = sub(source, 1, startPos - 1)
8
+ local replacement = (((type(replaceValue) == "string") and (function() return replaceValue end)) or (function() return replaceValue(_G, searchValue, startPos - 1, source) end))()
9
+ local after = sub(source, endPos + 1)
10
+ return (before .. replacement) .. after
16
11
  end
@@ -0,0 +1,35 @@
1
+ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2
+ local replacer
3
+ if type(replaceValue) == "string" then
4
+ replacer = function() return replaceValue end
5
+ else
6
+ replacer = replaceValue
7
+ end
8
+ local parts = {}
9
+ local partsIndex = 1
10
+ local sub = string.sub
11
+ if #searchValue == 0 then
12
+ parts[1] = replacer(_G, "", 0, source)
13
+ partsIndex = 2
14
+ for i = 1, #source do
15
+ parts[partsIndex] = sub(source, i, i)
16
+ parts[partsIndex + 1] = replacer(_G, "", i, source)
17
+ partsIndex = partsIndex + 2
18
+ end
19
+ else
20
+ local find = string.find
21
+ local currentPos = 1
22
+ while true do
23
+ local startPos, endPos = find(source, searchValue, currentPos, true)
24
+ if not startPos then
25
+ break
26
+ end
27
+ parts[partsIndex] = sub(source, currentPos, startPos - 1)
28
+ parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
29
+ partsIndex = partsIndex + 2
30
+ currentPos = endPos + 1
31
+ end
32
+ parts[partsIndex] = sub(source, currentPos)
33
+ end
34
+ return table.concat(parts)
35
+ end