Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

The keyword 'await' is reserved #79

Closed krnlde closed 7 years ago

krnlde commented 7 years ago

Run this specimen through https://butternut.now.sh/?version=0.4.1

{
  await: function await() {}
}

// -> Error: The keyword 'await' is reserved (2:2)  bundle.js:324

Both await occurrences are perfectly valid and parsed correctly by Chrome (V8), butternut refuses to minify this.

This code is (essentially) used by the AsyncGenerator babel transform plugin.

Rich-Harris commented 7 years ago

Acorn won't parse it by default. The way we fixed this in Rollup was to add an acorn option where you could pass through the appropriate options:

const {code, map} = butternut.squash(source, {
  acorn: {
    allowReserved: true
  }
});

Might be tricky to do via the CLI though...

krnlde commented 7 years ago

Mhm. Maybe it is better to inject this by default through butternut? What would be the downsides?

Rich-Harris commented 7 years ago

I was wondering the same. I feel like there must be a reason that Acorn disables it by default, but I'm having a hard time understanding what the dangers are. I guess we could do that, and revisit it if it causes any weird bugs for people

krnlde commented 7 years ago

The dangers would be that all "future reserved keywords" are valid. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Future_reserved_keywords

I don't know what the implications are though.

Rich-Harris commented 7 years ago

I think that the worst case is that it would preserve any existing bugs in the code, it wouldn't ever introduce new ones (since the mangler avoids reserved words)

krnlde commented 7 years ago

Sounds like a reasonable change.