-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Update async await transpilation to avoid captures of super
#3103
Update async await transpilation to avoid captures of super
#3103
Conversation
I don't think we can make this change. Is there some workaround for the MS edge bug we could generate here? |
In an arrow function in Edge, it looks like
I can keep looking for other options. One option is to replace the reference to |
d2925ef
to
ef49982
Compare
@brad4d I think I may have found a workable solution: Use I only switch to this technique if classes are not being transpiled. This avoids a dependence on |
I tested this on both Chrome and MS Edge in a project where I'm trying to land ES6 out. |
…ing ES2015+ output. MS Edge 17 does not properly capture references to `super` in an arrow function. Closes google#3101
ef49982
to
56401a1
Compare
" m() {", | ||
" const $jscomp$async$this = this;", | ||
" const $jscomp$async$super$get$m =", | ||
" () => Object.getPrototypeOf(this.constructor).prototype.m;", |
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.
Couldn't we just get the prototype directly from this
?
() => Object.getPrototypeOf(this).m;
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.
Unfortunately not. See the comments in the following snippet:
class Base {
static foo() { console.log('base foo'); }
bar() { console.log('base bar'); }
}
class Child extends Base {
static foo() {
console.log(Object.getPrototypeOf(this), Object.getPrototypeOf(this).foo);
Object.getPrototypeOf(this).foo.call(this);
}
bar() {
console.log(Object.getPrototypeOf(this), Object.getPrototypeOf(this).bar);
Object.getPrototypeOf(this).bar(); // logs out "base bar" appropriately
Object.getPrototypeOf(this).bar.call(this); // infinitely loops and locks up the Chrome tab!
}
}
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.
Ah, I see my mistake.
I meant to say Object.getPrototypeOf(Object.getPrototypeOf(this))
I wonder which is the safer choice in the face of code that mucks around with prototypes?
Is it more likely that this.constructor
isn't pointing at the right thing or that an additional object has been inserted into the prototype chain?
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.
Discussed this with @concavelenz
We agree that it seems more correct and slightly safer to call Object.getPrototypeOf()
twice to get up to the superclass prototype rather than relying on this.constructor
.
Would you be willing to make that change?
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.
Of course - done.
@ChadKillingsworth Is there some reason why we can't just do |
Classes and super references are tricky to transpile. I was able to simplify static references to |
for (String replacedMethodName : functionContext.replacedSuperProperties) { | ||
// MS Edge 17 cannot properly capture references to "super" in an arrow function. |
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 you have any link we could insert here pointing to the MS Edge bug?
We'd really like to be able to track when the MS Edge bug gets fixed, or if it's already fixed and we're just stuck because of installed browsers not getting the fix.
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 created one and added the link
ec9f2ca
to
20b4c32
Compare
Imported and sent for internal review and testing. |
…peOf` This is in effect a rollback of the functional change in #3103 Preserving the `super.function()` syntax is more spec-compliant in some cases, and MS Edge 17 is incredibly rare these days. PiperOrigin-RevId: 406004773
Closes #3101
MS Edge 17 does not properly honor captures of
super
in arrow functions. Avoid this pattern when transpiling async/await.