@@ -60,16 +60,16 @@ local function bindDocs(source)
6060end
6161
6262--- @param source parser.object | vm.variable
63- --- @param key any
63+ --- @param key string | vm.global | vm.ANY
6464--- @param pushResult fun ( res : parser.object , markDoc ?: boolean )
6565local function searchFieldByLocalID (source , key , pushResult )
6666 local fields
67- if key then
67+ if key ~= vm .ANY then
68+ if type (key ) ~= ' string' then
69+ return
70+ end
6871 if source .type == ' variable' then
6972 --- @cast source vm.variable
70- if type (key ) ~= ' string' then
71- return
72- end
7373 fields = source :getSets (key )
7474 else
7575 --- @cast source parser.object
@@ -109,15 +109,15 @@ end
109109
110110--- @param suri uri
111111--- @param source parser.object
112- --- @param key any
112+ --- @param key string | vm.global | vm.ANY
113113--- @param pushResult fun ( res : parser.object , markDoc ?: boolean )
114114local function searchFieldByGlobalID (suri , source , key , pushResult )
115115 local node = vm .getGlobalNode (source )
116116 if not node then
117117 return
118118 end
119119 if node .cate == ' variable' then
120- if key then
120+ if key ~= vm . ANY then
121121 if type (key ) ~= ' string' then
122122 return
123123 end
@@ -149,14 +149,14 @@ local searchFieldSwitch = util.switch()
149149 if field .type == ' tablefield'
150150 or field .type == ' tableindex' then
151151 local fieldKey = guide .getKeyName (field )
152- if key == nil
152+ if key == vm . ANY
153153 or key == fieldKey then
154154 hasFiled = true
155155 pushResult (field )
156156 end
157157 end
158158 if field .type == ' tableexp' then
159- if key == nil
159+ if key == vm . ANY
160160 or key == field .tindex then
161161 hasFiled = true
162162 pushResult (field )
@@ -211,7 +211,7 @@ local searchFieldSwitch = util.switch()
211211 local fieldNode = vm .compileNode (fieldKey )
212212 for fn in fieldNode :eachObject () do
213213 if fn .type == ' global' and fn .cate == ' type' then
214- if key == nil
214+ if key == vm . ANY
215215 or fn .name == ' any'
216216 or (fn .name == ' boolean' and type (key ) == ' boolean' )
217217 or (fn .name == ' number' and type (key ) == ' number' )
@@ -222,15 +222,15 @@ local searchFieldSwitch = util.switch()
222222 elseif fn .type == ' doc.type.string'
223223 or fn .type == ' doc.type.integer'
224224 or fn .type == ' doc.type.boolean' then
225- if key == nil
225+ if key == vm . ANY
226226 or fn [1 ] == key then
227227 pushResult (field )
228228 end
229229 end
230230 end
231231 end
232232 if fieldKey .type == ' doc.field.name' then
233- if key == nil or fieldKey [1 ] == key then
233+ if key == vm . ANY or fieldKey [1 ] == key then
234234 pushResult (field )
235235 end
236236 end
@@ -269,7 +269,7 @@ local searchFieldSwitch = util.switch()
269269
270270--- @param suri uri
271271--- @param object vm.global
272- --- @param key ? string | number | integer | boolean | vm.global
272+ --- @param key string | number | integer | boolean | vm.global | vm.ANY
273273--- @param pushResult fun ( field : vm.object , isMark ?: boolean )
274274function vm .getClassFields (suri , object , key , pushResult )
275275 local mark = {}
@@ -298,7 +298,7 @@ function vm.getClassFields(suri, object, key, pushResult)
298298 local fieldKey = guide .getKeyName (field )
299299 if fieldKey then
300300 -- ---@field x boolean -> class.x
301- if key == nil
301+ if key == vm . ANY
302302 or fieldKey == key then
303303 if not searchedFields [fieldKey ] then
304304 pushResult (field , true )
@@ -307,7 +307,7 @@ function vm.getClassFields(suri, object, key, pushResult)
307307 end
308308 goto CONTINUE
309309 end
310- if key == nil then
310+ if key == vm . ANY then
311311 pushResult (field , true )
312312 goto CONTINUE
313313 end
@@ -444,7 +444,7 @@ function vm.getClassFields(suri, object, key, pushResult)
444444
445445 local function searchGlobal (class )
446446 if class .cate == ' type' and class .name == ' _G' then
447- if key == nil then
447+ if key == vm . ANY then
448448 local sets = vm .getGlobalSets (suri , ' variable' )
449449 for _ , set in ipairs (sets ) do
450450 pushResult (set )
@@ -635,7 +635,7 @@ local function bindAs(source)
635635end
636636
637637--- @param source parser.object | vm.variable
638- --- @param key ? string | vm.global
638+ --- @param key string | vm.global | vm.ANY
639639--- @param pushResult fun ( source : parser.object )
640640function vm .compileByParentNode (source , key , pushResult )
641641 local parentNode = vm .compileNode (source )
@@ -1277,14 +1277,13 @@ local compilerSwitch = util.switch()
12771277 vm .setNode (source , vm .compileNode (src ))
12781278 end )
12791279 else
1280- local hasDefinedField
12811280 --- @cast key string
1282- vm .compileByParentNode (source .node , key , function (src )
1283- hasDefinedField = true
1284- vm .setNode (source , vm .compileNode (src ))
1285- end )
1286- if not hasDefinedField and source .value then
1281+ if source .value then
12871282 vm .setNode (source , vm .compileNode (source .value ))
1283+ else
1284+ vm .compileByParentNode (source .node , key , function (src )
1285+ vm .setNode (source , vm .compileNode (src ))
1286+ end )
12881287 end
12891288 end
12901289 end
@@ -1308,6 +1307,9 @@ local compilerSwitch = util.switch()
13081307 return
13091308 end
13101309 local key = guide .getKeyName (source )
1310+ if not key then
1311+ return
1312+ end
13111313 vm .compileByParentNode (source .node , key , function (src )
13121314 vm .setNode (source , vm .compileNode (src ))
13131315 end )
@@ -1321,14 +1323,17 @@ local compilerSwitch = util.switch()
13211323 end
13221324
13231325 if not hasMarkDoc then
1324- vm .compileByParentNode (source .node , guide .getKeyName (source ), function (src )
1325- if src .type == ' doc.field'
1326- or src .type == ' doc.type.field'
1327- or src .type == ' doc.type.name' then
1328- hasMarkDoc = true
1329- vm .setNode (source , vm .compileNode (src ))
1330- end
1331- end )
1326+ local key = guide .getKeyName (source )
1327+ if key then
1328+ vm .compileByParentNode (source .node , key , function (src )
1329+ if src .type == ' doc.field'
1330+ or src .type == ' doc.type.field'
1331+ or src .type == ' doc.type.name' then
1332+ hasMarkDoc = true
1333+ vm .setNode (source , vm .compileNode (src ))
1334+ end
1335+ end )
1336+ end
13321337 end
13331338
13341339 if not hasMarkDoc and source .value then
0 commit comments