Skip to content

Commit e4bfc2f

Browse files
committed
Fixed splice not matching js standard
1 parent 0251281 commit e4bfc2f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

dist/lualib/typescript.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,25 @@ function TS_slice(list, startI, endI)
4141
end
4242

4343
function TS_splice(list, startI, deleteCount, ...)
44-
if not deleteCount then
45-
deleteCount = #list - startI
46-
else if deleteCount > #list - startI then
44+
if not deleteCount or deleteCount > #list - startI then
4745
deleteCount = #list - startI
4846
end
47+
startI = startI + 1
48+
local newElements = {...}
4949
local out = {}
50-
for i = startI + deleteCount, startI, -1 do
51-
table.insert(out, table.remove(list, i))
50+
local k = #newElements
51+
for i = startI + deleteCount - 1, startI, -1 do
52+
table.insert(out, list[i])
53+
if newElements[k] then
54+
list[i] = newElements[k]
55+
k = k - 1
56+
else
57+
table.remove(list, i)
58+
end
5259
end
53-
for _, value in ipairs({...}) do
54-
table.insert(list, value)
60+
while newElements[k] do
61+
table.insert(list, startI, newElements[k])
62+
k = k - 1
5563
end
5664
return out
5765
end

0 commit comments

Comments
 (0)