ampproject / ampproject/rollup-plugin-closure-compiler
Unexpected character '#' , when Computed property names contain invalid javascript identifier
- Dominant language
- TypeScript
- Stars
- 293
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
**Please only file bugs/feature requests for rollup-plugin-closure-compiler here.**
## What's the issue?
Briefly describe the bug/feature request.
When Computed property names contain invalid javascript identifiers, like '#', '!',
acron parser fails because of forgetting to preserve quotation marks.
## How do we reproduce the issue?
We'll likely need to know:
1. Your Rollup configuration.
the test fixtures:
mixed-keys.test.js
```js
console.log({
['foo#']:'value',
});
```
3. Error logs from your console when invoking Rollup with this plugin present.
```
Unhandled rejection in test/literal-computed-keys/mixed-keys.test.js
/Users/icyflzhang/Documents/web/rollup-plugin-closure-compiler/node_modules/acorn/dist/acorn.js:2927
SyntaxError: Unexpected character '#' (1:54)
Parser.pp$4.raise (node_modules/acorn/dist/acorn.js:2927:15)
Parser.pp$9.getTokenFromCode (node_modules/acorn/dist/acorn.js:4695:10)
Parser.pp$9.readToken (node_modules/acorn/dist/acorn.js:4409:17)
Parser.pp$9.nextToken (node_modules/acorn/dist/acorn.js:4400:17)
Parser.pp$9.next (node_modules/acorn/dist/acorn.js:4357:10)
Parser.pp$3.parseIdent (node_modules/acorn/dist/acorn.js:2880:10)
Parser.pp$3.parsePropertyName (node_modules/acorn/dist/acorn.js:2686:107)
Parser.pp$3.parseProperty (node_modules/acorn/dist/acorn.js:2613:10)
Parser.pp$3.parseObj (node_modules/acorn/dist/acorn.js:2567:23)
Parser.pp$3.parseExprAtom (node_modules/acorn/dist/acorn.js:2302:19)
```
If this is a feature request you can use this section to point to a prototype/mockup that will help us understand the request.
## Additional context
This is because[ `LiteralComputedKeys` transformer ](https://github.com/ampproject/rollup-plugin-closure-compiler/blob/7ec95e00d7cc08e9fb168e0eb5a3e2ff66a0d5d7/src/transformers/chunk/literal-computed-keys.ts#L50) use `property.key.value`, which strip off quotation marks.
Could we use `property.key.raw` instead when present?
Contributor guide
Research direction
Read src/transformers/chunk/literal-computed-keys.ts, especially the referenced handling of property.key.value, then inspect test/literal-computed-keys/mixed-keys.test.js. Reproduce the computed key containing '#', and verify the fixture completes without Acorn's unexpected-character error while preserving the key's quotation marks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100