diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-17 04:24:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-17 04:24:44 +0800 |
commit | fbb028fa8ac1c1d146e4e6aecda03442af9ddee8 (patch) | |
tree | bd0e28e93525f9f95754800f118d77c8ae8cecc9 /script/vm/node.lua | |
parent | 103d77b9789d0e9d420479dd7b746827ce79e3da (diff) | |
download | lua-language-server-fbb028fa8ac1c1d146e4e6aecda03442af9ddee8.zip |
fix optional
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 3145a34d..6ef7c9d5 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -146,43 +146,30 @@ function mt:getData(k) end function mt:addOptional() - if self:isOptional() then - return self - end self.optional = true end function mt:removeOptional() - if not self:isOptional() then - return self - end - self:_expand() - for i = #self, 1, -1 do - local n = self[i] - if n.type == 'nil' - or (n.type == 'boolean' and n[1] == false) - or (n.type == 'doc.type.boolean' and n[1] == false) then - self[i] = self[#self] - self[#self] = nil - end - end + self.optional = false end ---@return boolean function mt:isOptional() - if self.optional ~= nil then - return self.optional + return self.optional == true +end + +---@return boolean +function mt:isFalsy() + if self.optional then + return true end - self:_expand() for _, c in ipairs(self) do if c.type == 'nil' or (c.type == 'boolean' and c[1] == false) or (c.type == 'doc.type.boolean' and c[1] == false) then - self.optional = true return true end end - self.optional = false return false end @@ -196,6 +183,11 @@ function mt:eachObject() end end +---@return vm.node +function mt:copy() + return vm.createNode(self) +end + ---@param source parser.object | vm.generic ---@param node vm.node | vm.object ---@param cover? boolean |