diff --git a/.changeset/gorgeous-cooks-jog.md b/.changeset/gorgeous-cooks-jog.md new file mode 100644 index 000000000..6811555b0 --- /dev/null +++ b/.changeset/gorgeous-cooks-jog.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Prevent import assertion from being scanned too soon diff --git a/internal/js_scanner/js_scanner.go b/internal/js_scanner/js_scanner.go index f6d199936..77f49acae 100644 --- a/internal/js_scanner/js_scanner.go +++ b/internal/js_scanner/js_scanner.go @@ -365,7 +365,7 @@ func NextImportStatement(source []byte, pos int) (int, ImportStatement) { continue } - if !foundAssertion && next == js.IdentifierToken && string(nextValue) == "assert" { + if !foundAssertion && foundSpecifier && next == js.IdentifierToken && string(nextValue) == "assert" { foundAssertion = true continue } diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 7f02afdde..5af2470e7 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -314,6 +314,19 @@ import data from "test" assert { type: 'json' }; metadata: metadata{modules: []string{`{ module: $$module1, specifier: 'test', assert: {type:'json'} }`}}, }, }, + { + name: "import to identifier named assert", + + source: `--- +import assert from 'test'; +---`, + want: want{ + frontmatter: []string{ + `import assert from 'test';`, + }, + metadata: metadata{modules: []string{`{ module: $$module1, specifier: 'test', assert: {} }`}}, + }, + }, { name: "no expressions in math", source: `

Hello, world! This is a buggy formula: f ⁣:XR2xf\colon X \to \mathbb R^{2x}

`,