From 39d45c009eeefc9599443d1f86c5f02f6f886823 Mon Sep 17 00:00:00 2001
From: Ika
Date: Wed, 14 Nov 2018 11:53:04 +0800
Subject: [PATCH 1/7] refactor
---
src/language-html/conditional-comment.js | 49 ++++++++++++++++++++++++
src/language-html/parser-html.js | 45 +---------------------
2 files changed, 50 insertions(+), 44 deletions(-)
create mode 100644 src/language-html/conditional-comment.js
diff --git a/src/language-html/conditional-comment.js b/src/language-html/conditional-comment.js
new file mode 100644
index 000000000000..f2fafff469dc
--- /dev/null
+++ b/src/language-html/conditional-comment.js
@@ -0,0 +1,49 @@
+"use strict";
+
+function parseIeConditionalComment(node, parseHtml) {
+ if (!node.value) {
+ return null;
+ }
+
+ const match = node.value.match(
+ /^(\[if([^\]]*?)\]>)([\s\S]*?) {
+ try {
+ return [true, parseHtml(data, contentStartSpan).children];
+ } catch (e) {
+ const text = {
+ type: "text",
+ value: data,
+ sourceSpan: new ParseSourceSpan(contentStartSpan, contentEndSpan)
+ };
+ return [false, [text]];
+ }
+ })();
+ return {
+ type: "ieConditionalComment",
+ complete,
+ children,
+ condition: condition.trim().replace(/\s+/g, " "),
+ sourceSpan: node.sourceSpan,
+ startSourceSpan: new ParseSourceSpan(
+ node.sourceSpan.start,
+ contentStartSpan
+ ),
+ endSourceSpan: new ParseSourceSpan(contentEndSpan, node.sourceSpan.end)
+ };
+}
+
+module.exports = {
+ parseIeConditionalComment
+};
diff --git a/src/language-html/parser-html.js b/src/language-html/parser-html.js
index 972088eb4954..cfdcf09ed488 100644
--- a/src/language-html/parser-html.js
+++ b/src/language-html/parser-html.js
@@ -5,6 +5,7 @@ const { HTML_ELEMENT_ATTRIBUTES, HTML_TAGS } = require("./utils");
const { hasPragma } = require("./pragma");
const createError = require("../common/parser-create-error");
const { Node } = require("./ast");
+const { parseIeConditionalComment } = require("./conditional-comment");
function ngHtmlParser(input, canSelfClose) {
const parser = require("angular-html-parser");
@@ -240,50 +241,6 @@ function _parse(
});
}
-function parseIeConditionalComment(node, parseHtml) {
- if (!node.value) {
- return null;
- }
-
- const match = node.value.match(
- /^(\[if([^\]]*?)\]>)([\s\S]*?) {
- try {
- return [true, parseHtml(data, contentStartSpan).children];
- } catch (e) {
- const text = {
- type: "text",
- value: data,
- sourceSpan: new ParseSourceSpan(contentStartSpan, contentEndSpan)
- };
- return [false, [text]];
- }
- })();
- return {
- type: "ieConditionalComment",
- complete,
- children,
- condition: condition.trim().replace(/\s+/g, " "),
- sourceSpan: node.sourceSpan,
- startSourceSpan: new ParseSourceSpan(
- node.sourceSpan.start,
- contentStartSpan
- ),
- endSourceSpan: new ParseSourceSpan(contentEndSpan, node.sourceSpan.end)
- };
-}
-
function locStart(node) {
return node.sourceSpan.start.offset;
}
From 757010b2b25b95ce2e8dc74a1d43cd4f187bd135 Mon Sep 17 00:00:00 2001
From: Ika
Date: Wed, 14 Nov 2018 12:31:05 +0800
Subject: [PATCH 2/7] test: add tests
---
.../__snapshots__/jsfmt.spec.js.snap | 259 ++++++++++++++++++
tests/html_comments/conditional.html | 21 ++
2 files changed, 280 insertions(+)
diff --git a/tests/html_comments/__snapshots__/jsfmt.spec.js.snap b/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
index 5e796d0c0f9c..3263ed0f4827 100644
--- a/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/html_comments/__snapshots__/jsfmt.spec.js.snap
@@ -99,6 +99,27 @@ exports[`conditional.html - html-verify 1`] = `