Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-toys-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix #340, fixing behavior of content after an expression inside of <select>
4 changes: 3 additions & 1 deletion internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,8 @@ func inSelectIM(p *parser) bool {
p.tokenizer.NextIsNotRawText()
// Ignore the token.
return true
default:
return inBodyIM(p)
}
case EndTagToken:
switch p.tok.DataAtom {
Expand Down Expand Up @@ -2195,7 +2197,7 @@ func inSelectIM(p *parser) bool {
case EndExpressionToken:
p.addLoc()
p.oe.pop()
return true
return inBodyIM(p)
case DoctypeToken:
// Ignore the token.
return true
Expand Down
7 changes: 7 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,13 @@ const value = 'test';
code: `<select>${value && $$render` + BACKTICK + `<option>${value}</option>` + BACKTICK + `}</select>`,
},
},
{
name: "select map expression",
source: `<select>{[1, 2, 3].map(num => <option>{num}</option>)}</select><div>Hello world!</div>`,
want: want{
code: `<select>${[1, 2, 3].map(num => $$render` + BACKTICK + `<option>${num}</option>` + BACKTICK + `)}</select><div>Hello world!</div>`,
},
},
{
name: "textarea",
source: `---
Expand Down
5 changes: 5 additions & 0 deletions internal/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ func TestBasic(t *testing.T) {
`<Fragment>foo</Fragment>`,
[]TokenType{StartTagToken, TextToken, EndTagToken},
},
{
"select with expression",
`<select>{[1, 2, 3].map(num => <option>{num}</option>)}</select>`,
[]TokenType{StartTagToken, StartExpressionToken, TextToken, StartTagToken, StartExpressionToken, TextToken, EndExpressionToken, EndTagToken, TextToken, EndExpressionToken, EndTagToken},
},
{
"Markdown codeblock",
fmt.Sprintf(`<Markdown>
Expand Down