Skip to content

refactor(transformer/react): don't follow the Babel's imports order#6176

Closed
Dunqing wants to merge 1 commit intomainfrom
09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order
Closed

refactor(transformer/react): don't follow the Babel's imports order#6176
Dunqing wants to merge 1 commit intomainfrom
09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Sep 30, 2024

The ImportDeclaration orders are not matter, they are always hoisted. Previously to 100% match Babel's output to pass the tests, we did some weird logic in our implementation. In this PR I removed them, and always inserted the imports at the top of the statements. The reason for doing this is I am moving ModuleImports to https://github.com/oxc-project/oxc/blob/5b5aad856213df18f09bf1972f6e3a13a5302a15/crates/oxc_transformer/src/common/mod.rs#L14-16

After being moved to common, the NamedImports will only insert imports once in common instead of inserting in each plugin that used it.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 30, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Sep 30, 2024
Copy link
Member Author

Dunqing commented Sep 30, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Dunqing and the rest of your teammates on Graphite Graphite

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 30, 2024

CodSpeed Performance Report

Merging #6176 will not alter performance

Comparing 09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order (73cfb59) with main (f2ac584)

Summary

✅ 29 untouched benchmarks

@Dunqing Dunqing force-pushed the 09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order branch from 5b5aad8 to 5908859 Compare September 30, 2024 07:14
@Dunqing Dunqing force-pushed the 09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order branch from 5908859 to 73cfb59 Compare September 30, 2024 07:16
@overlookmotel
Copy link
Member

overlookmotel commented Sep 30, 2024

Personally I am not keen on diverging from Babel at this stage.

My feeling is that Babel's transformer tests which we are using for conformance are not enough. To really test the transformer, we need to throw a lot more code at it. The best way I can see to do that is something like this:

  • Crawl all the JS/TS files from the top 1000 npm packages.
  • Run each of them through both Babel and Oxc transformer.
  • Compare the outputs.

When we have no mismatches all all, we can have high confidence that our transformer is bug-free (or at least has no more bugs than Babel). But to run those tests without spurious differences in the diffs, we need our transformer's output to match Babel's exactly - even in cosmetic aspects like statement order.

I'll look into this further and try to find if we can achieve what we're trying to do (move ModuleImports into common) without failing any tests. I think it should be possible.

@Dunqing
Copy link
Member Author

Dunqing commented Sep 30, 2024

@overlookmotel Feel free to take over this stack, I am on holiday now. 🏖️

@overlookmotel
Copy link
Member

#6183 negates the need for this.

@Boshen Boshen deleted the 09-30-refactor_transformer_react_don_t_follow_the_babel_s_imports_order branch February 17, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants