summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-22 00:36:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-22 00:36:32 +0800
commitd16545d285de2451b3d2c0a03cc299ef18ac0ca0 (patch)
treef2c10898ea928d651c6c563f88ac1e77c02c00d9 /script/vm/compiler.lua
parent629e8e052e444c51fb00e9d3af5a8c2a5ee371f8 (diff)
downloadlua-language-server-d16545d285de2451b3d2c0a03cc299ef18ac0ca0.zip
add `--[[@as type]]`
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 94968292..aee28366 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -478,6 +478,23 @@ local function getReturn(func, index, args)
return result
end
+---@param source parser.object
+---@return boolean
+local function bindAs(source)
+ local root = guide.getRoot(source)
+ local docs = root.docs
+ if not docs then
+ return
+ end
+ for _, doc in ipairs(docs) do
+ if doc.type == 'doc.as' and doc.originalComment.start == source.finish + 2 then
+ vm.setNode(source, vm.compileNode(doc.as), true)
+ return true
+ end
+ end
+ return false
+end
+
local function bindDocs(source)
local isParam = source.parent.type == 'funcargs'
or source.parent.type == 'in'
@@ -894,6 +911,9 @@ local compilerSwitch = util.switch()
end)
: case 'paren'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
if source.exp then
vm.setNode(source, vm.compileNode(source.exp))
end
@@ -924,6 +944,9 @@ local compilerSwitch = util.switch()
end
return vm.getNode(src)
elseif src.type == 'getlocal' then
+ if bindAs(src) then
+ return
+ end
vm.setNode(src, node, true)
end
end)
@@ -944,6 +967,9 @@ local compilerSwitch = util.switch()
end)
: case 'getlocal'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
vm.compileNode(source.node)
end)
: case 'setfield'
@@ -966,6 +992,9 @@ local compilerSwitch = util.switch()
: case 'getmethod'
: case 'getindex'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
compileByLocalID(source)
local key = guide.getKeyName(source)
if key == nil and source.index then
@@ -1001,6 +1030,9 @@ local compilerSwitch = util.switch()
end)
: case 'getglobal'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
if source.node[1] ~= '_ENV' then
return
end
@@ -1275,6 +1307,9 @@ local compilerSwitch = util.switch()
end)
: case 'unary'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
if source.op.type == 'not' then
local result = vm.test(source[1])
if result == nil then
@@ -1330,6 +1365,9 @@ local compilerSwitch = util.switch()
end)
: case 'binary'
: call(function (source)
+ if bindAs(source) then
+ return
+ end
if source.op.type == 'and' then
local r1 = vm.test(source[1])
if r1 == true then