From 024f51e5f8cdffc959dc29c3e4cbddd69058a0f3 Mon Sep 17 00:00:00 2001 From: Selvazhagan <38141381+selvazhagan@users.noreply.github.com> Date: Mon, 6 Jan 2020 11:00:09 -0800 Subject: [PATCH] =?UTF-8?q?Fixes=20:=20#5915=20HTML=20comments=20in=20pre?= =?UTF-8?q?=20tags=20causes=20bad=20formatting=20o=E2=80=A6=20(#5959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog_unreleased/html/pr-5959 | 24 +++++ src/language-html/utils.js | 2 + .../__snapshots__/jsfmt.spec.js.snap | 100 ++++++++++++++++++ tests/html_tags/pre.html | 9 ++ 4 files changed, 135 insertions(+) create mode 100644 changelog_unreleased/html/pr-5959 diff --git a/changelog_unreleased/html/pr-5959 b/changelog_unreleased/html/pr-5959 new file mode 100644 index 000000000..a55167123 --- /dev/null +++ b/changelog_unreleased/html/pr-5959 @@ -0,0 +1,24 @@ +#### Comments in `pre` tags caused bad formatting of following closing tag ([#5959](https://github.com/prettier/prettier/pull/5959) by [@selvazhagan](https://github.com/selvazhagan)) + + +``` + +
+
+    
+  
+ + +
+
+    
+  
+ + +
+
+    
+  
+
+``` diff --git a/src/language-html/utils.js b/src/language-html/utils.js index 0b7827312..8a9cab05c 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -194,6 +194,7 @@ function isLeadingSpaceSensitiveNode(node) { if ( !node.prev && (node.parent.type === "root" || + (isPreLikeNode(node) && node.parent) || isScriptLikeTag(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay)) ) { @@ -235,6 +236,7 @@ function isTrailingSpaceSensitiveNode(node) { if ( !node.next && (node.parent.type === "root" || + (isPreLikeNode(node) && node.parent) || isScriptLikeTag(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay)) ) { diff --git a/tests/html_tags/__snapshots__/jsfmt.spec.js.snap b/tests/html_tags/__snapshots__/jsfmt.spec.js.snap index 41f028cc1..7b9b5127e 100644 --- a/tests/html_tags/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_tags/__snapshots__/jsfmt.spec.js.snap @@ -806,6 +806,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -896,6 +905,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -986,6 +1006,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1100,6 +1129,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1189,6 +1229,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1271,6 +1320,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1362,6 +1422,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1452,6 +1521,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1543,6 +1623,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1633,6 +1722,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; diff --git a/tests/html_tags/pre.html b/tests/html_tags/pre.html index 6307de469..05b61de54 100644 --- a/tests/html_tags/pre.html +++ b/tests/html_tags/pre.html @@ -78,3 +78,12 @@ ___________________________

 
 
+ +
+

+  
+ +
+  
+
+