Skip to content

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

@yyx990803

Description

@yyx990803

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions