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/cjs): Preserve order of imports for reexports #2598

Merged
merged 5 commits into from
Nov 2, 2021

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Oct 31, 2021

This PR attempts to order of the imports / reexports in transpiled runtime codebase. #2594 itself sufficiently explains the issue itself. It could be an implementation detail but so far based on observation tsc / babel works in the same way, which makes think it'd better to align as well. As issue described normally this won't appear but if there's some sort of circular dependencies, or reexports have dependencies across each other it may reveal different behavior.

For the change itself, PR changes the order of injecting handled export_all stmt by putting it after require stmt is created. In result, export_all stmt doesn't use extra_stmt (which appends to stmt at the end). Also changed exports_alls to map to stmt itself - when encountering ExportAll stmt it is gauranteed we'll need stmt anyway - hashmap contains generated stmt instead of only keeping name of export. This allowed easier lookup at the end.

Lastly, I noticed there is prior test cases from #133 (https://github.com/swc-project/swc/pull/133/files#diff-6d08f604fc5444313bf8d80ca76a84f5abbc95129eb4e1311592637fbb17b089R1075) , looks like it is coming from original transform impl. Test cases are updated without adding new one.

@JeremyGrieshop
Copy link
Contributor

Thank you for tackling this! I suspect the test cases for my recent merge (tests/fixture/issue-2548/) also need to be updated in order for the workflow tests to pass.

@kwonoj kwonoj force-pushed the fix-cjs-export-all-ordering branch from 03edc8a to 213a35e Compare October 31, 2021 17:16
@kwonoj
Copy link
Member Author

kwonoj commented Oct 31, 2021

Thank you for tackling this! I suspect the test cases for my recent merge (tests/fixture/issue-2548/) also need to be updated in order for the workflow tests to pass.

Thanks, I tried to update test cases as well.

@kwonoj kwonoj force-pushed the fix-cjs-export-all-ordering branch from 213a35e to 34d8da1 Compare October 31, 2021 18:10
@kwonoj kwonoj force-pushed the fix-cjs-export-all-ordering branch from 34d8da1 to 4a1cede Compare November 1, 2021 04:04
@kdy1 kdy1 added this to the v1.2.107 milestone Nov 1, 2021
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.

Thank you!

I have some concerns about changes.

ecmascript/transforms/module/src/common_js.rs Outdated Show resolved Hide resolved
ecmascript/transforms/module/src/common_js.rs Show resolved Hide resolved
@JeremyGrieshop
Copy link
Contributor

This may possibly resolve #1733, too.

@kwonoj kwonoj force-pushed the fix-cjs-export-all-ordering branch from 5b16122 to 601aa9a Compare November 2, 2021 00:53
@kwonoj kwonoj force-pushed the fix-cjs-export-all-ordering branch from 601aa9a to 3436fff Compare November 2, 2021 01:06
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.

LGTM.
I found one issue, but it's not related to this PR.
I'll patch it after merging this. Thanks!

ecmascript/transforms/module/src/common_js.rs Show resolved Hide resolved
@kwonoj
Copy link
Member Author

kwonoj commented Nov 2, 2021

Appreciate for the review for both, @kdy1 and @JeremyGrieshop 🙇

@kdy1 kdy1 changed the title fix(es/transforms/cjs): preserve import order for reexports fix(es/transforms/cjs): Preserve order of imports for reexports Nov 2, 2021
@kdy1 kdy1 merged commit 5b141ee into swc-project:master Nov 2, 2021
@kwonoj kwonoj deleted the fix-cjs-export-all-ordering branch November 2, 2021 08:21
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 4, 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.

Existing order of generated requires/defines can be problematic for inter-dependency relationships
3 participants