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

Hoisting fixes (#2606) #2607

Merged
merged 1 commit into from Dec 23, 2018
Merged

Hoisting fixes (#2606) #2607

merged 1 commit into from Dec 23, 2018

Conversation

lye
Copy link
Contributor

@lye lye commented Dec 21, 2018

When hoisting a var, use UNKNOWN_EXPRESSION as the initializer instead
of the actual one. This prevents the initializer from being used during
the optimization step when it hasn't yet been assigned at runtime.

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

#2606

Description

The bug is described in #2606. I more-or-less copied the examples as new test cases.

I'm not able to run the watch tests on my FreeBSD box, but the rest of npm test runs without error post-patch. The codebase was kind of hard for me to follow so grains of salt.

The patch is also sub-optimal in that it prevents the optimizer from figuring out that hoisted variables from trimmed branches are falsy, but I couldn't work out a way to plumb that through.

When hoisting a var, use UNKNOWN_EXPRESSION as the initializer instead
of the actual one. This prevents the initializer from being used during
the optimization step when it hasn't yet been assigned at runtime.
@nifgraup
Copy link

nifgraup commented Dec 22, 2018

Confirming 5739cbd fixes the test case in #2606. (and that this test https://github.com/terser-js/terser/blob/master/test/compress/issue-2871.js passes when terser is bundled with rollup).

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot! I was afraid that such a fix might break tree-shaking optimizations in some places but apparently this was not the case as all tests remain green :)

@lukastaegert lukastaegert merged commit f8600a9 into rollup:master Dec 23, 2018
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 this pull request may close these issues.

None yet

3 participants