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

Use ?. where it represents the intended semantics #11512

Merged
merged 5 commits into from May 9, 2020

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented May 2, 2020

Q                       A
License MIT

Let's test our ?. implementation in a real codebase! After #11500, it can be correctly type-checked by Flow.

I replaced this using a few regular expressions, to only replace && where on the right there was a property access, a method call, or a comparison.

Also, I noticed that ?. plays very bad with .indexOf() because it returns -1 instead of null.

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label May 2, 2020
filename,
};
}
const options = { ...opts, filename };
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't really related, but since opts can only be null or an object these two things have the same behavior.

targetObj.line = pos ? pos.line : null;
targetObj.column = pos ? pos.column : null;
targetObj.filename = (loc && loc.filename) || null;
(prop === "start" && loc?.identifierName) || null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I left null for the prop !== "start" case.

@babel-bot
Copy link
Collaborator

babel-bot commented May 2, 2020

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

@@ -207,7 +207,7 @@ function onDOMContentLoaded() {

// Listen for load event if we're in a browser and then kick off finding and
// running of scripts with "text/babel" type.
if (typeof window !== "undefined" && window && window.addEventListener) {
if (typeof window !== "undefined" && window?.addEventListener) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Here typeof is still necessary in case window isn't defined.

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 2, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f91fae6:

Sandbox Source
elastic-moon-jxqcb Configuration
elated-dan-s59sf Configuration

@nicolo-ribaudo nicolo-ribaudo marked this pull request as draft May 2, 2020 20:52
@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review May 2, 2020 20:56
@JLHwung
Copy link
Contributor

JLHwung commented May 2, 2020

FYI there is a codemod: https://github.com/NullVoxPopuli/optional-chaining-codemod

@nicolo-ribaudo
Copy link
Member Author

I love writing regexps! 😛

@hzoo
Copy link
Member

hzoo commented May 2, 2020

Nice! We should try to make some codemods for all proposals if possible!

@nicolo-ribaudo nicolo-ribaudo merged commit 31b361b into babel:master May 9, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the use-optional-chaining branch May 9, 2020 21:31
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2020
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: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants