Skip to content

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

Merged
lukastaegert merged 1 commit intomasterfrom
gh-2799-improve-return-expression-evaluation
Apr 10, 2019
Merged

Handle out-of-order binding of identifiers to improve tree-shaking#2803
lukastaegert merged 1 commit intomasterfrom
gh-2799-improve-return-expression-evaluation

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