google / google/closure-compiler
Stop representing quoted member functions as computed properties in the AST
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Filing this after internal discussion with @concavelenz
Right now the compiler represents quoted member functions, e.g. `class C { 'f'() {} }`, the same way it represents computed property member functions: `class C { ['f']() {} }`.
This means that the compiler prints `class C { ['f']() {} }` if given `class C { 'f'() {} }`: [example](https://closure-compiler-debugger.appspot.com/#input0%3Dclass%2520C%2520%257B%250A%2520%2520'f'()%2520%257B%257D%250A%257D%26input1%26conformanceConfig%26externs%26refasterjs-template%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue).
This does not align with how we treat quoted regular object literal properties, getters, and setters. Those have a special 'quoted_prop' attribute to store whether they were originally quoted or not.
https://github.com/google/closure-compiler/blob/6f01d69e6fb0116b9b5cdc47ce9d25e2e4d3131a/src/com/google/javascript/rhino/Node.java#L385
Computed properties/getter/setters are stored differently in the AST.
We probably want to revisit this decision at some point:
1. it's confusing to have different behavior for member functions and regular properties/getters/setters.
2. @concavelenz suggested that (paraphrasing): we want the AST for quoted member functions to maintain the code's original structure, even though they are conceptually similar to computed properties. we also already have a concept of a quoted property.
Contributor guide
Assessment
This issue has not been assessed yet.