@@ -9,7 +9,7 @@ local guide = require 'parser.guide'
99--- @class vm.tracer
1010--- @field source parser.object
1111--- @field assigns parser.object[]
12- --- @field nodes table<parser.object , vm.node>
12+ --- @field nodes table<parser.object , vm.node | false >
1313--- @field main parser.object
1414--- @field uri uri
1515local mt = {}
3434--- @param mark table
3535function mt :collectBlock (obj , mark )
3636 while true do
37+ obj = obj .parent
3738 if mark [obj ] then
3839 return
3940 end
40- mark [obj ] = true
41- self .assigns [# self .assigns + 1 ] = obj
41+ if not guide .isBlockType (obj ) then
42+ return
43+ end
4244 if obj == self .main then
4345 return
4446 end
45- obj = obj .parent
47+ mark [obj ] = true
48+ if obj .type ~= ' do' then
49+ self .assigns [# self .assigns + 1 ] = obj
50+ end
4651 end
4752end
4853
7883--- @return parser.object ?
7984function mt :getLastAssign (source )
8085 local assign = self .source
86+ local block = guide .getParentBlock (source )
87+ if not block then
88+ return nil
89+ end
8190 for _ , obj in ipairs (self .assigns ) do
82- if obj .start > source .start then
91+ if obj .start >= source .start then
8392 break
8493 end
85- assign = obj
94+ local objBlock = guide .getParentBlock (obj )
95+ if not objBlock then
96+ break
97+ end
98+ if objBlock == block
99+ or objBlock .type == ' do'
100+ or objBlock .finish > block .finish then
101+ assign = obj
102+ end
86103 end
87104 return assign
88105end
89106
90107--- @param source parser.object
91108--- @return vm.node ?
92109function mt :getNode (source )
93- if self .nodes [source ] then
94- return self .nodes [source ]
110+ if self .nodes [source ] ~= nil then
111+ return self .nodes [source ] or nil
95112 end
96113 local lastAssign = self :getLastAssign (source )
97114 if not lastAssign then
115+ self .nodes [source ] = false
98116 return nil
99117 end
100118 if guide .isSet (lastAssign ) then
101119 local lastNode = vm .compileNode (lastAssign )
120+ self .nodes [source ] = lastNode
102121 return lastNode
103122 end
123+ local lastNode = self :getNode (lastAssign )
124+ self .nodes [source ] = lastNode
125+ return lastNode
104126end
105127
106128--- @param source parser.object
0 commit comments