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

Sort module export names #13788

Merged
merged 4 commits into from Sep 26, 2021
Merged

Sort module export names #13788

merged 4 commits into from Sep 26, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Sep 23, 2021

Q                       A
Fixed Issues? Fixes #13785
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we sort the export initialization statements by the export names. The initStatements and exportsNames are merged to an array of tuple<string, Statement> so we can sort the init statements by their names.

We didn't add new tests as current tests are sufficient to show that the initializations are ordered by names.

Note that under the noIncompleteNsImportDetection assumption, the issue can not be fixed without adding new initialization statements, which are exactly removed by definition of the assumption. We can add an extra note about the effects of this assumption.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories area: modules labels Sep 23, 2021
} else {
// We generate init statements (`exports.a = exports.b = ... = void 0`)
// for every 100 exported names.
const chunkSize = 100;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The chunk behaviour has existed since 95e08b6#diff-f9b022d801ca0bab9bbb7057b9ac49aac0d8c2ab53f41f97e7e15bdd10f26069R272. I don't know if it is a workaround of browser quirks or it is for aesthetic reasons.

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 it's to avoid a too deeply nested AST

Copy link
Member

Choose a reason for hiding this comment

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

Ref - #14272

@babel-bot
Copy link
Collaborator

babel-bot commented Sep 23, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/48889/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 23, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3f6b64f:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

Copy link
Contributor Author

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

We still need to update the buildNamespaceInitStatements implementation.

@JLHwung JLHwung marked this pull request as draft September 23, 2021 21:22
@JLHwung JLHwung marked this pull request as ready for review September 24, 2021 18:22
@JLHwung
Copy link
Contributor Author

JLHwung commented Sep 24, 2021

Turns out we don't need to update buildNamespaceInitStatements because all statically know exports have been initialized in buildExportInitializationStatements.

@JLHwung JLHwung merged commit 14572e1 into babel:main Sep 26, 2021
@JLHwung JLHwung deleted the sort-module-export-names branch September 26, 2021 14:12
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: modules outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: the order of exports is incorrect when converting ESM to CJS
4 participants