summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-29 17:43:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-29 17:43:45 +0800
commite5f07d0c9830afdfa1ce3b354a123212e5837526 (patch)
treeae9b64471b1d6139d43e5d0193ff3c056f9e3c3f /script/vm/compiler.lua
parent1149fe63ddb1a3b6c9fac722e5dc3ab3ec61d74f (diff)
downloadlua-language-server-e5f07d0c9830afdfa1ce3b354a123212e5837526.zip
don't check `t.field = nil`
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 1abad3e3..7e26e08f 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -14,10 +14,15 @@ local vm = require 'vm.vm'
---@field func parser.object
-- 该函数有副作用,会给source绑定node!
+---@param source parser.object
+---@return boolean
local function bindDocs(source)
+ local docs = source.bindDocs
+ if not docs then
+ return false
+ end
local isParam = source.parent.type == 'funcargs'
or (source.parent.type == 'in' and source.finish <= source.parent.keys.finish)
- local docs = source.bindDocs
for i = #docs, 1, -1 do
local doc = docs[i]
if doc.type == 'doc.type' then
@@ -47,6 +52,9 @@ local function bindDocs(source)
end
if doc.type == 'doc.module' then
local name = doc.module
+ if not name then
+ return true
+ end
local uri = rpath.findUrisByRequirePath(guide.getUri(source), name)[1]
if not uri then
return true
@@ -1380,9 +1388,18 @@ local compilerSwitch = util.switch()
else
---@cast key string
vm.compileByParentNode(source.node, key, false, function (src)
- vm.setNode(source, vm.compileNode(src))
if src.value then
- vm.setNode(source, vm.compileNode(src.value))
+ if bindDocs(src) then
+ vm.setNode(source, vm.compileNode(src))
+ else
+ vm.setNode(source, vm.compileNode(src.value))
+ local node = vm.getNode(src)
+ if node then
+ vm.setNode(source, node)
+ end
+ end
+ else
+ vm.setNode(source, vm.compileNode(src))
end
end)
end