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

Object literals in output causing syntax errors #3920

Closed
jbt opened this issue Jan 6, 2021 · 3 comments · Fixed by #3921
Closed

Object literals in output causing syntax errors #3920

jbt opened this issue Jan 6, 2021 · 3 comments · Fixed by #3921

Comments

@jbt
Copy link

jbt commented Jan 6, 2021

  • Rollup Version: 2.36.0
  • Operating System (or Browser): any
  • Node Version (if applicable):
  • Link to reproduction (IMPORTANT, read below): repl

I've started seeing non-tree-shakeable object literals appearing in my output as of 2.36.0 when the thing to which they were assigned is shaken away. But without the assignment, they're not interpreted as object literals and throw syntax errors.

Spotted this with .propTypes being applied to a React component as a default export which was being removed, but the prop types defintion was left in the output.

Seems to work fine with 2.35.1 so I guess it's related to #3919

repl link

Input:

export default function foo() {}

foo.propTypes = { foo: something() }

Expected Behavior

If foo gets tree-shaken then the non-tree-shakeable definition of propTypes shouldn't produce invalid output.

Actual Behavior

Output is just { foo: something() }; which on its own is invalid js because without the assignment it's not interpreted as an object literal

@lukastaegert
Copy link
Member

Thanks for spotting! This was definitely an oversight on my part as this is a variation of an issue we already solved for other similar optimizations. Fix at #3921, will release once CI is clear.

@jbt
Copy link
Author

jbt commented Jan 6, 2021

Amazing, nice one!

@jbt
Copy link
Author

jbt commented Jan 6, 2021

Just tested my case with 2.36.1 and working perfectly now! Appreciate the quick fix 🙌

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