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

Changes

Fix this issue: 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

⚠️ No Changeset found

Latest commit: a6081c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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 ?

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.

3 participants