summaryrefslogtreecommitdiff
path: root/script/vm/node.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-19 23:54:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-19 23:54:02 +0800
commit6f3d539072512feb34d9d759f8b2adb09733fbdc (patch)
tree8b7e474fc691c664a742eacb1160a0e629f562bf /script/vm/node.lua
parentc8a4a575caf8e1cc4a44b26dd824112e790782ac (diff)
downloadlua-language-server-6f3d539072512feb34d9d759f8b2adb09733fbdc.zip
update runner
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r--script/vm/node.lua32
1 files changed, 29 insertions, 3 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 99bc3340..a4e22b68 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -93,8 +93,34 @@ function mt:isFalsy()
return false
end
-function mt:removeFalsy()
-
+---@return vm.node
+function mt:copyTruly()
+ local newNode = vm.createNode()
+ newNode.optional = false
+ local hasBoolean, hasTrue
+ 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
+ goto CONTINUE
+ end
+ if c.type == 'global' and c.cate == 'type' and c.name == 'boolean' then
+ hasBoolean = true
+ goto CONTINUE
+ end
+ if c.type == 'boolean' or c.type == 'doc.type.boolean' then
+ hasTrue = true
+ end
+ newNode:merge(c)
+ ::CONTINUE::
+ end
+ if hasBoolean and not hasTrue then
+ newNode:merge {
+ type = 'doc.type.boolean',
+ [1] = true,
+ }
+ end
+ return newNode
end
---@return fun():vm.object
@@ -130,7 +156,7 @@ function vm.setNode(source, node, cover)
me:merge(node)
else
if node.type == 'vm.node' then
- vm.nodeCache[source] = node
+ vm.nodeCache[source] = node:copy()
else
vm.nodeCache[source] = vm.createNode(node)
end