-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update async await transpilation to avoid captures of super
#3103
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
Changes from 2 commits
56401a1
cfa4af4
20b4c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,73 @@ public void testInnerSuperReference() { | |
"}")); | ||
} | ||
|
||
@Test | ||
public void testInnerSuperCallEs2015Out() { | ||
setLanguageOut(LanguageMode.ECMASCRIPT_2015); | ||
test( | ||
lines( | ||
"class A {", | ||
" m() {", | ||
" return this;", | ||
" }", | ||
"}", | ||
"class X extends A {", | ||
" async m() {", | ||
" return super.m();", | ||
" }", | ||
"}"), | ||
lines( | ||
"class A {", | ||
" m() {", | ||
" return this;", | ||
" }", | ||
"}", | ||
"class X extends A {", | ||
" 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 commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we just get the prototype directly from () => Object.getPrototypeOf(this).m; There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see my mistake. I wonder which is the safer choice in the face of code that mucks around with prototypes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed this with @concavelenz Would you be willing to make that change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course - done. |
||
" return $jscomp.asyncExecutePromiseGeneratorFunction(", | ||
" function* () {", | ||
" return $jscomp$async$super$get$m().call($jscomp$async$this);", | ||
" });", | ||
" }", | ||
"}")); | ||
} | ||
|
||
@Test | ||
public void testInnerSuperCallStaticEs2015Out() { | ||
setLanguageOut(LanguageMode.ECMASCRIPT_2015); | ||
test( | ||
lines( | ||
"class A {", | ||
" static m() {", | ||
" return this;", | ||
" }", | ||
"}", | ||
"class X extends A {", | ||
" static async m() {", | ||
" return super.m();", | ||
" }", | ||
"}"), | ||
lines( | ||
"class A {", | ||
" static m() {", | ||
" return this;", | ||
" }", | ||
"}", | ||
"class X extends A {", | ||
" static m() {", | ||
" const $jscomp$async$this = this;", | ||
" const $jscomp$async$super$get$m = () => Object.getPrototypeOf(this).m;", | ||
" return $jscomp.asyncExecutePromiseGeneratorFunction(", | ||
" function* () {", | ||
" return $jscomp$async$super$get$m().call($jscomp$async$this);", | ||
" });", | ||
" }", | ||
"}")); | ||
} | ||
|
||
@Test | ||
public void testNestedArrowFunctionUsingThis() { | ||
test( | ||
|
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