Use weak tables in tree-sitter code (#17117)

feat(treesitter): use weak tables when possible

Also add the defaulttable function to create a table whose values are created when a key is missing.
This commit is contained in:
Thomas Vigouroux
2022-09-07 08:39:56 +02:00
committed by GitHub
parent f32fd19f1e
commit fd1595514b
5 changed files with 69 additions and 10 deletions

View File

@@ -2754,6 +2754,24 @@ describe('lua stdlib', function()
end)
describe("vim.defaulttable", function()
it("creates nested table by default", function()
eq({ b = {c = 1 } }, exec_lua[[
local a = vim.defaulttable()
a.b.c = 1
return a
]])
end)
it("allows to create default objects", function()
eq({ b = 1 }, exec_lua[[
local a = vim.defaulttable(function() return 0 end)
a.b = a.b + 1
return a
]])
end)
end)
end)
describe('lua: builtin modules', function()