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

Compress more nullish checks into nullish coalescing #985

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jridgewell
Copy link
Collaborator

This adds support for foo != null ? foo : bar (and the respective !== checks). This is particularly important because Babel outputs this form of nullish coalescing.

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 === "!=")
) {
Copy link
Collaborator

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);
Copy link
Collaborator

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
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fabiosantoscode
Copy link
Collaborator

fabiosantoscode commented May 16, 2021

I'm confused as to why the functional tests don't run. Maybe there's a test in react that uses document.all? 🤔

@jridgewell
Copy link
Collaborator Author

I don't think it's document.all, I think whatever is running it can't parse a ?? operator. Now that we're transforming more expressions into ??, it's hitting an error.

@fabiosantoscode
Copy link
Collaborator

fabiosantoscode commented Jun 3, 2021

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).

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

Successfully merging this pull request may close these issues.

None yet

2 participants