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

Optional Chaining: Account for document.all #6525

Merged
merged 1 commit into from
Oct 21, 2017

Conversation

azz
Copy link
Member

@azz azz commented Oct 21, 2017

Q                       A
Fixed Issues?
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? 👍
Documentation PR
Any Dependency Changes?

Account for document.all with the optional-chaining operator.

Input:

foo?.bar;

Output - Before:

var _foo;

(_foo = foo) == null ? void 0 : _foo.bar;

Output - After:

var _foo;

(_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar;

This is spec-compliant as per 3.8.1 Runtime Semantics: Evaluation

  1. If baseValue is undefined or null, then
    Return undefined.

As this can generate a fair amount of code, and due to the rarity of document.all in practice, I've only made the change in spec mode.

NB: This will likely have merge conflicts with the files to be deleted in #6345 @jridgewell

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 21, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5438/

Copy link
Member

@Andarist Andarist left a comment

Choose a reason for hiding this comment

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

If we do it here only in spec mode, the same thing (introducing loose mode) imho should be done in babel-plugin-transform-nullish-coalescing-operator

@azz
Copy link
Member Author

azz commented Oct 21, 2017

Indeed. I can do that in a follow-up PR.

@Andarist
Copy link
Member

Sure, I didn't mean it should go into this one :)

@existentialism existentialism added Spec: Optional Chaining PR: Spec Compliance 👓 A type of pull request used for our changelog categories labels Oct 21, 2017
Copy link
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

Please add a loose test.

@nicolo-ribaudo
Copy link
Member

@jridgewell jridgewell merged commit 9e0f523 into babel:master Oct 21, 2017
@azz azz deleted the chaining-dda branch October 21, 2017 23:04
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 1, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Optional Chaining
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants