Minor tweak to semicolon print (#18026)
This commit is contained in:
1 parent
0d1e7abd50
commit
274b249223
7 files changed
+28
-31
No files matched your search
@@ -225,7 +225,6 @@ function printClassMethod(path, options, print) {
|
||||
function printClassProperty(path, options, print) {
|
||||
const { node } = path;
|
||||
const parts = [];
|
||||
const semi = options.semi ? ";" : "";
|
||||
|
||||
if (isNonEmptyArray(node.decorators)) {
|
||||
parts.push(printClassMemberDecorators(path, options, print));
|
||||
@@ -275,7 +274,7 @@ function printClassProperty(path, options, print) {
|
||||
" =",
|
||||
isAbstractProperty ? undefined : "value",
|
||||
),
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ function printEstree(path, options, print, args) {
|
||||
return printLiteral(path, options);
|
||||
}
|
||||
|
||||
const semi = options.semi ? ";" : "";
|
||||
/** @type{Doc[]} */
|
||||
let parts = [];
|
||||
|
||||
@@ -304,7 +303,7 @@ function printEstree(path, options, print, args) {
|
||||
case "Super":
|
||||
return "super";
|
||||
case "Directive":
|
||||
return [print("value"), semi]; // Babel 6
|
||||
return [print("value"), options.semi ? ";" : ""];
|
||||
case "UnaryExpression":
|
||||
parts.push(node.operator);
|
||||
|
||||
@@ -366,8 +365,8 @@ function printEstree(path, options, print, args) {
|
||||
),
|
||||
];
|
||||
|
||||
if (!(isParentForLoop && parentNode.body !== node)) {
|
||||
parts.push(semi);
|
||||
if (options.semi && !(isParentForLoop && parentNode.body !== node)) {
|
||||
parts.push(";");
|
||||
}
|
||||
|
||||
return group(parts);
|
||||
@@ -499,7 +498,7 @@ function printEstree(path, options, print, args) {
|
||||
"while (",
|
||||
group([indent([softline, print("test")]), softline]),
|
||||
")",
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
);
|
||||
|
||||
return parts;
|
||||
@@ -514,7 +513,7 @@ function printEstree(path, options, print, args) {
|
||||
parts.push(" ", print("label"));
|
||||
}
|
||||
|
||||
parts.push(semi);
|
||||
parts.push(options.semi ? ";" : "");
|
||||
|
||||
return parts;
|
||||
case "LabeledStatement":
|
||||
@@ -612,7 +611,7 @@ function printEstree(path, options, print, args) {
|
||||
}
|
||||
// JSX extensions below.
|
||||
case "DebuggerStatement":
|
||||
return ["debugger", semi];
|
||||
return ["debugger", options.semi ? ";" : ""];
|
||||
|
||||
case "ClassDeclaration":
|
||||
case "ClassExpression":
|
||||
|
||||
@@ -64,8 +64,6 @@ function printFlow(path, options, print) {
|
||||
return node.type.slice(0, -14).toLowerCase();
|
||||
}
|
||||
|
||||
const semi = options.semi ? ";" : "";
|
||||
|
||||
switch (node.type) {
|
||||
case "ComponentDeclaration":
|
||||
case "DeclareComponent":
|
||||
@@ -89,7 +87,7 @@ function printFlow(path, options, print) {
|
||||
"function ",
|
||||
print("id"),
|
||||
print("predicate"),
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
];
|
||||
case "DeclareModule":
|
||||
return ["declare module ", print("id"), " ", print("body")];
|
||||
@@ -97,7 +95,7 @@ function printFlow(path, options, print) {
|
||||
return [
|
||||
"declare module.exports",
|
||||
printTypeAnnotationProperty(path, print),
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
];
|
||||
case "DeclareNamespace":
|
||||
return ["declare namespace ", print("id"), " ", print("body")];
|
||||
@@ -108,7 +106,7 @@ function printFlow(path, options, print) {
|
||||
node.kind ?? "var",
|
||||
" ",
|
||||
print("id"),
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
];
|
||||
case "DeclareExportDeclaration":
|
||||
case "DeclareExportAllDeclaration":
|
||||
|
||||
@@ -230,7 +230,6 @@ function printReturnType(path, print) {
|
||||
// `ReturnStatement` and `ThrowStatement`
|
||||
function printReturnOrThrowArgument(path, options, print) {
|
||||
const { node } = path;
|
||||
const semi = options.semi ? ";" : "";
|
||||
const parts = [];
|
||||
|
||||
if (node.argument) {
|
||||
@@ -258,20 +257,20 @@ function printReturnOrThrowArgument(path, options, print) {
|
||||
|
||||
const hasDanglingComments = hasComment(node, CommentCheckFlags.Dangling);
|
||||
const shouldPrintSemiBeforeComments =
|
||||
semi &&
|
||||
options.semi &&
|
||||
hasDanglingComments &&
|
||||
hasComment(node, CommentCheckFlags.Last | CommentCheckFlags.Line);
|
||||
|
||||
if (shouldPrintSemiBeforeComments) {
|
||||
parts.push(semi);
|
||||
parts.push(";");
|
||||
}
|
||||
|
||||
if (hasDanglingComments) {
|
||||
parts.push(" ", printDanglingComments(path, options));
|
||||
}
|
||||
|
||||
if (!shouldPrintSemiBeforeComments) {
|
||||
parts.push(semi);
|
||||
if (!shouldPrintSemiBeforeComments && options.semi) {
|
||||
parts.push(";");
|
||||
}
|
||||
|
||||
return parts;
|
||||
|
||||
@@ -27,7 +27,6 @@ import { printTypeAnnotationProperty } from "./type-annotation.js";
|
||||
/** @import {Doc} from "../../document/builders.js" */
|
||||
|
||||
function printObject(path, options, print) {
|
||||
const semi = options.semi ? ";" : "";
|
||||
const { node } = path;
|
||||
|
||||
const isTypeAnnotation = node.type === "ObjectTypeAnnotation";
|
||||
@@ -105,7 +104,9 @@ function printObject(path, options, print) {
|
||||
const separator = isFlowInterfaceLikeBody
|
||||
? ";"
|
||||
: node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral"
|
||||
? ifBreak(semi, ";")
|
||||
? options.semi
|
||||
? ";"
|
||||
: ifBreak("", ";")
|
||||
: ",";
|
||||
const leftBrace = node.exact ? "{|" : "{";
|
||||
const rightBrace = node.exact ? "|}" : "}";
|
||||
|
||||
@@ -82,7 +82,6 @@ function shouldHugType(node) {
|
||||
- `OpaqueType`(flow)
|
||||
*/
|
||||
function printOpaqueType(path, options, print) {
|
||||
const semi = options.semi ? ";" : "";
|
||||
const { node } = path;
|
||||
const parts = [
|
||||
printDeclareToken(path),
|
||||
@@ -114,7 +113,7 @@ function printOpaqueType(path, options, print) {
|
||||
parts.push(" = ", print("impltype"));
|
||||
}
|
||||
|
||||
parts.push(semi);
|
||||
parts.push(options.semi ? ";" : "");
|
||||
|
||||
return parts;
|
||||
}
|
||||
@@ -125,16 +124,19 @@ function printOpaqueType(path, options, print) {
|
||||
- `TSTypeAliasDeclaration`(TypeScript)
|
||||
*/
|
||||
function printTypeAlias(path, options, print) {
|
||||
const semi = options.semi ? ";" : "";
|
||||
const { node } = path;
|
||||
const parts = [printDeclareToken(path)];
|
||||
const parts = [
|
||||
printDeclareToken(path),
|
||||
"type ",
|
||||
print("id"),
|
||||
print("typeParameters"),
|
||||
];
|
||||
|
||||
parts.push("type ", print("id"), print("typeParameters"));
|
||||
const rightPropertyName =
|
||||
node.type === "TSTypeAliasDeclaration" ? "typeAnnotation" : "right";
|
||||
return [
|
||||
printAssignment(path, options, print, parts, " =", rightPropertyName),
|
||||
semi,
|
||||
options.semi ? ";" : "",
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ function printTypescript(path, options, print) {
|
||||
return node.type.slice(2, -7).toLowerCase();
|
||||
}
|
||||
|
||||
const semi = options.semi ? ";" : "";
|
||||
const parts = [];
|
||||
|
||||
switch (node.type) {
|
||||
@@ -109,7 +108,7 @@ function printTypescript(path, options, print) {
|
||||
case "TSDeclareFunction":
|
||||
return printFunction(path, options, print);
|
||||
case "TSExportAssignment":
|
||||
return ["export = ", print("expression"), semi];
|
||||
return ["export = ", print("expression"), options.semi ? ";" : ""];
|
||||
case "TSModuleBlock":
|
||||
return printBlock(path, options, print);
|
||||
case "TSInterfaceBody":
|
||||
@@ -199,7 +198,7 @@ function printTypescript(path, options, print) {
|
||||
node.parameters ? parametersGroup : "",
|
||||
"]",
|
||||
printTypeAnnotationProperty(path, print),
|
||||
isClassMember ? semi : "",
|
||||
isClassMember && options.semi ? ";" : "",
|
||||
];
|
||||
}
|
||||
case "TSTypePredicate":
|
||||
@@ -303,7 +302,7 @@ function printTypescript(path, options, print) {
|
||||
} else if (node.body) {
|
||||
parts.push(" ", group(print("body")));
|
||||
} else {
|
||||
parts.push(semi);
|
||||
parts.push(options.semi ? ";" : "");
|
||||
}
|
||||
|
||||
return parts;
|
||||
|
||||
Reference in new issue
Block a user