Skip to content

Commit bebee7d

Browse files
authored
feat: add Ranges to SwitchExpressions (#1265)
1 parent 5094fb5 commit bebee7d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

parser/v2/switchexpressionparser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (switchExpressionParser) Parse(pi *parse.Input) (n Node, matched bool, err
5858
return r, true, err
5959
}
6060

61+
r.Range = NewRange(pi.PositionAt(start), pi.Position())
6162
return r, true, nil
6263
}
6364

parser/v2/switchexpressionparser_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func TestSwitchExpressionParser(t *testing.T) {
3333
},
3434
},
3535
},
36+
Range: Range{
37+
From: Position{Index: 0, Line: 0, Col: 0},
38+
To: Position{Index: 20, Line: 1, Col: 1},
39+
},
3640
},
3741
},
3842
{
@@ -115,6 +119,10 @@ default:
115119
},
116120
},
117121
},
122+
Range: Range{
123+
From: Position{Index: 0, Line: 0, Col: 0},
124+
To: Position{Index: 68, Line: 5, Col: 1},
125+
},
118126
},
119127
},
120128
{
@@ -196,6 +204,10 @@ default:
196204
},
197205
},
198206
},
207+
Range: Range{
208+
From: Position{Index: 0, Line: 0, Col: 0},
209+
To: Position{Index: 73, Line: 5, Col: 1},
210+
},
199211
},
200212
},
201213
{
@@ -304,6 +316,10 @@ default:
304316
},
305317
},
306318
},
319+
Range: Range{
320+
From: Position{Index: 0, Line: 0, Col: 0},
321+
To: Position{Index: 62, Line: 5, Col: 1},
322+
},
307323
},
308324
},
309325
}

parser/v2/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ func (n *IfExpression) Visit(v Visitor) error {
13221322
type SwitchExpression struct {
13231323
Expression Expression
13241324
Cases []CaseExpression
1325+
Range Range
13251326
}
13261327

13271328
func (se SwitchExpression) ChildNodes() []Node {

0 commit comments

Comments
 (0)