Use ?. where it represents the intended semantics (#11512)
This commit is contained in:
@@ -31,7 +31,7 @@ export default class TraversalContext {
|
||||
|
||||
// check if we're going to traverse into this node
|
||||
const keys: ?Array<string> = t.VISITOR_KEYS[node.type];
|
||||
if (!keys || !keys.length) return false;
|
||||
if (!keys?.length) return false;
|
||||
|
||||
// we need to traverse into this node so ensure that it has children to traverse into!
|
||||
for (const key of keys) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -53,7 +53,7 @@ export function _getTypeAnnotation(): ?Object {
|
||||
}
|
||||
|
||||
inferer = inferers[this.parentPath.type];
|
||||
if (inferer && inferer.validParent) {
|
||||
if (inferer?.validParent) {
|
||||
return this.parentPath.getTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() &&
|
||||
|
||||
@@ -7,7 +7,7 @@ export function remove() {
|
||||
this._assertUnremoved();
|
||||
|
||||
this.resync();
|
||||
if (!this.opts || !this.opts.noScope) {
|
||||
if (!this.opts?.noScope) {
|
||||
this._removeFromScope();
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ export default class Scope {
|
||||
const cached = scopeCache.get(node);
|
||||
// Sometimes, a scopable path is placed higher in the AST tree.
|
||||
// In these cases, have to create a new Scope.
|
||||
if (cached && cached.path === path) {
|
||||
if (cached?.path === path) {
|
||||
return cached;
|
||||
}
|
||||
scopeCache.set(node, this);
|
||||
@@ -322,7 +322,7 @@ export default class Scope {
|
||||
|
||||
get parent() {
|
||||
const parent = this.path.findParent(p => p.isScope());
|
||||
return parent && parent.scope;
|
||||
return parent?.scope;
|
||||
}
|
||||
|
||||
get parentBlock() {
|
||||
@@ -523,7 +523,7 @@ export default class Scope {
|
||||
toArray(node: Object, i?: number) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
if (binding && binding.constant && binding.path.isGenericType("Array")) {
|
||||
if (binding?.constant && binding.path.isGenericType("Array")) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -1014,13 +1014,12 @@ export default class Scope {
|
||||
}
|
||||
|
||||
getBindingIdentifier(name: string) {
|
||||
const info = this.getBinding(name);
|
||||
return info && info.identifier;
|
||||
return this.getBinding(name)?.identifier;
|
||||
}
|
||||
|
||||
getOwnBindingIdentifier(name: string) {
|
||||
const binding = this.bindings[name];
|
||||
return binding && binding.identifier;
|
||||
return binding?.identifier;
|
||||
}
|
||||
|
||||
hasOwnBinding(name: string) {
|
||||
@@ -1038,7 +1037,7 @@ export default class Scope {
|
||||
}
|
||||
|
||||
parentHasBinding(name: string, noGlobals?) {
|
||||
return this.parent && this.parent.hasBinding(name, noGlobals);
|
||||
return this.parent?.hasBinding(name, noGlobals);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1060,10 +1059,7 @@ export default class Scope {
|
||||
|
||||
removeBinding(name: string) {
|
||||
// clear literal binding
|
||||
const info = this.getBinding(name);
|
||||
if (info) {
|
||||
info.scope.removeOwnBinding(name);
|
||||
}
|
||||
this.getBinding(name)?.scope.removeOwnBinding(name);
|
||||
|
||||
// clear uids with this name - https://github.com/babel/babel/issues/2101
|
||||
let scope = this;
|
||||
|
||||
Reference in New Issue
Block a user