From 790c8ee9dbe2850e06937d07cae7b2d9432c5a7d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Dec 2020 08:39:23 +0800 Subject: [PATCH] Replace `normalizeParts` with safer `cleanDoc` (#9844) --- src/language-js/print/binaryish.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index 4caa4725f..22fb959b2 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -4,7 +4,7 @@ const { printComments } = require("../../main/comments"); const { getLast } = require("../../common/util"); const { builders: { concat, join, line, softline, group, indent, align, ifBreak }, - utils: { normalizeParts }, + utils: { cleanDoc }, } = require("../../document"); const { hasLeadingOwnLineComment, @@ -271,9 +271,15 @@ function printBinaryishExpressions( // the other ones since we don't call the normal print on BinaryExpression, // only for the left and right parts if (isNested && hasComment(node)) { - parts = normalizeParts( - printComments(path, () => concat(parts), options).parts + const printed = cleanDoc( + printComments(path, () => concat(parts), options) ); + /* istanbul ignore if */ + if (printed.type === "string") { + parts = [printed]; + } else { + parts = printed.parts; + } } } else { // Our stopping case. Simply print the node normally.