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

Named export from destructuring doesn't work #563

Closed
brapifra opened this issue Nov 29, 2020 · 1 comment · Fixed by #564
Closed

Named export from destructuring doesn't work #563

brapifra opened this issue Nov 29, 2020 · 1 comment · Fixed by #564
Assignees

Comments

@brapifra
Copy link

It looks like named exports that come from destructuring an object don't get compiled:

const { someFieldIWantToExport } = someObject;

export { someFieldIWantToExport }; // This does not get exported as it should

Example

https://sucrase.io/#compressedCode=H4sIAHh6w18AA8vMLcgvKlEISk1MLtFRqFZwzgcK5KXmlSjUKqQV5ecqKBWBpJSsubiS8%2FOKS4BKSotTg0sSS1KBKmwhGq0V9PUVQjIyixVS8lOL89RLFMrzi7K5uGCiIF4xiAcxAm4AVLseTABoSWoF2D3ItsDEUlLTEktzShQcCwqACgGDCiqfuQAAAA%3D%3D

@alangpierce
Copy link
Owner

Thanks for reporting! It looks like the someFieldIWantToExport declaration is being misidentified by the parser as ObjectShorthandBlockScopedDeclaration when it should be ObjectShorthandTopLevelDeclaration, so it ends up being elided like a type.

@alangpierce alangpierce self-assigned this Dec 1, 2020
alangpierce added a commit that referenced this issue Dec 1, 2020
Fixes #563
Fixes #473

The type-only export elision implemented in #433 had a false positive for
destructure delcarations, since `getDeclarationInfo` only looks at top-level
declarations and top-level expressions like `const {x} = ...` weren't being
marked correctly. To fix, we can mark object shorthand declarations as top-level
when applicable. I also refactored both relevant code paths to avoid the
repeated assignment left-hand side.
alangpierce added a commit that referenced this issue Dec 2, 2020
Fixes #563
Fixes #473

The type-only export elision implemented in #433 had a false positive for
destructure delcarations, since `getDeclarationInfo` only looks at top-level
declarations and top-level expressions like `const {x} = ...` weren't being
marked correctly. To fix, we can mark object shorthand declarations as top-level
when applicable. I also refactored both relevant code paths to avoid the
repeated assignment left-hand side.
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 a pull request may close this issue.

2 participants