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

Handle out-of-order binding of identifiers to improve tree-shaking #2803

Merged
merged 1 commit into from Apr 10, 2019

Conversation

lukastaegert
Copy link
Member

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:
Resolves #2799

Description

It is possible that Rollup needs to analyze values of identifiers before they have been bound to their variables, which can cause in sub-optimal tree-shaking results. This is fixed here by allowing out-of-order binding of identifiers if their value is needed earlier. This allows for the following:

// input
export const test = () => {
	console.log(foo());
	console.log(bar());
};

const foo = () => {
	return BUILD ? A : B;
};

const bar = () => {
	return getBuild() ? A : B;
};

const getBuild = () => BUILD;

const BUILD = true;

// output
const test = () => {
	console.log(foo());
	console.log(bar());
};

const foo = () => {
	return A;
};

const bar = () => {
	return A;
};

export { test };

@lukastaegert lukastaegert merged commit c3d73ff into master Apr 10, 2019
@lukastaegert lukastaegert deleted the gh-2799-improve-return-expression-evaluation branch April 10, 2019 06:58
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.

Dead-code removal not working on return expressions
1 participant