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

Treeshaking of sequence expressions #1649

Closed
corneliusweig opened this issue Sep 24, 2017 · 0 comments · Fixed by #1650
Closed

Treeshaking of sequence expressions #1649

corneliusweig opened this issue Sep 24, 2017 · 0 comments · Fixed by #1650

Comments

@corneliusweig
Copy link
Contributor

Rollup does not know about the SequenceExpression AST node. This means that the following code is not tree-shaken at all:

// should remove expressions without side-effect
var a = (0,foo(),1,2);
var b = (0,foo());

// should remove variable without effect
var c = (1,2);

// should only keep final expression
var d = (1,2);
console.log(d);

// should infer value
if ((1, 2) !== 2) {
	console.log( 'effect' );
}

Even though it could be simplified to

// IMHO the final value should be retained in this case even though the variable is not used.
var a = (foo(), 2);
var b = foo();

var d = 2;
console.log(d);
corneliusweig pushed a commit to corneliusweig/rollup that referenced this issue Sep 24, 2017
Looks at each expression in the sequence and only retains the node if it has an effect.

Note: in sequence expressions with effects always keep the last node, to be consistent when assigning the resulting value to a variable.
corneliusweig pushed a commit to corneliusweig/rollup that referenced this issue Sep 24, 2017
corneliusweig pushed a commit to corneliusweig/rollup that referenced this issue Sep 24, 2017
Looks at each expression in the sequence and only retains the node if it has an effect.

Note: in sequence expressions with effects always keep the last node, to be consistent when assigning the resulting value to a variable.
corneliusweig pushed a commit to corneliusweig/rollup that referenced this issue Sep 24, 2017
corneliusweig pushed a commit to corneliusweig/rollup that referenced this issue Sep 29, 2017
Looks at each expression in the sequence and only retains the node if it has an effect.

Note: in sequence expressions with effects always keep the last node, to be consistent when assigning the resulting value to a variable.
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 a pull request may close this issue.

1 participant