ampproject / rollup-plugin-closure-compiler

Leverage Closure Compiler to minify and optimize JavaScript with Rollup.
Apache License 2.0
292 stars 27 forks source link

Unexpected character '#' , when Computed property names contain invalid javascript identifier #465

Open icy0307 opened 1 year ago

icy0307 commented 1 year ago

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
    console.log({
    });
  2. 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?