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
Compress more nullish checks into nullish coalescing #985
base: master
Are you sure you want to change the base?
Conversation
This adds support for `foo != null ? foo : bar` (and the respective `!==` checks). This is particularly important because Babel outputs this form of nullish coalescing.
OR | ||
? !(cmp.operator === "===" || cmp.operator === "==") | ||
: !(cmp.operator === "!==" || cmp.operator === "!=") | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
left: alternative, | ||
right: consequent | ||
left: left, | ||
right: left == alternative ? consequent : alternative, | ||
}).optimize(compressor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess is_nullish_check could return the left and right hand side:
const nullish_check = get_nullish_check(condition, consequent, alternative, compressor);
if (nullish_check != null) { // very meta line here
const [left, right] = nullish_check
// create "??" expression using left and right
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I'm confused as to why the functional tests don't run. Maybe there's a test in react that uses document.all? 🤔 |
I don't think it's |
Oh, I think I know what it is then. What we're running the tests on is node 12 (one of the applications under test requires it). |
This adds support for
foo != null ? foo : bar
(and the respective!==
checks). This is particularly important because Babel outputs this form of nullish coalescing.