You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ES6 transpilation of async + super call moves properties from unquoted->quoted #21088
TypeScript should not emit code that accesses properties by string name, as this breaks optimizers such as Closure Compiler or Uglify with property renaming enabled.
scriby This isn't valid javascript, unfortunately. super cannot be captured like an identifier. The only valid uses of super are a super-constructor call (i.e. super()), super-property access (i.e. super.test), or super-element access (i.e. super["test"]). We chose to use super-element access here as it allows us to parameterize super properties using super-element access in an arrow function closure.
The only way to address your concern would be to inject a wrapper for every super-property access in an async function:
This is effectively the same as my proposal above, except that my proposal logically groups all of these helpers together and allows for the use of super.x as a binding target in a destructuring assignment:
No idea how palatable this is, but another option would be:
class A {
test(arg) { }
}
class B extends A {
test() {
const _super = name => super[name];
return __awaiter(this, void 0, void 0, function* () {
return _super({test: [this, someArg]});
});
}
}
where _super then uses const [key, args] = Object.entries(obj)[0]; super[key].call(...args) instead of a string directly. Closure and Uglify would then know to rename 'test' in both places, and they'd get renamed to the same string, by design.
Activity
mhegazy commentedon Jan 9, 2018
So what is the proposal here? this was the best solution we came up with for the super access that does not completely massacre the use code.
mhegazy commentedon Jan 9, 2018
//cc Ron Buckton (@rbuckton)
scriby commentedon Jan 9, 2018
I am sure I am missing something, but why doesn't that one work?
rbuckton commentedon Jan 9, 2018
scriby This isn't valid javascript, unfortunately.
supercannot be captured like an identifier. The only valid uses ofsuperare a super-constructor call (i.e.super()), super-property access (i.e.super.test), or super-element access (i.e.super["test"]). We chose to use super-element access here as it allows us to parameterize super properties using super-element access in an arrow function closure.The only way to address your concern would be to inject a wrapper for every super-property access in an async function:
scriby commentedon Jan 9, 2018
So this one would work?
rbuckton commentedon Jan 16, 2018
scriby, not if
super.testis a getter with side-effects, as the side-effects happen in the wrong place. Consider:You would expect it to print:
But with the above proposal it would print:
scriby commentedon Jan 16, 2018
Nice test case. I'll just keep guessing at it until something sticks :)
rbuckton commentedon Jan 16, 2018
This is effectively the same as my proposal above, except that my proposal logically groups all of these helpers together and allows for the use of
super.xas a binding target in a destructuring assignment:scriby commentedon Jan 17, 2018
Ah sorry, I should have read that more carefully. Looks great!
calebegg commentedon Aug 17, 2018
No idea how palatable this is, but another option would be:
where _super then uses
const [key, args] = Object.entries(obj)[0]; super[key].call(...args)instead of a string directly. Closure and Uglify would then know to rename 'test' in both places, and they'd get renamed to the same string, by design.Per-property super accessors in async functions.
Per-property super accessors in async functions.
Per-property super accessors in async functions.
Per-property super accessors in async functions.
Per-property super accessors in async functions.