@@ -9,25 +9,32 @@ local vm = require 'vm.vm'
99--- @class parser.object
1010--- @field _compiledNodes boolean
1111--- @field _node vm.node
12+ --- @field package _hasBindedDocs ? boolean
1213--- @field cindex integer
1314--- @field func parser.object
1415
1516-- 该函数有副作用,会给source绑定node!
1617--- @param source parser.object
1718--- @return boolean
18- local function bindDocs (source )
19+ function vm . bindDocs (source )
1920 local docs = source .bindDocs
2021 if not docs then
2122 return false
2223 end
24+ if source ._hasBindedDocs ~= nil then
25+ return source ._hasBindedDocs
26+ end
27+ source ._hasBindedDocs = false
2328 for i = # docs , 1 , - 1 do
2429 local doc = docs [i ]
2530 if doc .type == ' doc.type' then
2631 vm .setNode (source , vm .compileNode (doc ))
32+ source ._hasBindedDocs = true
2733 return true
2834 end
2935 if doc .type == ' doc.class' then
3036 vm .setNode (source , vm .compileNode (doc ))
37+ source ._hasBindedDocs = true
3138 return true
3239 end
3340 if doc .type == ' doc.param' then
@@ -36,23 +43,28 @@ local function bindDocs(source)
3643 node :addOptional ()
3744 end
3845 vm .setNode (source , node )
46+ source ._hasBindedDocs = true
3947 return true
4048 end
4149 if doc .type == ' doc.module' then
4250 local name = doc .module
4351 if not name then
52+ source ._hasBindedDocs = true
4453 return true
4554 end
4655 local uri = rpath .findUrisByRequireName (guide .getUri (source ), name )[1 ]
4756 if not uri then
57+ source ._hasBindedDocs = true
4858 return true
4959 end
5060 local state = files .getState (uri )
5161 local ast = state and state .ast
5262 if not ast then
63+ source ._hasBindedDocs = true
5364 return true
5465 end
5566 vm .setNode (source , vm .compileNode (ast ))
67+ source ._hasBindedDocs = true
5668 return true
5769 end
5870 end
@@ -90,7 +102,7 @@ local function searchFieldByLocalID(source, key, pushResult)
90102 local hasMarkDoc = {}
91103 for _ , src in ipairs (fields ) do
92104 if src .bindDocs then
93- if bindDocs (src ) then
105+ if vm . bindDocs (src ) then
94106 local skey = guide .getKeyName (src )
95107 if skey then
96108 hasMarkDoc [skey ] = true
@@ -170,7 +182,7 @@ local searchFieldSwitch = util.switch()
170182 hasFiled = true
171183 pushResult (field )
172184 end
173- if key == nil then
185+ if key == vm . ANY then
174186 pushResult (field )
175187 end
176188 end
@@ -695,7 +707,7 @@ function vm.compileByParentNode(source, key, pushResult)
695707 pushResult (res )
696708 end
697709 end
698- if # docedResults == 0 or key == nil then
710+ if # docedResults == 0 or key == vm . ANY then
699711 for _ , res in ipairs (commonResults ) do
700712 pushResult (res )
701713 end
@@ -970,7 +982,7 @@ local function compileLocal(source)
970982
971983 local hasMarkDoc
972984 if source .bindDocs then
973- hasMarkDoc = bindDocs (source )
985+ hasMarkDoc = vm . bindDocs (source )
974986 end
975987 local hasMarkParam
976988 if not hasMarkDoc then
@@ -1035,7 +1047,7 @@ local function compileLocal(source)
10351047 -- for x = ... do
10361048 if source .parent .type == ' loop' then
10371049 if source .parent .loc == source then
1038- if bindDocs (source ) then
1050+ if vm . bindDocs (source ) then
10391051 return
10401052 end
10411053 vm .setNode (source , vm .declareGlobal (' type' , ' integer' ))
@@ -1199,7 +1211,7 @@ local compilerSwitch = util.switch()
11991211 end )
12001212 : case ' setlocal'
12011213 : call (function (source )
1202- if bindDocs (source ) then
1214+ if vm . bindDocs (source ) then
12031215 return
12041216 end
12051217 local locNode = vm .compileNode (source .node )
@@ -1236,7 +1248,7 @@ local compilerSwitch = util.switch()
12361248 : case ' getmethod'
12371249 : case ' getindex'
12381250 : call (function (source )
1239- if bindDocs (source ) then
1251+ if vm . bindDocs (source ) then
12401252 return
12411253 end
12421254 if guide .isGet (source ) and bindAs (source ) then
@@ -1278,7 +1290,7 @@ local compilerSwitch = util.switch()
12781290 end )
12791291 : case ' setglobal'
12801292 : call (function (source )
1281- if bindDocs (source ) then
1293+ if vm . bindDocs (source ) then
12821294 return
12831295 end
12841296 if source .node [1 ] ~= ' _ENV' then
@@ -1307,7 +1319,7 @@ local compilerSwitch = util.switch()
13071319 : call (function (source )
13081320 local hasMarkDoc
13091321 if source .bindDocs then
1310- hasMarkDoc = bindDocs (source )
1322+ hasMarkDoc = vm . bindDocs (source )
13111323 end
13121324
13131325 if not hasMarkDoc then
@@ -1875,9 +1887,10 @@ function vm.compileNode(source)
18751887
18761888 --- @cast source parser.object
18771889 vm .setNode (source , vm .createNode (), true )
1878- vm .compileByGlobal (source )
1879- vm .compileByVariable (source )
1880- compileByNode (source )
1890+ if not vm .compileByGlobal (source ) then
1891+ vm .compileByVariable (source )
1892+ compileByNode (source )
1893+ end
18811894 compileByParentNode (source )
18821895 matchCall (source )
18831896
0 commit comments