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
refactor: do not rely on AST extra properties in plugins #11662
refactor: do not rely on AST extra properties in plugins #11662
Conversation
@@ -32,8 +32,8 @@ class Foo { | |||
(o == null ? void 0 : o.Foo.m.bind(o.Foo))().toString(); | |||
((_o$Foo$self$getSelf = ((_o$Foo = o.Foo) == null ? void 0 : _o$Foo.self.getSelf.bind(_o$Foo.self))()) == null ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))(); | |||
((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) == null ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) == null ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))(); | |||
((_fn$Foo$self$getSelf = ((_fn = fn()) == null ? void 0 : (_fn$Foo = _fn.Foo) == null ? void 0 : _fn$Foo.self.getSelf.bind(_fn.Foo.self))()) == null ? void 0 : _fn$Foo$self$getSelf.m.bind(_fn$Foo$self$getSelf))(); | |||
((_fn$Foo$self$getSelf2 = (fn == null ? void 0 : (_fn$Foo$self2 = _fn$Foo$self = fn().Foo.self) == null ? void 0 : _fn$Foo$self2.getSelf.bind(_fn$Foo$self))()) == null ? void 0 : _fn$Foo$self$getSelf2.m.bind(_fn$Foo$self$getSelf2))(); |
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.
✌️Unnecessary memoizers removed.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/23457/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 99f7986:
|
8426858
to
71972b5
Compare
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
replacementPath.parentPath !== parentPath) && | ||
parentPath.isCallExpression() | ||
) { | ||
if (i === 0 && parentIsCall) { |
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.
What happens if we remove the i
check?
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.
Good question!
Since parentIsCall
is computed only once for the baseRef
, if we don't limit this branch with i === 0
, which means applying to the baseRef only, it will generate multiple memoizing assignment during looping all the optional chain elements.
This change fixes an issue in https://github.com/babel/babel/pull/11662/files#diff-778d6015479bf103795200e754865e9dL30 where fn().Foo.self
is memoized twice.
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.
Do we want to add this in a comment?
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.
🎉
As a follow-up to #11623, this PR refines
(a?.b)()
detection and ensures that plugins never rely onextra
AST properties. Also fixes a regression introduced in #11623 thatf((a?.b))
is incorrectly transformed intof((a == null ? void 0 : a.b.bind(a)))
.