-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Standardize conventions for transforms #4881
Labels
A-transformer
Area - Transformer / Transpiler
C-cleanup
Category - technical debt or refactoring. Solution not expected to change behavior
Comments
overlookmotel
changed the title
Standardize format and naming of transforms
Standardize conventions for transforms
Aug 13, 2024
overlookmotel
added
C-cleanup
Category - technical debt or refactoring. Solution not expected to change behavior
A-transformer
Area - Transformer / Transpiler
and removed
C-bug
Category - Bug
labels
Aug 13, 2024
TODO: add this to crate README |
Boshen
pushed a commit
that referenced
this issue
Aug 15, 2024
Add a README to `oxc_transformer` crate, including a "style guide" for writing transforms. As discussed in #4881.
This was referenced Aug 19, 2024
Dunqing
added a commit
that referenced
this issue
Aug 20, 2024
This was referenced Aug 22, 2024
overlookmotel
pushed a commit
that referenced
this issue
Aug 22, 2024
This was referenced Aug 22, 2024
overlookmotel
pushed a commit
that referenced
this issue
Aug 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-transformer
Area - Transformer / Transpiler
C-cleanup
Category - technical debt or refactoring. Solution not expected to change behavior
We are planning to build out a ton more transforms over next few months. The transformer is going to get a lot more complicated and unwieldy. To avoid it becoming hard to navigate and understand, I suggest that we adopt a standardized coding style to use on all transforms.
This is prompted in part from the difficulties I found in reviewing #4587.
I propose:
1. Make clear what are the "entry points" to transform
impl Traverse for MyTransform
.enter_*
andexit_*
.impl MyTransform
block. Those methods can be named descriptively.2. Encapsulate logic
All logic for each transform should live in that specific file, with no "leaking" into the parent transform. Each transform is only called into via the standard
enter_*
/exit_*
entry points.Only exception is that parent can check if child transform is enabled or not.
i.e. Instead of the parent being quite "fat":
oxc/crates/oxc_transformer/src/react/mod.rs
Lines 75 to 87 in a9c729a
Move the JSX-related logic into
jsx.rs
:3. Comments
Top of file
Each transform should include comment at top of file including:
Methods
If it's a complicated transform with multiple visitors which interact with each other, add comments explaining how the pieces fit together.
Code snippets
AstBuilder
calls are often very verbose. Preface each chunk ofAstBuilder
calls with a short comment of what this code produces. e.g.:Where we can improve on Babel
Where we feel Babel's implementation is inefficient, but we have to follow it at present to pass their tests, make a
// TODO(improve-on-babel): Babel's impl is poor because X, we could do better by Y
comment.Boring!
Sorry this is rather boring! Much of the above we're doing already, but I feel it's worth the effort now to formalize some conventions and then go "by the book". It's tedious, but I feel that if we're a bit "stiff" now, we'll benefit in long run from a more maintainable and contributor-friendly transformer.
My suggestions above are not set in stone. If anyone would like to propose different conventions, go ahead. I just feel we should have some conventions, and stick to them.
The text was updated successfully, but these errors were encountered: