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

Side effects function calls in parameters are dropped #2922

Closed
manucorporat opened this issue Jun 11, 2019 · 3 comments · Fixed by #2924
Closed

Side effects function calls in parameters are dropped #2922

manucorporat opened this issue Jun 11, 2019 · 3 comments · Fixed by #2924

Comments

@manucorporat
Copy link
Contributor

manucorporat commented Jun 11, 2019

We have never reproduced this issue on the wild, but I thought it could be a problem after going though the rollup's code. Low priority.

  • Rollup Version: 1.14.6
  • Operating System (or Browser): browser
  • Node Version:

How Do We Reproduce?

https://rollupjs.org/repl?version=1.14.6&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMiU1Q25mdW5jdGlvbiUyMHNpZGVFZmZlY3RzKCklMjAlN0IlNUNuJTVDdGNvbnNvbGUubG9nKCdwcmludCUyMG1lc3NhZ2UnKSUzQiU1Q24lNUN0cmV0dXJuJTIwdHJ1ZSUzQiU1Q24lN0QlNUNuJTVDbmZ1bmN0aW9uJTIwaG9sYShhJTJDJTIwYiklMjAlN0IlNUNuJTVDdGNvbnNvbGUubG9nKGEpJTNCJTVDbiU3RCU1Q24lNUNuaG9sYSgxJTJDJTIwc2lkZUVmZmVjdHMoKSklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJjanMlMjIlMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==

Expected Behavior

It should not drop the call to sideEffects(), since it might have side effects, it's not safe to drop.
Giving this entry-point:

function sideEffects() {
	console.log('print message');
	return true;
}

function hola(a, b) {
	console.log(a);
}

hola(1, sideEffects());

it should emit:

function sideEffects() {
	console.log('print message');
	return true;
}

function hola(a, b) {
	console.log(a);
}

hola(1, sideEffects());

Actual Behavior

It drops the side effect function if the parameter is unused.

function hola(a, b) {
	console.log(a);
}

hola(1);

so the console.log() is never printed

@lukastaegert
Copy link
Member

Interesting, I distinctly remember having written code to prevent this. Will need to check again and add more tests.

@lukastaegert
Copy link
Member

Thanks again for finding this, the fix was indeed as simple as an if instead of an else if. And a missed test case. Fix at #2924

@manucorporat
Copy link
Contributor Author

Awesome job @lukastaegert ! you rock

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