Skip to content

fix(cloudflare): skip regex literals when rewriting top-level returns in frontmatter - #17698

Open
lazerg wants to merge 1 commit into
withastro:mainfrom
lazerg:fix/issue-17697-frontmatter-regex-literal
Open

fix(cloudflare): skip regex literals when rewriting top-level returns in frontmatter#17698
lazerg wants to merge 1 commit into
withastro:mainfrom
lazerg:fix/issue-17697-frontmatter-regex-literal

Conversation

@lazerg

@lazerg lazerg commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Changes

  • The dep-scan plugins for .astro files rewrite top-level return to throw so esbuild/Rolldown accept the frontmatter as an ES module. They found those return keywords with a single regex whose skip group covered strings, template literals and comments, but not regex literals. A quote inside a regex literal, as in value.replace(/"/g, """), was then read as an opening string delimiter, so quote pairing stayed off by one for the rest of the frontmatter and every later top-level return was left alone. Vite reported Failed to run dependency scan plus one Top-level return cannot be used inside an ECMAScript module per surviving return, and only on a cold node_modules/.vite, which made it look intermittent.
  • replaceTopLevelReturns now scans the frontmatter character by character instead. It skips strings, template literals, line and block comments, and regex literals, and only rewrites a return found in code. A / is treated as the start of a regex literal only when the preceding token allows an expression there, so division is left alone.
  • Moved the helper to src/utils/frontmatter.ts, since the esbuild and Rolldown plugins each carried their own copy of the same tokenizer and the same bug.

Closes #17697

Testing

Added test/frontmatter-returns.test.ts covering the reported case along with division, character classes, member access, strings and comments. The regex-literal case fails on main and passes here. The existing top-level-return integration test still passes.

Docs

No docs needed, this only fixes the dependency scan for frontmatter that was already valid.

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eec3bd6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 44 packages
Name Type
@astrojs/cloudflare Patch
@test/astro-cloudflare-node-prerender-mdx Patch
@test/astro-cloudflare Patch
@test/astro-cloudflare-allowed-hosts Patch
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-binding-image-cache Patch
@test/astro-cloudflare-binding-image-service Patch
@test/astro-cloudflare-cache-provider-wait-until Patch
@test/astro-cloudflare-cache-provider Patch
@test/astro-cloudflare-client-address Patch
@test/astro-cloudflare-compile-custom-image-service Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-custom-entryfile-fetch-state Patch
@test/astro-cloudflare-custom-entryfile Patch
@test/astro-cloudflare-custom-image-service Patch
@test/astro-cloudflare-dev-image-endpoint Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-external-redirects Patch
@test/cloudflare-incremental-images Patch
@test/astro-cloudflare-internal-redirects Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-prerender-node-env Patch
@test/astro-cloudflare-prerender-queue-consumers Patch
@test/astro-cloudflare-prerender-styles Patch
@test/astro-cloudflare-prerenderer-errors Patch
@test/astro-cloudflare-prerenderer-render-error Patch
@test/routing-priority-cloudflare Patch
@test/cf-server-entry Patch
@test/astro-cloudflare-server-island-prerender-framework Patch
@test/astro-cloudflare-sessions Patch
@test/astro-cloudflare-sql-import Patch
@test/cf-ssr-deps Patch
@test/astro-cloudflare-static Patch
@test/astro-cloudflare-svelte-rune-deps Patch
@test/astro-cloudflare-top-level-return Patch
@test/cf-user-optimize-deps Patch
@test/astro-cloudflare-vite-plugin Patch
@test/astro-cloudflare-with-base Patch
@test/astro-cloudflare-with-react Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-with-svelte Patch
@test/astro-cloudflare-with-vue Patch
@test/astro-cloudflare-wrangler-preview-platform Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] @astrojs/cloudflare: frontmatter dep-scan tokenizer does not skip regex literals, breaking top-level return rewriting

1 participant