-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix bug super
ref check doesn’t honor spec evaluation order
#5801
Conversation
@buunguyen, thanks for your PR! By analyzing the history of the files in this pull request, we identified @existentialism, @hzoo and @loganfsmyth to be potential reviewers. |
@@ -0,0 +1,3 @@ | |||
{ | |||
"throws": "'super.*' is not allowed before super()" |
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.
Is this is valid, why are we asserting it throws?
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 think it's not valid because super.foo
is being accessed before the call to super()
. (See rule SuperProperty:super.IdentifierName
in spec).
That's consistent with behavior in Firefox. This will throw:
class Bar {
foo() {
console.log('out');
}
}
class Foo extends Bar {
constructor() {
super.foo(super());
}
}
new Foo()
=> ReferenceError: |this| used uninitialized in Foo class constructor
But the following would run and print "out" in Firefox.
class Bar {
foo() {
console.log('out');
}
get method() {
return 'foo';
}
}
class Foo extends Bar {
constructor() {
super[super().method]();
}
}
new Foo()
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.
Lol, I got this confused with the valid case below. Ignore me.
Codecov Report
@@ Coverage Diff @@
## 7.0 #5801 +/- ##
==========================================
- Coverage 84.91% 84.87% -0.04%
==========================================
Files 284 284
Lines 9928 9927 -1
Branches 2788 2786 -2
==========================================
- Hits 8430 8426 -4
- Misses 988 991 +3
Partials 510 510
Continue to review full report at Codecov.
|
# Conflicts: # packages/babel-plugin-transform-es2015-classes/src/vanilla.js
Just resolved conflict from #5802 that was just merged. |
Any further feedback on this? Thanks! |
Per spec, the following is valid code but Babel throws
'super.*' is not allowed before super()
error.Fixed by performing validation in
exit
handler ofMemberExpression
whose object issuper
. Also added a related test for the case ofsuper.foo(super());
(should throw).