Use ?. where it represents the intended semantics (#11512)
This commit is contained in:
@@ -44,7 +44,7 @@ export default class Buffer {
|
||||
// source string since it may be arbitrarily large after all transformations
|
||||
code: this._buf.join("").trimRight(),
|
||||
map: null,
|
||||
rawMappings: map && map.getRawMappings(),
|
||||
rawMappings: map?.getRawMappings(),
|
||||
};
|
||||
|
||||
if (map) {
|
||||
@@ -315,10 +315,10 @@ export default class Buffer {
|
||||
const origFilename = targetObj.filename;
|
||||
|
||||
targetObj.identifierName =
|
||||
(prop === "start" && loc && loc.identifierName) || null;
|
||||
targetObj.line = pos ? pos.line : null;
|
||||
targetObj.column = pos ? pos.column : null;
|
||||
targetObj.filename = (loc && loc.filename) || null;
|
||||
(prop === "start" && loc?.identifierName) || null;
|
||||
targetObj.line = pos?.line;
|
||||
targetObj.column = pos?.column;
|
||||
targetObj.filename = loc?.filename;
|
||||
|
||||
// We want to skip reassigning `force` if we're re-setting the same position.
|
||||
if (
|
||||
|
||||
@@ -21,7 +21,7 @@ export function BlockStatement(node: Object) {
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
|
||||
const hasDirectives = node.directives && node.directives.length;
|
||||
const hasDirectives = node.directives?.length;
|
||||
|
||||
if (node.body.length || hasDirectives) {
|
||||
this.newline();
|
||||
|
||||
@@ -147,7 +147,7 @@ export function ImportDeclaration(node: Object) {
|
||||
}
|
||||
|
||||
const specifiers = node.specifiers.slice(0);
|
||||
if (specifiers && specifiers.length) {
|
||||
if (specifiers?.length) {
|
||||
// print "special" specifiers first
|
||||
for (;;) {
|
||||
const first = specifiers[0];
|
||||
|
||||
@@ -196,10 +196,7 @@ nodes.ObjectTypeCallProperty = function(
|
||||
node: Object,
|
||||
parent,
|
||||
): ?WhitespaceObject {
|
||||
if (
|
||||
parent.callProperties[0] === node &&
|
||||
(!parent.properties || !parent.properties.length)
|
||||
) {
|
||||
if (parent.callProperties[0] === node && !parent.properties?.length) {
|
||||
return {
|
||||
before: true,
|
||||
};
|
||||
@@ -209,8 +206,8 @@ nodes.ObjectTypeCallProperty = function(
|
||||
nodes.ObjectTypeIndexer = function(node: Object, parent): ?WhitespaceObject {
|
||||
if (
|
||||
parent.indexers[0] === node &&
|
||||
(!parent.properties || !parent.properties.length) &&
|
||||
(!parent.callProperties || !parent.callProperties.length)
|
||||
!parent.properties?.length &&
|
||||
!parent.callProperties?.length
|
||||
) {
|
||||
return {
|
||||
before: true,
|
||||
@@ -224,9 +221,9 @@ nodes.ObjectTypeInternalSlot = function(
|
||||
): ?WhitespaceObject {
|
||||
if (
|
||||
parent.internalSlots[0] === node &&
|
||||
(!parent.properties || !parent.properties.length) &&
|
||||
(!parent.callProperties || !parent.callProperties.length) &&
|
||||
(!parent.indexers || !parent.indexers.length)
|
||||
!parent.properties?.length &&
|
||||
!parent.callProperties?.length &&
|
||||
!parent.indexers?.length
|
||||
) {
|
||||
return {
|
||||
before: true,
|
||||
|
||||
@@ -310,7 +310,7 @@ export default class Printer {
|
||||
|
||||
// catch up to this nodes newline if we're behind
|
||||
const pos = loc ? loc[prop] : null;
|
||||
if (pos && pos.line !== null) {
|
||||
if (pos?.line != null) {
|
||||
const count = pos.line - this._buf.getCurrentLine();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
@@ -360,7 +360,7 @@ export default class Printer {
|
||||
|
||||
endTerminatorless(state: Object) {
|
||||
this._noLineTerminator = false;
|
||||
if (state && state.printed) {
|
||||
if (state?.printed) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token(")");
|
||||
@@ -380,7 +380,7 @@ export default class Printer {
|
||||
throw new ReferenceError(
|
||||
`unknown node of type ${JSON.stringify(
|
||||
node.type,
|
||||
)} with constructor ${JSON.stringify(node && node.constructor.name)}`,
|
||||
)} with constructor ${JSON.stringify(node?.constructor.name)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ export default class Printer {
|
||||
}
|
||||
|
||||
printJoin(nodes: ?Array, parent: Object, opts = {}) {
|
||||
if (!nodes || !nodes.length) return;
|
||||
if (!nodes?.length) return;
|
||||
|
||||
if (opts.indent) this.indent();
|
||||
|
||||
@@ -523,7 +523,7 @@ export default class Printer {
|
||||
}
|
||||
|
||||
printInnerComments(node, indent = true) {
|
||||
if (!node.innerComments || !node.innerComments.length) return;
|
||||
if (!node.innerComments?.length) return;
|
||||
if (indent) this.indent();
|
||||
this._printComments(node.innerComments);
|
||||
if (indent) this.dedent();
|
||||
@@ -606,7 +606,7 @@ export default class Printer {
|
||||
: `/*${comment.value}*/`;
|
||||
|
||||
if (isBlockComment && this.format.indent.adjustMultilineComment) {
|
||||
const offset = comment.loc && comment.loc.start.column;
|
||||
const offset = comment.loc?.start.column;
|
||||
if (offset) {
|
||||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
@@ -630,7 +630,7 @@ export default class Printer {
|
||||
}
|
||||
|
||||
_printComments(comments?: Array<Object>, inlinePureAnnotation?: boolean) {
|
||||
if (!comments || !comments.length) return;
|
||||
if (!comments?.length) return;
|
||||
|
||||
if (
|
||||
inlinePureAnnotation &&
|
||||
|
||||
Reference in New Issue
Block a user