-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ES6 transpilation of async + super call moves properties from unquoted->quoted #21088
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
Comments
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. |
//cc @rbuckton |
I am sure I am missing something, but why doesn't that one work? |
@scriby This isn't valid javascript, unfortunately. The only way to address your concern would be to inject a wrapper for every super-property access in an async function: // TypeScript
class B extends A {
async test() {
// get
const w = super.w;
// set
super.x = 1;
// destructuring
({ y: super.y } = { y: 2 });
// call
super.z();
}
}
// JavaScript
class B extends A {
test() {
const _super = Object.create(null, {
w: { get: () => super.w },
x: { set: (value) => super.x = value },
y: { set: (value) => super.y = value },
z: { get: () => super.z }
});
return __awaiter(this, void 0, void 0, function* () {
// get
const w = _super.w;
// set
_super.x = 1;
// destructuring
({ y: _super.y } = { y: 2 });
// call
_super.z.call(this);
});
}
} |
So this one would work?
|
@scriby, not if class Base {
testCounter = 0;
get test() {
this.testCounter++;
return () => this.testCounter;
}
}
class Sub extends Base {
async fn() {
console.log(super.test());
console.log(super.test());
}
} You would expect it to print:
But with the above proposal it would print:
|
Nice test case. I'll just keep guessing at it until something sticks :)
|
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 const _super = Object.create(null, {
w: { get: () => super.w },
x: { set: (value) => super.x = value },
y: { set: (value) => super.y = value },
z: { get: () => super.z }
}); |
Ah sorry, I should have read that more carefully. Looks great! |
No idea how palatable this is, but another option would be:
where _super then uses |
TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a specific accessor for each property access on super, which fixes the quoted/unquoted confusion. It keeps the generic accessor for element access statements. Fixes microsoft#21088.
TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a variable `_superProps` that contains accessors for each property accessed on super within the async method. This allows accessing the properties by name (instead of quoted string), which fixes the quoted/unquoted confusion. The change keeps the generic accessor for element access statements to match quoting behaviour. Fixes microsoft#21088.
TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a variable `_superProps` that contains accessors for each property accessed on super within the async method. This allows accessing the properties by name (instead of quoted string), which fixes the quoted/unquoted confusion. The change keeps the generic accessor for element access statements to match quoting behaviour. Fixes microsoft#21088.
TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a variable `_superProps` that contains accessors for each property accessed on super within the async method. This allows accessing the properties by name (instead of quoted string), which fixes the quoted/unquoted confusion. The change keeps the generic accessor for element access statements to match quoting behaviour. Fixes microsoft#21088.
TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a variable `_superProps` that contains accessors for each property accessed on super within the async method. This allows accessing the properties by name (instead of quoted string), which fixes the quoted/unquoted confusion. The change keeps the generic accessor for element access statements to match quoting behaviour. Fixes microsoft#21088.
TypeScript Version: Version 2.7.0-dev.20180109
Code
Expected behavior:
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.
Actual behavior:
_super("test")
boils down tosuper['test']
, which breaks whentest
was renamed by an optimizing compiler.The text was updated successfully, but these errors were encountered: