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

Provide an option to assume missing properties from object literals are undefined #584

Open
shicks opened this issue Mar 6, 2020 · 0 comments · May be fixed by #589
Open

Provide an option to assume missing properties from object literals are undefined #584

shicks opened this issue Mar 6, 2020 · 0 comments · May be fixed by #589
Labels
compress Issue in the compression step enhancement

Comments

@shicks
Copy link

shicks commented Mar 6, 2020

Bug report or Feature request?
Feature request

Version (complete output of terser -V or specific git commit)
4.6.6

Complete CLI command or minify() options used

terser -c --define process.env={} a.js

terser input

if (process.env.DEBUG) console.log('please remove');

terser output or error

({}).DEBUG&&console.log("please remove");

Expected result

void 0;

Discussion

The current behavior is correct from a conservative standpoint, because it's technically possible that Object.prototype.DEBUG has been defined. But given the exceedingly insignificant chance of this actually happening, it makes sense to provide the option to more aggressively inline the missing property as undefined, which would allow removing the log statement. Rollup actually does this by default already.

EDIT: clarified discussion slightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compress Issue in the compression step enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants