Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve top-level return error #6036

Merged
merged 1 commit into from
Jan 30, 2023
Merged

Improve top-level return error #6036

merged 1 commit into from
Jan 30, 2023

Conversation

natemoo-re
Copy link
Member

Changes

  • Closes "Top-level return cannot be used inside an ECMAScript module" #5922
  • Fixes some problems with our error handling in dev. We "enhance" compiler errors by doing a second esbuild pass for possible frontmatter errors, but there were two problems here:
    1. We weren't checking if the error actually came from the frontmatter first.
    2. esbuild doesn't support top-level return (for obvious reasons) so any code using return Astro.redirect() would always fail with this message. As a fix, we now replace all instances of return with throw before scanning with esbuild.

Testing

Tested manually as the exact error messages here are subject to change

Docs

QoL improvement only

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2023

🦋 Changeset detected

Latest commit: 91769a7

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

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: astro Related to the core `astro` package (scope) label Jan 30, 2023
@natemoo-re natemoo-re merged commit e779c62 into main Jan 30, 2023
@natemoo-re natemoo-re deleted the fix/top-level-return branch January 30, 2023 17:37
@astrobot-houston astrobot-houston mentioned this pull request Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Top-level return cannot be used inside an ECMAScript module"
2 participants