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

fix(es/transforms/module/commonjs): fix named exports overrides #2883

Merged
merged 16 commits into from
Nov 28, 2021

Conversation

JeremyGrieshop
Copy link
Contributor

This PR closes #2101 and the details can be found in the issue description.

This is somewhat of a followup to PR #2583, as the PR was a incomplete solution. It only fixed named exports declared as import/export statements. Furthermore, the order of the named exports could appear before or after the wildcard exports, causing cases to be missed.

This fix requires a preliminary pass through the items to find all named exports first in order to address the ordering. Furthermore, I've moved the logic from PR #2583 into this preliminary loop instead to catch both cases where export/imports are declared as well as simple named exports.

I've used Babel REPL to compare my output to multiple use cases, which also required changing a couple of internal test outputs.

This re-ordering can cause the _exportNames array to be declared sooner than previously found. I've found that Babel seems to always declare it right away.

It should also be noted that the testing has changed much since my first PR, and I've tried to follow the same patterns and locations to place and run tests.

@kdy1 kdy1 added this to the v1.2.113 milestone Nov 27, 2021
@@ -89,6 +89,31 @@ where
// Used only if export * exists
let mut exported_names: Option<Ident> = None;

// make a preliminary pass through to collect exported names ahead of time
for item in items.clone() {
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need clone().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fairly new to Rust. Is there a better way to iterate a vector twice? Removing clone would cause the second iteration to fail.

Copy link
Member

Choose a reason for hiding this comment

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

You can use for item in &items instead, as &Vec<T> implements IntoIterator<Item = &T>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thank you! One of these days, I will learn Rust properly.

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

I found one perf issue, thanks!

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thanks!

@kdy1 kdy1 modified the milestones: v1.2.113, v1.2.114 Nov 27, 2021
@kdy1 kdy1 enabled auto-merge (squash) November 28, 2021 08:15
@kdy1 kdy1 merged commit 6f05c10 into swc-project:main Nov 28, 2021
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Runtime issue with named export overrides
2 participants