diff --git a/.changeset/perfect-terms-rush.md b/.changeset/perfect-terms-rush.md new file mode 100644 index 000000000..c2750dd4a --- /dev/null +++ b/.changeset/perfect-terms-rush.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Fixed issue where expressions did not work within SVG elements diff --git a/internal/parser.go b/internal/parser.go index b2850915c..4f96f5f80 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -2533,7 +2533,6 @@ func ignoreTheRemainingTokens(p *parser) bool { const whitespaceOrNUL = whitespace + "\x00" -// TODO: handle expressions in SVG // Section 12.2.6.5 func parseForeignContent(p *parser) bool { switch p.tok.Type { @@ -2612,6 +2611,14 @@ func parseForeignContent(p *parser) bool { } } return true + case StartExpressionToken: + p.reconstructActiveFormattingElements() + p.addExpression() + return true + case EndExpressionToken: + p.addLoc() + p.oe.pop() + return true default: // Ignore the token. } diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 31b7e244c..c34053153 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -850,6 +850,28 @@ import ZComponent from '../components/ZComponent.jsx';`}, code: `
`, }, }, + { + name: "svg expressions", + source: `--- +const title = 'icon'; +--- +`, + want: want{ + frontmatter: []string{"", "const title = 'icon';"}, + code: ``, + }, + }, + { + name: "advanced svg expression", + source: `--- +const title = 'icon'; +--- +`, + want: want{ + frontmatter: []string{"", "const title = 'icon';"}, + code: ``, + }, + }, { name: "Empty script", source: ``,