Skip to content

Commit

Permalink
Handle string templates within expressions (#91)
Browse files Browse the repository at this point in the history
* Handle string templates within expressions

* Adds a changeset
  • Loading branch information
matthewp authored Oct 22, 2021
1 parent 23298d2 commit f262b61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-houses-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix for string template usage within expressions
3 changes: 3 additions & 0 deletions internal/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,9 @@ func (z *Tokenizer) Next() TokenType {
if z.fm != FrontmatterClosed {
goto frontmatter_loop
}
if len(z.expressionStack) > 0 {
goto expression_loop
}

loop:
for {
Expand Down
5 changes: 5 additions & 0 deletions internal/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ func TestExpressions(t *testing.T) {
"<title>{content.title && `${title} 🚀 ${title}`}</title>",
[]TokenType{StartTagToken, StartExpressionToken, TextToken, EndExpressionToken, EndTagToken},
},
{
"Nested use of string templates inside expressions",
"<div>{`${a} inner${a > 1 ? 's' : ''}.`}</div>",
[]TokenType{StartTagToken, StartExpressionToken, TextToken, EndExpressionToken, EndTagToken},
},
}

runTokenTypeTest(t, Expressions)
Expand Down

0 comments on commit f262b61

Please sign in to comment.