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

Rollup v0.56.5 breaks bundles where there are two (or more) classes defined with the same name #2047

Closed
ilmiont opened this issue Mar 12, 2018 · 3 comments · Fixed by #2048
Closed

Comments

@ilmiont
Copy link

ilmiont commented Mar 12, 2018

Please refer to the repro here: https://github.com/ilmiont/rollup-v0.56.5-test

The repro-v0.56.4.js was compiled in Rollup v0.56.4 and runs fine in current browsers (Chrome latest, Firefox latest).

The repro-v0.56.5.js was compiled from the same source in Rollup v0.56.5, and does not run in browsers, as it throws an Uncaught ReferenceError: Model is not defined.

This is caused by the change in Rollup v0.56.5 due to #2025 which creates the following in the bundle:

let Model$1 = class Model extends Model { }

Maybe it seems like an edge case that there are two classes with the same name (as written) in the project, but I really don't think it is. In my scenario, I've got an ecosystem of libraries with components that extend each other to add additional functionality.

The end result is, that in an app I'm working on, a search for "class Model" or "class Controller" definitions in the unbundled source will result in several matches, which wasn't an issue in Rollup v0.56.4 because it would just append $x to the end of each class name (where x is obviously an integer incremented for each new class definition of this name).

The new syntax in Rollup v0.56.5 means builds of this app are currently completely broken, and I don't think there's a way to mitigate this without me renaming all my classes. Sticking with Rollup v0.56.4 for now until this behaviour is confirmed.

@ilmiont ilmiont changed the title Rollup v0.56.5 breaks bundles where there are two classes with the same name Rollup v0.56.5 breaks bundles where there are two (or more) classes defined with the same name Mar 12, 2018
@guybedford
Copy link
Contributor

REPL case - https://rollupjs.org/repl?version=0.56.5&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyME1vZGVsQmFzZSUyMGZyb20lMjAlNUMlMjIuJTJGTW9kZWxCYXNlLmpzJTVDJTIyJTNCJTVDbiU1Q25jbGFzcyUyME1vZGVsJTIwZXh0ZW5kcyUyME1vZGVsQmFzZSUyMCU3QiU1Q24lNUNuJTVDdGNvbnN0cnVjdG9yKCklMjAlN0IlNUNuJTVDdCU1Q3RzdXBlcigpJTNCJTVDbiU1Q3QlNUN0Y29uc29sZS5sb2coJTVDJTIySSdtJTIwdGhlJTIwbW9kZWwuJTVDJTIyKSUzQiU1Q24lNUN0JTdEJTVDbiU1Q24lN0QlNUNuJTVDbnZhciUyMG1vZCUyMCUzRCUyMG5ldyUyME1vZGVsKCklM0IlMjIlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyTW9kZWxCYXNlLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmNsYXNzJTIwTW9kZWwlMjAlN0IlNUNuJTVDbiU1Q3Rjb25zdHJ1Y3RvcigpJTIwJTdCJTVDbiU1Q3QlNUN0Y29uc29sZS5sb2coJTVDJTIySSdtJTIwdGhlJTIwbW9kZWwlMjBiYXNlLiU1QyUyMiklM0IlNUNuJTVDdCU3RCU1Q24lNUNuJTdEJTVDbiU1Q25leHBvcnQlMjBkZWZhdWx0JTIwTW9kZWwlM0IlMjIlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyY2pzJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=

Thanks for posting, it seems this is an edge case of #2025 where for some mysterious reason the JS spec has decided that the class name itself exists supersedes in the super expression scope even if it is a class expression.

The fix here will likely be to explicitly check if the class name itself is used as a non-deshadowed binding in the super expression and then to skip this renaming trick in that case!

//cc @NaridaL

@lukastaegert
Copy link
Member

lukastaegert commented Mar 12, 2018

The fix here will likely be to explicitly check if the class name itself is used as a non-deshadowed binding in the super expression and then to skip this renaming tr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WUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

I guess we will need to find a way to mark the class id as used when deshadowing variables.

@guybedford
Copy link
Contributor

Ahh, right that is definitely a problem then as these deshadowing cases all effectively invalidate the optimization.

I think we should revert #2025 then at least until a new approach can be found.

mikebolt added a commit to mikebolt/angular that referenced this issue Jan 13, 2020
…pression names

remove unnecessary underscore suffix and the corresponding TODO comments,
because the rollup bug was fixed: github.com/rollup/rollup/issues/2047
matsko pushed a commit to angular/angular that referenced this issue Jan 16, 2020
…pression names (#34757)

remove unnecessary underscore suffix and the corresponding TODO comments,
because the rollup bug was fixed: github.com/rollup/rollup/issues/2047

PR Close #34757
matsko pushed a commit to angular/angular that referenced this issue Jan 16, 2020
…pression names (#34757)

remove unnecessary underscore suffix and the corresponding TODO comments,
because the rollup bug was fixed: github.com/rollup/rollup/issues/2047

PR Close #34757
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.

3 participants