Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named export renaming uses reserved keywords #2761

Closed
FruitieX opened this issue Mar 20, 2019 · 3 comments · Fixed by #2768
Closed

Named export renaming uses reserved keywords #2761

FruitieX opened this issue Mar 20, 2019 · 3 comments · Fixed by #2768
Assignees

Comments

@FruitieX
Copy link

FruitieX commented Mar 20, 2019

  • 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 😄) 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.

@FruitieX
Copy link
Author

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

@lukastaegert
Copy link
Member

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.

@lukastaegert
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants