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

Non-strict-mode-compliant codegen for entry with the name arguments containing mixed exports #4612

Closed
yyx990803 opened this issue Aug 18, 2022 · 1 comment · Fixed by #4613

Comments

@yyx990803
Copy link
Contributor

yyx990803 commented Aug 18, 2022

Rollup Version

2.78.0

Operating System (or Browser)

any

Node Version (if applicable)

any

Link To Reproduction

https://rollupjs.org/repl/?version=2.78.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGRlZmF1bHQlMjAlN0IlN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCUyQyU3QiUyMm5hbWUlMjIlM0ElMjJhcmd1bWVudHMuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwY29uc3QlMjBmb28lMjAlM0QlMjAxJTVDbmV4cG9ydCUyMGRlZmF1bHQlMjAlN0IlN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

Expected Behaviour

The generated code should be valid in strict mode (i.e. modules)

Actual Behaviour

When an entry file contains both named and default exports:

export const foo = 1
export default {}

Rollup rewrites them into a single export statement:

const foo = 1;
var arguments = {};

export { arguments as default, foo };

The default export value is assigned to a variable, which uses the file's name as its variable name. The variable name gets prefixed with _ for most keywords, but somehow arguments is missed, which is in fact invalid in strict mode / module context.

Actually, I don't see a reason why the temp variable needs to use the filename, maybe just use something like _default with conflict postfixes is simpler and safer.

@lukastaegert
Copy link
Member

Thanks for spotting, fix at #4613.

but somehow arguments is missed

turns out arguments is not a reserved word, which is what we were looking for, but it is a variable name with special logic attached to it...

Actually, I don't see a reason why the temp variable needs to use the filename, maybe just use something like _default with conflict postfixes is simpler and safer.

There are other situations where those names are helpful and it avoids having a dozen _default with attached numbers in the generated code where it is not clear where they came from.

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