From 35afa86939bf3f2fd9fdd7f3a07a5f9d571bafa9 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 6 Sep 2022 16:44:34 -0400 Subject: [PATCH 1/2] Fix assertion parsing to always happen after the specifier --- internal/js_scanner/js_scanner.go | 2 +- internal/printer/printer_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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}

`, From 56ee7d535ae4f9815bbe27e6294bb0797ffa9443 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 6 Sep 2022 16:46:16 -0400 Subject: [PATCH 2/2] Changeset --- .changeset/gorgeous-cooks-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-cooks-jog.md 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