Rollup: Named export renaming uses reserved keywords

Created on 20 Mar 2019  路  3Comments  路  Source: rollup/rollup

  • Rollup Version: v1.7.0
  • Operating System (or Browser): Linux / Firefox v64
  • Node Version: v10.12.0

Rollup seems to rename named exports in some cases when using code splitting (export { var1 as a, var2 as b, ... }, see first Rollup repl link for minimal repro).

This is all fine, but issues arise if one of the chunks contains a huge amount of named exports (in my case, a UI library with icons). After we run out of single letter tokens, Rollup will start using, aa, ab ... and eventually da, db ... do. It seems there's no checks in place that avoid using reserved keywords here such as do, which now occurs in my project. My bundle ends up containing:

import { a as firstExport, b as secondExport, ... dn as IconFavorite, do as IconFavoriteFilled, dp as IconFilledSquare, ... }
                                                                      ^^

which create-react-app chokes on when importing the resulting bundle (Unexpected keyword 'do').

How Do We Reproduce?

Minimal reproduction of the renaming behavior

repl link

Note how black is renamed to a in the above example.

Minimal reproduction of the rename as do problem

repl link

With a huge number of variables (271 to be exact :smile:) we can see the problematic output being generated. ctrl+f search for as do or do as in the output and you will spot the problem, which also the repl's syntax highlighting displays as a keyword:

image

Expected Behavior

Avoid using reserved keywords when renaming named exports

Actual Behavior

Reserved keywords such as do are being used for renamed named exports.

b鹿 馃敧 code-splitting t鹿 馃悶 bug

Most helpful comment

Thanks for the issue. There is in fact sanitation for regular variable names but not for auto-shortened exports and imports. Should not be too difficult to fix. I am working on a few other things at the moment but it should be possible to sneak in a fix for this soon.

All 3 comments

Oops looks like the second repl link is broken due to being too long. Here's a version with shorter variable names: repl link

Thanks for the issue. There is in fact sanitation for regular variable names but not for auto-shortened exports and imports. Should not be too difficult to fix. I am working on a few other things at the moment but it should be possible to sneak in a fix for this soon.

As it turns out, it was really not a lot of effort as I could just re-use your nice test case as an official test and we already have a table of reserved names in the code. Fix at #2768.

Was this page helpful?
0 / 5 - 0 ratings