closure-compiler: Unable to set property as extern when compiling in ADVANCED level

Hi guys,

First of all, I’m new to closure-compiler, so please bear with me.

I’m unable to get my web worker module (below snippet) to work with closure-compiler when using the ADVANCED level.

$ closure-compiler --compilation_level ADVANCED --js trock.js
var tRock;
self.addEventListener('message', (ev) => {
    /** @const */
    const msg = ev.data;

    switch(msg.tag) {
    case 'upload':
        tRock = msg.ep.tRock; // <------- error happens here after it's compiled
        [...]
        break;
    default:
        //console.error("unexpected msg from main thread", msg);
        self.close();
    }
});

When the compiler runs, it changes this:


switch(msg.tag) {
    case 'upload':
        tRock = msg.ep.tRock

to:

switch(a) {
    case 'upload':
        k=a.a.g

How i can prevent renaming msg.ep ? I tried to put /** @const */, but it had no impact.

As this is a web worker, the ev message is received from elsewhere and the compiler should not rename its properties.

I was expecting the following correct output:

switch(a.tag) {
    case 'upload':
      k=a.ep.tRock

Help appreciated. Thanks

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I think we’re missing the extern for replaceAll - I don’t see it anywhere in es[356].js.