Use ?. where it represents the intended semantics (#11512)
This commit is contained in:
@@ -165,7 +165,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (name === "__proto__" && prop.kind === "init") {
|
||||
// Store the first redefinition's position
|
||||
if (protoRef.used) {
|
||||
if (refExpressionErrors && refExpressionErrors.doubleProto === -1) {
|
||||
if (refExpressionErrors?.doubleProto === -1) {
|
||||
refExpressionErrors.doubleProto = key.start;
|
||||
} else {
|
||||
this.raise(key.start, Errors.DuplicateProto);
|
||||
@@ -181,7 +181,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
stmt.type === "ExpressionStatement" &&
|
||||
stmt.expression.type === "Literal" &&
|
||||
typeof stmt.expression.value === "string" &&
|
||||
(!stmt.expression.extra || !stmt.expression.extra.parenthesized)
|
||||
!stmt.expression.extra?.parenthesized
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2198,7 +2198,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
): $ReadOnlyArray<N.Pattern> {
|
||||
for (let i = 0; i < exprList.length; i++) {
|
||||
const expr = exprList[i];
|
||||
if (expr && expr.type === "TypeCastExpression") {
|
||||
if (expr?.type === "TypeCastExpression") {
|
||||
exprList[i] = this.typeCastToParameter(expr);
|
||||
}
|
||||
}
|
||||
@@ -2216,7 +2216,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (
|
||||
expr &&
|
||||
expr.type === "TypeCastExpression" &&
|
||||
(!expr.extra || !expr.extra.parenthesized) &&
|
||||
!expr.extra?.parenthesized &&
|
||||
(exprList.length > 1 || !isParenthesizedExpr)
|
||||
) {
|
||||
this.raise(expr.typeAnnotation.start, FlowErrors.TypeCastInPattern);
|
||||
@@ -2665,7 +2665,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
}
|
||||
|
||||
if ((jsx && jsx.error) || this.isRelational("<")) {
|
||||
if (jsx?.error || this.isRelational("<")) {
|
||||
state = state || this.state.clone();
|
||||
|
||||
let typeParameters;
|
||||
@@ -2690,9 +2690,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}, state);
|
||||
|
||||
const arrowExpression: ?N.ArrowFunctionExpression =
|
||||
arrow.node && arrow.node.type === "ArrowFunctionExpression"
|
||||
? arrow.node
|
||||
: null;
|
||||
arrow.node?.type === "ArrowFunctionExpression" ? arrow.node : null;
|
||||
|
||||
if (!arrow.error && arrowExpression) return arrowExpression;
|
||||
|
||||
@@ -2702,7 +2700,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// If the error is recoverable, we can only re-report it if there is
|
||||
// a node we can return.
|
||||
|
||||
if (jsx && jsx.node) {
|
||||
if (jsx?.node) {
|
||||
/*:: invariant(jsx.failState) */
|
||||
this.state = jsx.failState;
|
||||
return jsx.node;
|
||||
@@ -2714,7 +2712,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return arrowExpression;
|
||||
}
|
||||
|
||||
if (jsx && jsx.thrown) throw jsx.error;
|
||||
if (jsx?.thrown) throw jsx.error;
|
||||
if (arrow.thrown) throw arrow.error;
|
||||
|
||||
/*:: invariant(typeParameters) */
|
||||
|
||||
@@ -261,7 +261,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
checkExport(node: N.ExportNamedDeclaration): void {
|
||||
const { specifiers } = node;
|
||||
if (specifiers && specifiers.length) {
|
||||
if (specifiers?.length) {
|
||||
node.specifiers = specifiers.filter(
|
||||
node => node.exported.type === "Placeholder",
|
||||
);
|
||||
|
||||
@@ -2340,7 +2340,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
}
|
||||
|
||||
if (!(jsx && jsx.error) && !this.isRelational("<")) {
|
||||
if (!jsx?.error && !this.isRelational("<")) {
|
||||
return super.parseMaybeAssign(...args);
|
||||
}
|
||||
|
||||
@@ -2362,7 +2362,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
// Correct TypeScript code should have at least 1 type parameter, but don't crash on bad code.
|
||||
if (typeParameters && typeParameters.params.length !== 0) {
|
||||
if (typeParameters?.params.length !== 0) {
|
||||
this.resetStartLocationFromNode(expr, typeParameters);
|
||||
}
|
||||
expr.typeParameters = typeParameters;
|
||||
@@ -2384,7 +2384,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (!typeCast.error) return typeCast.node;
|
||||
}
|
||||
|
||||
if (jsx && jsx.node) {
|
||||
if (jsx?.node) {
|
||||
/*:: invariant(jsx.failState) */
|
||||
this.state = jsx.failState;
|
||||
return jsx.node;
|
||||
@@ -2396,17 +2396,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return arrow.node;
|
||||
}
|
||||
|
||||
if (typeCast && typeCast.node) {
|
||||
if (typeCast?.node) {
|
||||
/*:: invariant(typeCast.failState) */
|
||||
this.state = typeCast.failState;
|
||||
return typeCast.node;
|
||||
}
|
||||
|
||||
if (jsx && jsx.thrown) throw jsx.error;
|
||||
if (jsx?.thrown) throw jsx.error;
|
||||
if (arrow.thrown) throw arrow.error;
|
||||
if (typeCast && typeCast.thrown) throw typeCast.error;
|
||||
if (typeCast?.thrown) throw typeCast.error;
|
||||
|
||||
throw (jsx && jsx.error) || arrow.error || (typeCast && typeCast.error);
|
||||
throw jsx?.error || arrow.error || typeCast?.error;
|
||||
}
|
||||
|
||||
// Handle type assertions
|
||||
@@ -2616,7 +2616,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
): $ReadOnlyArray<?N.Expression> {
|
||||
for (let i = 0; i < exprList.length; i++) {
|
||||
const expr = exprList[i];
|
||||
if (expr && expr.type === "TSTypeCastExpression") {
|
||||
if (expr?.type === "TSTypeCastExpression") {
|
||||
this.raise(expr.start, TSErrors.UnexpectedTypeAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user