Avoid unnecessary print() in printStatementSequence (#14255)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-02-06 10:45:33 +08:00
1 parent 5d4380372e
commit bad0906a8d
1 file changed
+10 -12
+10 -12
View File
@@ -29,22 +29,20 @@ function printStatementSequence(path, options, print) {
return;
}
const printed = print();
const needsSemi =
!options.semi &&
!isTheOnlyJsxElementInMarkdown(options, path) &&
statementNeedsASIProtection(path, options);
// in no-semi mode, prepend statement with semicolon if it might break ASI
// don't prepend the only JSX element in a program with semicolon
if (
!options.semi &&
!isTheOnlyJsxElementInMarkdown(options, path) &&
statementNeedsASIProtection(path, options)
) {
if (hasComment(node, CommentCheckFlags.Leading)) {
parts.push(print([], { needsSemi: true }));
} else {
parts.push(";", printed);
}
if (needsSemi && hasComment(node, CommentCheckFlags.Leading)) {
parts.push(print([], { needsSemi: true }));
} else {
parts.push(printed);
if (needsSemi) {
parts.push(";");
}
parts.push(print());
}
if (node !== lastStatement) {