Use ?. where it represents the intended semantics (#11512)
This commit is contained in:
@@ -3,7 +3,7 @@ import isNode from "../validators/isNode";
|
||||
|
||||
export default function assertNode(node?: Object): void {
|
||||
if (!isNode(node)) {
|
||||
const type = (node && node.type) || JSON.stringify(node);
|
||||
const type = node?.type ?? JSON.stringify(node);
|
||||
throw new TypeError(`Not a valid node of type "${(type: any)}"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function toSequenceExpression(
|
||||
nodes: Array<Object>,
|
||||
scope: Scope,
|
||||
): ?Object {
|
||||
if (!nodes || !nodes.length) return;
|
||||
if (!nodes?.length) return;
|
||||
|
||||
const declars = [];
|
||||
const result = gatherSequenceExpressions(nodes, scope, declars);
|
||||
|
||||
@@ -18,7 +18,7 @@ export const PLACEHOLDERS_ALIAS: { [string]: Array<string> } = {
|
||||
|
||||
for (const type of PLACEHOLDERS) {
|
||||
const alias = ALIAS_KEYS[type];
|
||||
if (alias && alias.length) PLACEHOLDERS_ALIAS[type] = alias;
|
||||
if (alias?.length) PLACEHOLDERS_ALIAS[type] = alias;
|
||||
}
|
||||
|
||||
export const PLACEHOLDERS_FLIPPED_ALIAS: { [string]: Array<string> } = {};
|
||||
|
||||
@@ -110,7 +110,7 @@ export function assertNodeType(...types: Array<string>): Validator {
|
||||
node.type
|
||||
} expected node to be of a type ${JSON.stringify(
|
||||
types,
|
||||
)} but instead got ${JSON.stringify(val && val.type)}`,
|
||||
)} but instead got ${JSON.stringify(val?.type)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ export function assertNodeOrValueType(...types: Array<string>): Validator {
|
||||
node.type
|
||||
} expected node to be of a type ${JSON.stringify(
|
||||
types,
|
||||
)} but instead got ${JSON.stringify(val && val.type)}`,
|
||||
)} but instead got ${JSON.stringify(val?.type)}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,7 @@ export default function isNodesEquivalent(a: any, b: any): boolean {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof a[field] === "object" &&
|
||||
(!visitorKeys || !visitorKeys.includes(field))
|
||||
) {
|
||||
if (typeof a[field] === "object" && !visitorKeys?.includes(field)) {
|
||||
for (const key of Object.keys(a[field])) {
|
||||
if (a[field][key] !== b[field][key]) {
|
||||
return false;
|
||||
|
||||
@@ -18,7 +18,7 @@ export function validateField(
|
||||
val: any,
|
||||
field: any,
|
||||
): void {
|
||||
if (!field || !field.validate) return;
|
||||
if (!field?.validate) return;
|
||||
if (field.optional && val == null) return;
|
||||
|
||||
field.validate(node, key, val);
|
||||
|
||||
Reference in New Issue
Block a user