oxc-project / oxc-project/backlog
Simplify treatment of getter/setter bindings in private properties transform
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
I've reviewed the whole class private methods transform. Holy cow! It took a lot of code to do that transform, much more than I expected.
It all looks really good to me, except for one thing. PrivateProp has got very complicated now that it has to represent properties, methods, and getter/setters.
In particular, the logic around checking on getters/setters which binding is which (binding or binding2?) is a bit convoluted.
I have a suggestion:
Turn PrivateProp into an enum:
enum PrivateProp<'a> {
InstanceProp(BoundIdentifier<'a>),
StaticProp(BoundIdentifier<'a>),
InstanceMethod(BoundIdentifier<'a>),
StaticMethod(BoundIdentifier<'a>),
InstanceGetter(BoundIdentifier<'a>),
InstanceSetter(BoundIdentifier<'a>),
InstanceGetterSetter((BoundIdentifier<'a>, BoundIdentifier<'a>)),
StaticGetter(BoundIdentifier<'a>),
StaticSetter(BoundIdentifier<'a>),
StaticGetterSetter((BoundIdentifier<'a>, BoundIdentifier<'a>)),
Accessor,
}
This enum encodes all the info from is_static, method_kind and is_accessor in its discriminant.
It's the same size as the previous struct version.
There's no ambiguity about which binding is which for getters/setters, so can set it correctly once in the entry phase of transform, and then it doesn't have to swap binding and binding2 around depending on method_kind over and over during the traversal of class body.
Also it'd remove the need to have "I can unwrap this Option because I know it must have a value because this is a setter" etc logic. Whether it does have a setter binding or not is statically encoded by the type.
I hope that after that change, a lot of the other logic can be simplified. Pretty much all the methods have different branches for properties / methods / getters / setters, and for instance / static, so it makes some sense, I think, to represent all these options in an enum and then match on it.
@Dunqing Do you think this would make things clearer? Or just make it even more complex?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the private properties transform and its PrivateProp representation, then trace the entry phase and class body traversal where getter/setter bindings are assigned and used. Compare the existing struct branches with the proposed enum variants and verify that binding order and optional setter handling remain explicit throughout the transform.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100