@@ -202,7 +202,7 @@ function mt:lookIntoChild(action, topNode, outNode)
202202 end
203203 end
204204 elseif action .type == ' function' then
205- self :lookIntoBlock (action , 0 , topNode :copy ())
205+ self :lookIntoBlock (action , action . args . finish , topNode :copy ())
206206 elseif action .type == ' unary' then
207207 if not action [1 ] then
208208 goto RETURN
@@ -312,12 +312,24 @@ function mt:lookIntoChild(action, topNode, outNode)
312312 or action .type == ' repeat'
313313 or action .type == ' for'
314314 or action .type == ' do' then
315- self :lookIntoBlock (action , 0 , topNode :copy ())
316- local lastAssign = self :getLastAssign (action .start , action .finish )
317- if lastAssign then
318- local node = self :getNode (lastAssign )
319- if node then
320- topNode = node :copy ()
315+ if action [1 ] then
316+ local actionStart
317+ if action .type == ' loop' then
318+ actionStart = action .keyword [4 ]
319+ elseif action .type == ' in' then
320+ actionStart = action .keyword [6 ]
321+ elseif action .type == ' repeat'
322+ or action .type == ' for'
323+ or action .type == ' do' then
324+ actionStart = action .keyword [2 ]
325+ end
326+ self :lookIntoBlock (action , actionStart , topNode :copy ())
327+ local lastAssign = self :getLastAssign (action .start , action .finish )
328+ if lastAssign then
329+ local node = self :getNode (lastAssign )
330+ if node then
331+ topNode = node :copy ()
332+ end
321333 end
322334 end
323335 elseif action .type == ' while' then
@@ -328,12 +340,14 @@ function mt:lookIntoChild(action, topNode, outNode)
328340 blockNode = topNode :copy ()
329341 mainNode = topNode :copy ()
330342 end
331- self :lookIntoBlock (action , 0 , blockNode :copy ())
332- local lastAssign = self :getLastAssign (action .start , action .finish )
333- if lastAssign then
334- local node = self :getNode (lastAssign )
335- if node then
336- topNode = mainNode :merge (node )
343+ if action [1 ] then
344+ self :lookIntoBlock (action , action .keyword [4 ], blockNode :copy ())
345+ local lastAssign = self :getLastAssign (action .start , action .finish )
346+ if lastAssign then
347+ local node = self :getNode (lastAssign )
348+ if node then
349+ topNode = mainNode :merge (node )
350+ end
337351 end
338352 end
339353 if action .filter then
@@ -355,25 +369,36 @@ function mt:lookIntoChild(action, topNode, outNode)
355369 hasElse = true
356370 mainNode :clear ()
357371 end
358- self :lookIntoBlock (subBlock , 0 , blockNode :copy ())
359- local neverReturn = subBlock .hasReturn
360- or subBlock .hasGoTo
361- or subBlock .hasBreak
362- or subBlock .hasError
363- if not neverReturn then
364- local ok
365- local lastAssign = self :getLastAssign (subBlock .start , subBlock .finish )
366- if lastAssign then
367- local node = self :getNode (lastAssign )
368- if node then
369- blockNodes [# blockNodes + 1 ] = node
370- ok = true
371- end
372+ local mergedNode
373+ if subBlock [1 ] then
374+ local actionStart
375+ if subBlock .type == ' ifblock'
376+ or subBlock .type == ' elseif' then
377+ actionStart = subBlock .keyword [4 ]
378+ else
379+ actionStart = subBlock .keyword [2 ]
372380 end
373- if not ok then
374- blockNodes [# blockNodes + 1 ] = blockNode
381+ self :lookIntoBlock (subBlock , actionStart , blockNode :copy ())
382+ local neverReturn = subBlock .hasReturn
383+ or subBlock .hasGoTo
384+ or subBlock .hasBreak
385+ or subBlock .hasError
386+ if neverReturn then
387+ mergedNode = true
388+ else
389+ local lastAssign = self :getLastAssign (subBlock .start , subBlock .finish )
390+ if lastAssign then
391+ local node = self :getNode (lastAssign )
392+ if node then
393+ blockNodes [# blockNodes + 1 ] = node
394+ mergedNode = true
395+ end
396+ end
375397 end
376398 end
399+ if not mergedNode then
400+ blockNodes [# blockNodes + 1 ] = blockNode
401+ end
377402 end
378403 if not hasElse and not topNode :hasKnownType () then
379404 mainNode :merge (vm .declareGlobal (' type' , ' unknown' ))
0 commit comments