Skip to content

fix: export w/ curly brace on next line, extra curly brace before def #1075

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-snezhko
Copy link

@alex-snezhko alex-snezhko commented May 19, 2025

Changes

Closes withastro/astro#13790, where a curly brace which is not the start of a function body is incorrectly classified as such.

This is just a patch for the case reported in this issue and a few other ones, such as:

  • A curly brace appearing on the parameter type i.e. export function getStaticPaths(input: { paginate: any })
  • A curly brace in the type definition of an arrow function i.e. export const getStaticPaths: () => { params: any }[]

There may be an additional case that I missed, please let me know if you can think of one!

Note

Though I did not do this in this PR to minimize the surface area of the changes, in my opinion it would be worthwhile to pull in a full-fledged TS parser and operate on the AST for this export hoisting use case. Perhaps when the new TS Go compiler from Microsoft is stable the parser can be taken from there 🤷

Testing

Tests added to appropriate files

Docs

Bug fix, no changes to public API

Copy link

changeset-bot bot commented May 19, 2025

🦋 Changeset detected

Latest commit: 49b8546

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

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler 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

Copy link
Member

@MoustaphaDev MoustaphaDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my opinion it would be worthwhile to pull in a full-fledged TS parser and operate on the AST for this export hoisting use case

Yeah we're actually experimenting on using ts-go 🙂
https://github.com/withastro/compiler/tree/experiment/ts-go

Thanks for contributing!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a changeset @alex-snezhko ?

@alex-snezhko alex-snezhko force-pushed the export-with-curly-brace-on-next-line branch from a6081c7 to 49b8546 Compare May 27, 2025 19:54
@alex-snezhko
Copy link
Author

Ok just added @ematipico!

@MoustaphaDev MoustaphaDev requested a review from ematipico May 27, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paginate only works with specific wrapping
3 participants