]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: pass all compiler-dom tests
authorEvan You <yyx990803@gmail.com>
Sun, 19 Nov 2023 03:46:44 +0000 (11:46 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/src/parser/Tokenizer.ts
packages/compiler-core/src/parser/index.ts

index fdbc84a10bb618169d0836ebf31904d7f9d8440a..d6fbba877680cb7f8e1532481056eda0b9bcdb9f 100644 (file)
@@ -238,6 +238,8 @@ export default class Tokenizer {
   private baseState = State.Text
   /** For special parsing behavior inside of script and style tags. */
   public inRCDATA = false
+  /** For disabling RCDATA tags handling */
+  public inXML = false
   /** Reocrd newline positions for fast line / column calculation */
   private newlines: number[] = []
 
@@ -528,7 +530,7 @@ export default class Tokenizer {
         // - everything except <template> is RAWTEXT
         // - <template> with lang other than html is also RAWTEXT
         this.state = State.InSFCRootTagName
-      } else {
+      } else if (!this.inXML) {
         // HTML mode
         // - <script>, <style> RAWTEXT
         // - <title>, <textarea> RCDATA
@@ -539,6 +541,8 @@ export default class Tokenizer {
           this.state =
             lower === 115 /* s */ ? State.BeforeSpecialS : State.InTagName
         }
+      } else {
+        this.state = State.InTagName
       }
     } else if (c === CharCodes.Slash) {
       this.state = State.BeforeClosingTagName
index 967dfc18738139e31d749c5ea173f9dc59672314..aabaaa0e51373ad0f50ecd4ae0c47b8b0ccf68b1 100644 (file)
@@ -406,14 +406,17 @@ function getSlice(start: number, end: number) {
 
 function endOpenTag(end: number) {
   addNode(currentElement!)
-  const name = currentElement!.tag
-  if (currentOptions.isPreTag(name)) {
+  const { tag, ns } = currentElement!
+  if (ns === Namespaces.HTML && currentOptions.isPreTag(tag)) {
     inPre++
   }
-  if (currentOptions.isVoidTag(name)) {
+  if (currentOptions.isVoidTag(tag)) {
     onCloseTag(currentElement!, end)
   } else {
     stack.unshift(currentElement!)
+    if (ns === Namespaces.SVG || ns === Namespaces.MATH_ML) {
+      tokenizer.inXML = true
+    }
   }
   currentElement = null
 }
@@ -458,7 +461,7 @@ function onCloseTag(el: ElementNode, end: number) {
   el.loc.end = tokenizer.getPos(end + offset + 1)
 
   // refine element type
-  const tag = el.tag
+  const { tag, ns } = el
   if (!inVPre) {
     if (tag === 'slot') {
       el.tagType = ElementTypes.SLOT
@@ -473,14 +476,19 @@ function onCloseTag(el: ElementNode, end: number) {
   if (!tokenizer.inRCDATA) {
     el.children = condenseWhitespace(el.children, el.tag)
   }
-
-  if (currentOptions.isPreTag(tag)) {
+  if (ns === Namespaces.HTML && currentOptions.isPreTag(tag)) {
     inPre--
   }
   if (currentVPreBoundary === el) {
     inVPre = false
     currentVPreBoundary = null
   }
+  if (
+    tokenizer.inXML &&
+    (stack[0] ? stack[0].ns : currentOptions.ns) === Namespaces.HTML
+  ) {
+    tokenizer.inXML = false
+  }
 }
 
 const specialTemplateDir = new Set(['if', 'else', 'else-if', 'for', 'slot'])