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

Handling known undefined properties #2222

Closed
guybedford opened this issue May 25, 2018 · 3 comments
Closed

Handling known undefined properties #2222

guybedford opened this issue May 25, 2018 · 3 comments

Comments

@guybedford
Copy link
Contributor

For cases like -

var a = {
	b: {
		c: 'd'
	}
};

if (a.b.d)
  console.log('yes');

surely we have all the analysis at this point to know that a.b.d is undefined and therefore falsy? Is this related to #2215?

@GrosSacASac
Copy link

Hi, I am curious , why does rollup need to analyze anything that is inside an if ? I thought rollup would only be concerned about finding top level import and export.

@lukastaegert
Copy link
Member

Rollup's tree-shaking has evolved quite a bit since then. Imagine a situation like this one:

import foo from 'foo.js';
import bar from 'bar.js';

function startup() {
  if (bar) foo();
}

startup();

Today, rollup can detect that if bar is always false, then foo will be tree-shaken even though its call is inside a function. It is a common misconception that tree-shaking has to do anything with top level ES module statements or ES modules at all. Incidentally, I recently held a talk explaining this: https://events.techcast.com/btd/2018/Garmisch_1130/

@GrosSacASac
Copy link

Interesting thank you very much.

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

No branches or pull requests

3 participants