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
Memoize class binding when compiling private methods and static elements #15701
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/54907/ |
@@ -1103,6 +1110,10 @@ export function buildFieldsInitNodes( | |||
return injectSuperRef; | |||
}; | |||
|
|||
const classRefForInnerBinding = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When ref
is not defined and classRefFlags.ForInnerBinding
is not enabled, e.g. compiling a plain class class C {}
without private methods / static elements, we will generate a uid identifier but we do not insert it to the final AST. In this case the memoizer variable _class0
, _class1
, etc. is not continuous.
Is only generating the extra ref when the class is reassigned doable? |
I pushed some commits to do #15701 (comment), wdyt about this approach? |
@nicolo-ribaudo Thanks for working on this. I didn't wrap it under the reassignment check because
Btw TypeScript memoizes the class binding without checking if it is reassigned, too: https://www.typescriptlang.org/play?#code/MYGwhgzhAEBiD29oG8BQ0PQgFzNglsNAMQjQC8ciA3KgL5A |
288e0a0
to
3a97c28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I reverted my changes, the code is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Just rebased this PR and it looks good to me.
In this PR we memoise the class binding when it is referenced in private methods or static elements, either via
this
or the class id. Previously we replacedthis
with class id, but as #15696 point out,it will fail when the outer binding is reassigned.
I suggest reviewing this PR by commits as there are many fixture changes.