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

@@ -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)}"`);
}
}

View File

@@ -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);

View File

@@ -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> } = {};

View File

@@ -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)}`,
);
}

View File

@@ -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;

View File

@@ -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);