Memoize class binding when compiling private methods and static elements#15701
Memoize class binding when compiling private methods and static elements#15701JLHwung merged 4 commits intobabel:mainfrom
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/54907/ |
| return injectSuperRef; | ||
| }; | ||
|
|
||
| const classRefForInnerBinding = |
There was a problem hiding this comment.
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
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
👍 I reverted my changes, the code is good
JLHwung
left a comment
There was a problem hiding this comment.
✅ 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
thisor the class id. Previously we replacedthiswith 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.