Skip to content

Commit b580171

Browse files
authored
feat: add Range to CallTemplateExpression nodes (#1275)
1 parent c2f3317 commit b580171

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

parser/v2/calltemplateparser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var callTemplateExpressionStart = parse.Or(parse.String("{! "), parse.String("{!
1212
type callTemplateExpressionParser struct{}
1313

1414
func (p callTemplateExpressionParser) Parse(pi *parse.Input) (n Node, ok bool, err error) {
15+
start := pi.Position()
16+
1517
// Check the prefix first.
1618
if _, ok, err = callTemplateExpressionStart.Parse(pi); err != nil || !ok {
1719
return
@@ -29,5 +31,7 @@ func (p callTemplateExpressionParser) Parse(pi *parse.Input) (n Node, ok bool, e
2931
return
3032
}
3133

34+
r.Range = NewRange(start, pi.Position())
35+
3236
return r, true, nil
3337
}

parser/v2/calltemplateparser_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func TestCallTemplateExpressionParser(t *testing.T) {
3232
},
3333
},
3434
},
35+
Range: Range{
36+
From: Position{Index: 0, Line: 0, Col: 0},
37+
To: Position{Index: 18, Line: 0, Col: 18},
38+
},
3539
},
3640
},
3741
{
@@ -53,6 +57,10 @@ func TestCallTemplateExpressionParser(t *testing.T) {
5357
},
5458
},
5559
},
60+
Range: Range{
61+
From: Position{Index: 0, Line: 0, Col: 0},
62+
To: Position{Index: 17, Line: 0, Col: 17},
63+
},
5664
},
5765
},
5866
{
@@ -74,6 +82,10 @@ func TestCallTemplateExpressionParser(t *testing.T) {
7482
},
7583
},
7684
},
85+
Range: Range{
86+
From: Position{Index: 0, Line: 0, Col: 0},
87+
To: Position{Index: 16, Line: 0, Col: 16},
88+
},
7789
},
7890
},
7991
}

parser/v2/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ func (c *HTMLComment) Visit(v Visitor) error {
11591159
type CallTemplateExpression struct {
11601160
// Expression returns a template to execute.
11611161
Expression Expression
1162+
Range Range
11621163
}
11631164

11641165
func (cte *CallTemplateExpression) IsNode() bool { return true }

0 commit comments

Comments
 (0)