ampproject/rollup-plugin-closure-compiler

Allow named imports with names `Storage`, `Plugin` and more.

prateekbh opened this issue · 4 comments

Closure throws an error if it sees a class named Storage or Plugin.

e.g.: https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250Aclass%2520Plugin%257B%257D

This might be fine as one can argue that it is a reserved word. But if these classes are a part of my imports and not global definitions, it should be a clear indication that we can safely mangle this.

What's the issue?

Closure throws error.

How do we reproduce the issue?

file-A:

export class Plugin {
}

file-B:

import {Plugin} from './file-A`
const p = new Plugin();

Run ☝️ this, with rollup-plugin-closure-compiler.

On another thought:

May be we can expose a config where user can just specify what other names do they want to be mangled before CC looks at the code

I also see this with names like Console and Location, that the Angular libraries declare classes for. This sounds like the kind of thing assume_function_wrapper (which is set by default with this plugin) should account for.

google/closure-compiler#3098

Looks like the Closure folks are investigating a flag that would remedy this issue for the rollup plugin.

I'd prefer to use the flag instead of manual mangling like attempted in #105.

WRT mangling, @rollup/plugin-replace can be used to rename the problematic class names. It's not a real generic solution though.