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
Use ?. where it represents the intended semantics #11512
Conversation
filename, | ||
}; | ||
} | ||
const options = { ...opts, filename }; |
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.
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; |
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.
Here I left null
for the prop !== "start"
case.
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) { |
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.
Here typeof
is still necessary in case window
isn't defined.
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:
|
FYI there is a codemod: https://github.com/NullVoxPopuli/optional-chaining-codemod |
I love writing regexps! 😛 |
Nice! We should try to make some codemods for all proposals if possible! |
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 ofnull
.