google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.39k stars 1.15k forks source link

Quoted ES6 Getters/Setters Transpiled to Unquoted #2282

Open ChadKillingsworth opened 7 years ago

ChadKillingsworth commented 7 years ago
class Foo extends HTMLElement {
 get 'foobar'() { return 'foobar'; }

 attachedCallback() {
   this.addEventListener('click', () => {
     console.log(this['foobar']);
   }, false);
 }
}
window['Foo'] = Foo;

The transpiled getter for foobar is not properly quoted.

MatrixFrog commented 7 years ago

@justinfagnani want to take a stab at fixing this? I think we just need to treat this the same as a computed-property getter (get ['foobar']() { return 'foobar'; }) which means the declaration we output will look like Foo.prototype['foobar'] instead of Foo.prototype.foobar.

This all happens in visitComputedPropInClass (which looks like it's misnamed and should be renamed to visitComputedPropOrGetterOrSetterInClass and perhaps refactored into smaller methods)