Use ?. where it represents the intended semantics (#11512)

This commit is contained in:
Nicolò Ribaudo
2020-05-09 23:31:50 +02:00
committed by GitHub
parent aeb51f463c
commit 31b361b736
47 changed files with 99 additions and 118 deletions

View File

@@ -236,7 +236,7 @@ export function setup(parentPath, container, listKey, key) {
export function setKey(key) {
this.key = key;
this.node = this.container[this.key];
this.type = this.node && this.node.type;
this.type = this.node?.type;
}
export function requeue(pathToQueue = this) {

View File

@@ -170,7 +170,7 @@ function hoistFunctionEnvironment(
p.isClassProperty({ static: false })
);
});
const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
const inConstructor = thisEnvFn?.node.kind === "constructor";
if (thisEnvFn.isClassProperty()) {
throw fnPath.buildCodeFrameError(

View File

@@ -160,7 +160,7 @@ function _evaluate(path, state) {
return deopt(binding.path, state);
}
if (binding && binding.hasValue) {
if (binding?.hasValue) {
return binding.value;
} else {
if (node.name === "undefined") {

View File

@@ -53,7 +53,7 @@ export function _getTypeAnnotation(): ?Object {
}
inferer = inferers[this.parentPath.type];
if (inferer && inferer.validParent) {
if (inferer?.validParent) {
return this.parentPath.getTypeAnnotation();
}
}

View File

@@ -10,7 +10,7 @@ export function VariableDeclarator() {
let type = init.getTypeAnnotation();
if (type && type.type === "AnyTypeAnnotation") {
if (type?.type === "AnyTypeAnnotation") {
// Detect "var foo = Array()" calls so we can optimize for arrays vs iterables.
if (
init.isCallExpression() &&

View File

@@ -7,7 +7,7 @@ export function remove() {
this._assertUnremoved();
this.resync();
if (!this.opts || !this.opts.noScope) {
if (!this.opts?.noScope) {
this._removeFromScope();
}

View File

@@ -196,7 +196,7 @@ export function _replaceWith(node) {
t.validate(this.parent, this.key, node);
}
this.debug(`Replace with ${node && node.type}`);
this.debug(`Replace with ${node?.type}`);
this.node = this.container[this.key] = node;
}
@@ -217,7 +217,7 @@ export function replaceExpressionWithStatements(nodes: Array<Object>) {
}
const functionParent = this.getFunctionParent();
const isParentAsync = functionParent && functionParent.is("async");
const isParentAsync = functionParent?.is("async");
const container = t.arrowFunctionExpression([], t.blockStatement(nodes));