Skip to content

Commit

Permalink
fix: make semicolon optional when detecting prerender option (#11678)
Browse files Browse the repository at this point in the history
* fix: make semicolon optional when detecting `prerender` option

* trim to remove possible carriage return

* Apply suggestions from code review

Co-authored-by: Bjorn Lu <[email protected]>

---------

Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
ematipico and bluwy authored Aug 13, 2024
1 parent 64f81e9 commit 34da907
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/good-birds-clap.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-scanner/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 34da907

Please sign in to comment.