From 182a92eb281f866e53b8e2439ddab124bbe310ca Mon Sep 17 00:00:00 2001 From: Ika Date: Sat, 10 Nov 2018 16:44:44 +0800 Subject: [PATCH] fix(html): preserve incomplete ie conditional comment (#5429) --- src/language-html/parser-html.js | 25 ++++-- src/language-html/utils.js | 6 ++ .../__snapshots__/jsfmt.spec.js.snap | 83 +++++++++++++++++++ tests/html_comments/conditional.html | 8 ++ 4 files changed, 116 insertions(+), 6 deletions(-) diff --git a/src/language-html/parser-html.js b/src/language-html/parser-html.js index 2e5322ac4179..972088eb4954 100644 --- a/src/language-html/parser-html.js +++ b/src/language-html/parser-html.js @@ -256,19 +256,32 @@ function parseIeConditionalComment(node, parseHtml) { const [, openingTagSuffix, condition, data] = match; const offset = " + if (node.type === "ieConditionalComment" && !node.complete) { + return true; + } + // TODO: handle non-text children in
   if (
     isPreLikeNode(node) &&
diff --git a/tests/html_comments/__snapshots__/jsfmt.spec.js.snap b/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
index d34082746ecf..5e796d0c0f9c 100644
--- a/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
@@ -91,6 +91,14 @@ exports[`conditional.html - html-verify 1`] = `
   
   
 
+
+
+  
+ +
+ +
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -124,6 +132,14 @@ exports[`conditional.html - html-verify 1`] = ` + +
+ +
+ +
+ + `; exports[`conditional.html - html-verify 2`] = ` @@ -160,6 +176,14 @@ exports[`conditional.html - html-verify 2`] = ` + + +
+ +
+ +
+ ~ @@ -224,6 +248,17 @@ exports[`conditional.html - html-verify 2`] = ` + +
+ +
+ +
+ + `; exports[`conditional.html - html-verify 3`] = ` @@ -260,6 +295,14 @@ exports[`conditional.html - html-verify 3`] = ` + + +
+ +
+ +
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~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; exports[`conditional.html - html-verify 4`] = ` @@ -329,6 +380,14 @@ exports[`conditional.html - html-verify 4`] = ` + + +
+ +
+ +
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -362,6 +421,14 @@ exports[`conditional.html - html-verify 4`] = ` + +
+ +
+ +
+ + `; exports[`conditional.html - html-verify 5`] = ` @@ -398,6 +465,14 @@ exports[`conditional.html - html-verify 5`] = ` + + +
+ +
+ +
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -446,6 +521,14 @@ exports[`conditional.html - html-verify 5`] = ` + +
+ +
+ +
+ + `; exports[`for_debugging.html - html-verify 1`] = ` diff --git a/tests/html_comments/conditional.html b/tests/html_comments/conditional.html index a4e18e171ab8..14ae802cc3c5 100644 --- a/tests/html_comments/conditional.html +++ b/tests/html_comments/conditional.html @@ -31,3 +31,11 @@ + + +
+ +
+ +
+