Skip to content

Commit

Permalink
fix: support package names in templ element expressions (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed May 11, 2023
1 parent 7efc71c commit 814273a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
9 changes: 6 additions & 3 deletions parser/v2/templelementparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ var templElementStartExpressionParams = parse.StringFrom(
)

var templElementStartExpression = ExpressionOf(parse.StringFrom(
parse.RuneInRanges(unicode.Letter),
parse.StringFrom(parse.AtMost(255, parse.RuneInRanges(unicode.Letter, unicode.Number))),
parse.StringFrom(parse.Optional(templElementStartExpressionParams)),
parse.AtLeast(1, parse.StringFrom(
parse.StringFrom(parse.Optional(parse.String("."))),
parse.RuneInRanges(unicode.Letter),
parse.StringFrom(parse.AtMost(255, parse.RuneInRanges(unicode.Letter, unicode.Number))),
parse.StringFrom(parse.Optional(templElementStartExpressionParams)),
)),
))

type templElementExpressionParser struct{}
Expand Down
42 changes: 42 additions & 0 deletions parser/v2/templelementparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,48 @@ func TestTemplElementExpressionParser(t *testing.T) {
},
},
},
{
name: "templelement: supports the use of templ elements in other packages",
input: `@templates.Icon("home", Inline)`,
expected: TemplElementExpression{
Expression: Expression{
Value: `templates.Icon("home", Inline)`,
Range: Range{
From: Position{
Index: 1,
Line: 0,
Col: 1,
},
To: Position{
Index: 31,
Line: 0,
Col: 31,
},
},
},
},
},
{
name: "templelement: supports the use of params which contain braces and params",
input: `@templates.New(test{}, other())`,
expected: TemplElementExpression{
Expression: Expression{
Value: `templates.New(test{}, other())`,
Range: Range{
From: Position{
Index: 1,
Line: 0,
Col: 1,
},
To: Position{
Index: 31,
Line: 0,
Col: 31,
},
},
},
},
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit 814273a

Please sign in to comment.