You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
按照上面的流程解析这个模板字符串时,当解析到结束标签`</p>`时,此时栈顶的标签应该是`p`才对,而现在是`span`,那么就说明`span`标签没有被正确闭合,此时控制台就会抛出警告:‘tag has no matching end tag.’相信这个警告你一定不会陌生。这就是栈的第二个用途: 检测模板字符串中是否有未正确闭合的标签。
671
+
按照上面的流程解析这个模板字符串时,当解析到结束标签`</p>`时,此时栈顶的标签应该是`p`才对,而现在是`span`,那么就说明`span`标签没有被正确闭合,此时控制台就会抛出警告:‘tag has no matching end tag.’相信这个警告你一定不会陌生。这就是栈的第二个用途: 检测模板字符串中是否有未正确闭合的标签。
668
672
669
673
OK,有了这个栈的概念之后,我们再回看上一章`HTML`解析器解析不同内容的代码。
670
674
@@ -701,28 +705,28 @@ function parseHTML(html, options) {
701
705
if (textEnd ===0) {
702
706
// 解析是否是注释
703
707
if (comment.test(html)) {
704
-
708
+
705
709
}
706
710
// 解析是否是条件注释
707
711
if (conditionalComment.test(html)) {
708
-
712
+
709
713
}
710
714
// 解析是否是DOCTYPE
711
715
constdoctypeMatch=html.match(doctype)
712
716
if (doctypeMatch) {
713
-
717
+
714
718
}
715
719
// 解析是否是结束标签
716
720
constendTagMatch=html.match(endTag)
717
721
if (endTagMatch) {
718
-
722
+
719
723
}
720
724
// 匹配是否是开始标签
721
725
conststartTagMatch=parseStartTag()
722
726
if (startTagMatch) {
723
-
727
+
724
728
}
725
-
}
729
+
}
726
730
// 如果html字符串不是以'<'开头,则解析文本类型
727
731
let text, rest, next
728
732
if (textEnd >=0) {
@@ -755,15 +759,15 @@ function parseHTML(html, options) {
0 commit comments