From f3305ff9fc55b21612cc2fe0e65adda74a8d6a9e Mon Sep 17 00:00:00 2001 From: Ben Baryo Date: Wed, 16 Oct 2024 19:05:08 +0300 Subject: [PATCH] Fix issue with comments being duplicated when replacing the root node --- src/arborist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arborist.js b/src/arborist.js index ef07b3d..dfd2a06 100644 --- a/src/arborist.js +++ b/src/arborist.js @@ -85,8 +85,8 @@ const Arborist = class { const leadingComments = rootNode.leadingComments || []; const trailingComments = rootNode.trailingComments || []; rootNode = rootNodeReplacement[1]; - if (leadingComments.length) rootNode.leadingComments = (rootNode.leadingComments || []).concat(leadingComments); - if (trailingComments.length) rootNode.trailingComments = (rootNode.trailingComments || []).concat(trailingComments); + if (leadingComments.length && rootNode.leadingComments !== leadingComments) rootNode.leadingComments = (rootNode.leadingComments || []).concat(leadingComments); + if (trailingComments.length && rootNode.trailingComments !== trailingComments) rootNode.trailingComments = (rootNode.trailingComments || []).concat(trailingComments); } else { for (const targetNodeId of this.markedForDeletion) { try {