google / google/closure-compiler
Quoted properties are stripped when using advanced options
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
If you have a constant with quoted field names the closure compiler will remove these field names when using the advanced flags.
Reproduction here: http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250Aconst%2520EVENT_NAMES%2520%253D%2520%257B%250A%2520'swipe'%253A%2520true%252C%250A%257D%250A%250A%252F**%2520%2540export%2520*%252F%250Afunction%2520foo(eventName)%2520%257B%250A%2509if%2520(!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()))%2520%257B%250A%2520%2520%2520%2520%2520%2520return%2520false%253B%250A%2520%2520%257D%250A%2520%2520return%2520true%253B%250A%257D%250Awindow%255B'foo'%255D%253Dfoo%253B%250A
This shouldn't happen, the quoted field names should remain after compilation.
A workaround is to use a computed property, but this shouldn't be needed:
http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250Aconst%2520EVENT_NAMES%2520%253D%2520%257B%250A%2520%255B'swipe'%255D%253A%2520true%252C%250A%257D%250A%250A%252F**%2520%2540export%2520*%252F%250Afunction%2520foo(eventName)%2520%257B%250A%2509if%2520(!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()))%2520%257B%250A%2520%2520%2520%2520%2520%2520return%2520false%253B%250A%2520%2520%257D%250A%2520%2520return%2520true%253B%250A%257D%250Awindow%255B'foo'%255D%253Dfoo%253B%250A
Contributor guide
Assessment
This issue has not been assessed yet.