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

Declaring Symbol variable conflicts with namespaceToStringTag #3969

Closed
yyx990803 opened this issue Feb 22, 2021 · 2 comments · Fixed by #3971
Closed

Declaring Symbol variable conflicts with namespaceToStringTag #3969

yyx990803 opened this issue Feb 22, 2021 · 2 comments · Fixed by #3971

Comments

@yyx990803
Copy link
Contributor

The bug occurs when combining the following:

  1. -f cjs
  2. --namespaceToStringTag
  3. Code: var Symbol = ...

Expected Behavior

Generated code should work.

Actual Behavior

The generated code:

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });
exports[Symbol.toStringTag] = 'Module';

var Symbol = 1;

exports.Symbol = Symbol;

Due to the var hoisting behavior, Symbol is undefined then exports[Symbol.toStringTag] = 'Module'; is executed.

This my seem like a very niche case but the actual code was found in lodash-es. i.e. if the user tries to bundle lodash-es with the above options they will run into the same error.

Possible Fixes

Make Symbol a reserved variable name (i.e. always consider it already declared) so that var Symbol in user code is rewritten to var Symbol$1 or something similar.

@lukastaegert
Copy link
Member

I see, that is not good. Will need to check if this conflicts in any way with how Polyfills handle Symbol.

@lukastaegert
Copy link
Member

Of course there are no issues with Polyfills as they all appear to first identify the global object and operate on that. Fix at #3971. This also avoids the same problem for Object and Promise, which Rollup also relies on for various things.

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

Successfully merging a pull request may close this issue.

2 participants