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

Exports before declaration don't work #671

Open
duailibe opened this issue Dec 19, 2021 · 1 comment
Open

Exports before declaration don't work #671

duailibe opened this issue Dec 19, 2021 · 1 comment

Comments

@duailibe
Copy link

duailibe commented Dec 19, 2021

Hi there!

I've recently started to migrate a relatively big project from Babel to Sucrase and hit a (not so much) blocker. We have a few files that reference export { foo } before the const foo declaration, which should be valid per spec and works with Babel and TypeScript.

Given the source

export { foo };
const foo = 1;

Sucrase will compile to:

exports.foo = foo;
const foo = 1;

And both Babel and TypeScript will compile to:

exports.foo = void 0;
const foo = 1;
exports.foo = foo;

(Sucrase link here)

This is kind of minor and I could just run a codemod on our codebase, but I figured this might be something worth fixing.

@duailibe
Copy link
Author

duailibe commented Dec 20, 2021

What I did to fix in my project was moving all statements (export.foo = foo;) to the end of the compilation (in getSuffixCode).

If you think this is an acceptable fix, I'm happy to send a PR.

@duailibe duailibe changed the title Exports before declaration doesn't work Exports before declaration don't work Dec 23, 2021
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

No branches or pull requests

1 participant