From 34da907f3b4fb411024e6d28fdb291fa78116950 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 13 Aug 2024 11:20:12 +0100 Subject: [PATCH] fix: make semicolon optional when detecting `prerender` option (#11678) * fix: make semicolon optional when detecting `prerender` option * trim to remove possible carriage return * Apply suggestions from code review Co-authored-by: Bjorn Lu --------- Co-authored-by: Bjorn Lu --- .changeset/good-birds-clap.md | 5 +++++ packages/astro/src/vite-plugin-scanner/scan.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/good-birds-clap.md diff --git a/.changeset/good-birds-clap.md b/.changeset/good-birds-clap.md new file mode 100644 index 0000000000..1a05c065c6 --- /dev/null +++ b/.changeset/good-birds-clap.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a case where omitting a semicolon and line ending with carriage return - CRLF - in the `prerender` option could throw an error. diff --git a/packages/astro/src/vite-plugin-scanner/scan.ts b/packages/astro/src/vite-plugin-scanner/scan.ts index f447a1f28f..b9f61e3b83 100644 --- a/packages/astro/src/vite-plugin-scanner/scan.ts +++ b/packages/astro/src/vite-plugin-scanner/scan.ts @@ -65,7 +65,7 @@ export async function scan( .trim(); // For a given export, check the value of the first non-whitespace token. // Basically extract the `true` from the statement `export const prerender = true` - const suffix = code.slice(endOfLocalName).trim().replace(/=/, '').trim().split(/[;\n]/)[0]; + const suffix = code.slice(endOfLocalName).trim().replace(/=/, '').trim().split(/[;\n\r]/)[0].trim(); if (prefix !== 'const' || !(isTruthy(suffix) || isFalsy(suffix))) { throw new AstroError({ ...AstroErrorData.InvalidPrerenderExport,