-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@@ -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() { |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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.