261
261
--- @param source parser.object
262
262
--- @param fieldName string
263
263
--- @param literal parser.object
264
- --- @return string[] ?
264
+ --- @return [ string, boolean] []?
265
265
local function getNodeTypesWithLiteralField (uri , source , fieldName , literal )
266
266
local loc = vm .getVariable (source )
267
267
if not loc then
@@ -279,7 +279,9 @@ local function getNodeTypesWithLiteralField(uri, source, fieldName, literal)
279
279
for _ , t in ipairs (f .extends .types ) do
280
280
if t [1 ] == literal [1 ] then
281
281
tys = tys or {}
282
- table.insert (tys , set .class [1 ])
282
+ -- If the type is in a union (e.g. 'lit' | foo), then the outNode
283
+ -- cannot be narrowed.
284
+ table.insert (tys , {set .class [1 ], # f .extends .types > 1 })
283
285
break
284
286
end
285
287
end
@@ -682,16 +684,16 @@ local lookIntoChild = util.switch()
682
684
683
685
-- TODO: handle more types
684
686
if tys and # tys == 1 then
685
- local ty = tys [1 ]
687
+ local ty , tyInUnion = tys [1 ][ 1 ], tys [ 1 ][ 2 ]
686
688
topNode = topNode :copy ()
687
689
if action .op .type == ' ==' then
688
690
topNode :narrow (tracer .uri , ty )
689
- if outNode then
691
+ if not tyInUnion and outNode then
690
692
outNode :remove (ty )
691
693
end
692
694
else
693
695
topNode :remove (ty )
694
- if outNode then
696
+ if not tyInUnion and outNode then
695
697
outNode :narrow (tracer .uri , ty )
696
698
end
697
699
end
0 commit comments