Skip to content

Commit 6bc8e0b

Browse files
authored
Fix assertion parsing to always happen after the specifier (#510)
* Fix assertion parsing to always happen after the specifier * Changeset
1 parent e52ba81 commit 6bc8e0b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/gorgeous-cooks-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/compiler': patch
3+
---
4+
5+
Prevent import assertion from being scanned too soon

internal/js_scanner/js_scanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func NextImportStatement(source []byte, pos int) (int, ImportStatement) {
365365
continue
366366
}
367367

368-
if !foundAssertion && next == js.IdentifierToken && string(nextValue) == "assert" {
368+
if !foundAssertion && foundSpecifier && next == js.IdentifierToken && string(nextValue) == "assert" {
369369
foundAssertion = true
370370
continue
371371
}

internal/printer/printer_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ import data from "test" assert { type: 'json' };
314314
metadata: metadata{modules: []string{`{ module: $$module1, specifier: 'test', assert: {type:'json'} }`}},
315315
},
316316
},
317+
{
318+
name: "import to identifier named assert",
319+
320+
source: `---
321+
import assert from 'test';
322+
---`,
323+
want: want{
324+
frontmatter: []string{
325+
`import assert from 'test';`,
326+
},
327+
metadata: metadata{modules: []string{`{ module: $$module1, specifier: 'test', assert: {} }`}},
328+
},
329+
},
317330
{
318331
name: "no expressions in math",
319332
source: `<p>Hello, world! This is a <em>buggy</em> formula: <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mspace></mspace><mspace width="0.1111em"></mspace><mo lspace="0em" rspace="0.17em"></mo><mtext> ⁣</mtext><mo lspace="0em" rspace="0em">:</mo><mspace width="0.3333em"></mspace><mi>X</mi><mo>→</mo><msup><mi mathvariant="double-struck">R</mi><mrow><mn>2</mn><mi>x</mi></mrow></msup></mrow><annotation encoding="application/x-tex">f\colon X \to \mathbb R^{2x}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mspace nobreak"></span><span class="mspace" style="margin-right:0.1111em;"></span><span class="mpunct"></span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mrel">:</span></span><span class="mspace" style="margin-right:0.3333em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord mathbb">R</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span><span class="mord mathnormal mtight">x</span></span></span></span></span></span></span></span></span></span></span></span></span></p>`,

0 commit comments

Comments
 (0)