From 7f8d5869c33668f74d405eca1c08378be1ffbf44 Mon Sep 17 00:00:00 2001 From: Drew Powers <1369770+drwpow@users.noreply.github.com> Date: Wed, 16 Jun 2021 13:26:38 -0600 Subject: [PATCH] Fix parser error on forward slash (#469) Fixes #407 --- .changeset/rude-cameras-rhyme.md | 5 +++++ packages/astro-parser/src/parse/read/expression.ts | 3 ++- packages/astro/test/astro-basic.test.js | 10 ++++++++++ .../astro-basic/src/pages/forward-slash.astro | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/rude-cameras-rhyme.md create mode 100644 packages/astro/test/fixtures/astro-basic/src/pages/forward-slash.astro diff --git a/.changeset/rude-cameras-rhyme.md b/.changeset/rude-cameras-rhyme.md new file mode 100644 index 000000000..bd18704ac --- /dev/null +++ b/.changeset/rude-cameras-rhyme.md @@ -0,0 +1,5 @@ +--- +'@astrojs/parser': patch +--- + +Bugfix: template literals in JSX tags breaking parser diff --git a/packages/astro-parser/src/parse/read/expression.ts b/packages/astro-parser/src/parse/read/expression.ts index 9d0d09175..c1fd6031b 100644 --- a/packages/astro-parser/src/parse/read/expression.ts +++ b/packages/astro-parser/src/parse/read/expression.ts @@ -84,7 +84,8 @@ function consume_tag(state: ParseState) { switch (char) { case "'": - case '"': { + case '"': + case '`': { consume_string(state, char); break; } diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index cdec77219..4f8fc3a32 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -64,4 +64,14 @@ Basics('Build does not include HMR client', async ({ build, readFile }) => { assert.equal(hmrPortScript.length, 0, 'No script setting the websocket port'); }); +Basics('Allows forward-slashes in mustache tags (#407)', async ({ runtime }) => { + const result = await runtime.load('/forward-slash'); + const html = result.contents; + const $ = doc(html); + + assert.equal($('a[href="/post/one"]').length, 1); + assert.equal($('a[href="/post/two"]').length, 1); + assert.equal($('a[href="/post/three"]').length, 1); +}); + Basics.run(); diff --git a/packages/astro/test/fixtures/astro-basic/src/pages/forward-slash.astro b/packages/astro/test/fixtures/astro-basic/src/pages/forward-slash.astro new file mode 100644 index 000000000..f4df3d024 --- /dev/null +++ b/packages/astro/test/fixtures/astro-basic/src/pages/forward-slash.astro @@ -0,0 +1,13 @@ +--- +const slugs = ['one', 'two', 'three']; +--- + + + + + + {slugs.map((slug) => ( + {slug} + ))} + +