From 334609d81eeb3b8d82be4234c39fae33b772ee6f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Dec 2020 12:09:55 +0800 Subject: [PATCH] Fix `comments.js` import style (#9917) --- src/language-js/print/call-arguments.js | 4 ++-- src/language-js/print/member-chain.js | 8 ++++---- src/language-js/printer-estree.js | 19 +++++-------------- src/main/ast-to-doc.js | 4 ++-- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index 24c8e9221..2dabfd8e1 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -1,6 +1,6 @@ "use strict"; -const comments = require("../../main/comments"); +const { printDanglingComments } = require("../../main/comments"); const { getLast, getPenultimate, @@ -43,7 +43,7 @@ function printCallArguments(path, options, print) { if (args.length === 0) { return concat([ "(", - comments.printDanglingComments(path, options, /* sameIndent */ true), + printDanglingComments(path, options, /* sameIndent */ true), ")", ]); } diff --git a/src/language-js/print/member-chain.js b/src/language-js/print/member-chain.js index 508595982..7669a87df 100644 --- a/src/language-js/print/member-chain.js +++ b/src/language-js/print/member-chain.js @@ -2,7 +2,7 @@ const flat = require("lodash/flatten"); -const comments = require("../../main/comments"); +const { printComments } = require("../../main/comments"); const { getLast, isNextLineEmpty, @@ -99,7 +99,7 @@ function printMemberChain(path, options, print) { printedNodes.unshift({ node, printed: concat([ - comments.printComments( + printComments( path, () => concat([ @@ -117,7 +117,7 @@ function printMemberChain(path, options, print) { printedNodes.unshift({ node, needsParens: pathNeedsParens(path, options), - printed: comments.printComments( + printed: printComments( path, () => node.type === "OptionalMemberExpression" || @@ -131,7 +131,7 @@ function printMemberChain(path, options, print) { } else if (node.type === "TSNonNullExpression") { printedNodes.unshift({ node, - printed: comments.printComments(path, () => "!", options), + printed: printComments(path, () => "!", options), }); path.call((expression) => rec(expression), "expression"); } else { diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 72ac8a3bf..fc392fbcd 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -6,7 +6,7 @@ const assert = require("assert"); // TODO(azz): anything that imports from main shouldn't be in a `language-*` dir. -const comments = require("../main/comments"); +const { printDanglingComments } = require("../main/comments"); const { hasNewline, printString, @@ -646,7 +646,7 @@ function printPathNoParens(path, options, print, args) { if (hasComment(n, CommentCheckFlags.Dangling)) { parts.push( - comments.printDanglingComments(path, options, true), + printDanglingComments(path, options, true), commentOnOwnLine ? hardline : " " ); } @@ -671,7 +671,7 @@ function printPathNoParens(path, options, print, args) { // We want to keep dangling comments above the loop to stay consistent. // Any comment positioned between the for statement and the parentheses // is going to be printed before the statement. - const dangling = comments.printDanglingComments( + const dangling = printDanglingComments( path, options, /* sameLine */ true @@ -985,12 +985,7 @@ function printPathNoParens(path, options, print, args) { if (n.members.length === 0 && !n.hasUnknownMembers) { parts.push( group( - concat([ - "{", - comments.printDanglingComments(path, options), - softline, - "}", - ]) + concat(["{", printDanglingComments(path, options), softline, "}"]) ) ); } else { @@ -1012,11 +1007,7 @@ function printPathNoParens(path, options, print, args) { ...(n.hasUnknownMembers ? [hardline, "..."] : []), ]) ), - comments.printDanglingComments( - path, - options, - /* sameIndent */ true - ), + printDanglingComments(path, options, /* sameIndent */ true), hardline, "}", ]) diff --git a/src/main/ast-to-doc.js b/src/main/ast-to-doc.js index ebf9471d5..712ef02dc 100644 --- a/src/main/ast-to-doc.js +++ b/src/main/ast-to-doc.js @@ -3,7 +3,7 @@ const assert = require("assert"); const FastPath = require("../common/fast-path"); const doc = require("../document"); -const comments = require("./comments"); +const { printComments } = require("./comments"); const multiparser = require("./multiparser"); const docBuilders = doc.builders; @@ -59,7 +59,7 @@ function printAstToDoc(ast, options, alignmentSize = 0) { } else { // printComments will call the plugin print function and check for // comments to print - res = comments.printComments( + res = printComments( path, (p) => callPluginPrintFunction(p, options, printGenerically, args), options,