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

Dead-code removal not working on return expressions #2799

Closed
manucorporat opened this issue Apr 9, 2019 · 2 comments · Fixed by #2803
Closed

Dead-code removal not working on return expressions #2799

manucorporat opened this issue Apr 9, 2019 · 2 comments · Fixed by #2803

Comments

@manucorporat
Copy link
Contributor

manucorporat commented Apr 9, 2019

  • Rollup Version: 1.9.0
  • Operating System (or Browser): osx and browser

How Do We Reproduce?

I am not sure about the root of the problem, but we hit the issue when we try to treeshake part of the stencil's runtime using a object of constant booleans.

https://rollupjs.org/repl?version=1.9.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIwQlVJTEQlMjAlM0QlMjB0cnVlJTNCJTVDbiU1Q25leHBvcnQlMjBjb25zdCUyMGJhciUyMCUzRCUyMCgpJTIwJTNEJTNFJTIwJTdCJTVDbiUyMCUyMCUyMCUyMGNvbnNvbGUubG9nKGZvbygpKSUzQiU1Q24lN0QlM0IlNUNuJTVDbmNvbnN0JTIwZm9vJTIwJTNEJTIwKCklMjAlM0QlM0UlMjAlN0IlNUNuJTVDdHJldHVybiUyMEJVSUxEJTIwJTNGJTIwQSUyMCUzQSUyMEIlM0IlNUNuJTdEJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyZXNtJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyYW1kJTIyJTNBJTdCJTIyaWQlMjIlM0ElMjIlMjIlN0QlMkMlMjJnbG9iYWxzJTIyJTNBJTdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=

Replacing BUILD with true directly, removes the dead-code properly.

Expected Behavior

Input:

const BUILD = true;

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

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

Should generate

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

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

export { bar };

Actual Behavior

const BUILD = true;

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

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

export { bar };

The constant expression is not dropped

@manucorporat manucorporat changed the title Constant folding on return expressions Dead-code removal not working on return expressions Apr 9, 2019
@lukastaegert
Copy link
Member

For now this is an ordering issue. If you switch the order of the definitions of foo and bar, it will work correctly. Will check if there is a simple way of improving it without introducing a second bind pass...

@lukastaegert
Copy link
Member

The fix was surprisingly easy, see #2803

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

Successfully merging a pull request may close this issue.

2 participants