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

Tree-shaking: Destructuring assignment not recognised as side-effect #3984

Open
kachurun opened this issue Mar 3, 2021 · 3 comments
Open

Comments

@kachurun
Copy link

kachurun commented Mar 3, 2021

Expected Behavior

test() {
  this.a;	// Side-effects
  this.b; // SIde-effects
  this.c; // SIde-effects

  // return { a, b, c };
}

Actual Behavior

test() {
  this.a;	// Side-effects
  this.b; // SIde-effects
  
  // return { a, b, c };
}
@kachurun kachurun changed the title Destructuring assignment not recognised as side-effects Tree-shaking: Destructuring assignment not recognised as side-effect Mar 3, 2021
@kzc
Copy link
Contributor

kzc commented Mar 3, 2021

related bug: #2219

@kzc
Copy link
Contributor

kzc commented Mar 3, 2021

fwiw, Removing the getters for a and b produces the same code for the test method as the top post.

$ cat main.js
const obj = {
	get c() {
		console.log('side-effect C')
	},
	test() {
		this.a;
		const b = this.b
		const { c } = this
	}
}
obj.test()
$ cat main.js | rollup --silent
const obj = {
	get c() {
		console.log('side-effect C');
	},
	test() {
		this.a;
		this.b;
	}
};
obj.test();

@kzc
Copy link
Contributor

kzc commented Mar 9, 2021

--treeshake.propertyReadSideEffects=always can now be used as a workaround for tree shaking with getters with side effects.

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

No branches or pull requests

3 participants