]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix self-closing tags with v-pre
authorEvan You <yyx990803@gmail.com>
Mon, 19 Jul 2021 23:29:28 +0000 (19:29 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 19 Jul 2021 23:29:28 +0000 (19:29 -0400)
packages/compiler-core/__tests__/parse.spec.ts
packages/compiler-core/src/parse.ts

index dbc982b9c1e35dda89eef9d161bab27481e99239..0e839d26bc7d96c9813e8cdd7b717ab2d8ce8bbc 100644 (file)
@@ -1644,6 +1644,54 @@ describe('compiler: parse', () => {
       })
     })
 
+    test('self-closing v-pre', () => {
+      const ast = baseParse(
+        `<div v-pre/>\n<div :id="foo"><Comp/>{{ bar }}</div>`
+      )
+      // should not affect siblings after it
+      const divWithoutPre = ast.children[1] as ElementNode
+      expect(divWithoutPre.props).toMatchObject([
+        {
+          type: NodeTypes.DIRECTIVE,
+          name: `bind`,
+          arg: {
+            type: NodeTypes.SIMPLE_EXPRESSION,
+            isStatic: true,
+            content: `id`
+          },
+          exp: {
+            type: NodeTypes.SIMPLE_EXPRESSION,
+            isStatic: false,
+            content: `foo`
+          },
+          loc: {
+            source: `:id="foo"`,
+            start: {
+              line: 2,
+              column: 6
+            },
+            end: {
+              line: 2,
+              column: 15
+            }
+          }
+        }
+      ])
+      expect(divWithoutPre.children[0]).toMatchObject({
+        type: NodeTypes.ELEMENT,
+        tagType: ElementTypes.COMPONENT,
+        tag: `Comp`
+      })
+      expect(divWithoutPre.children[1]).toMatchObject({
+        type: NodeTypes.INTERPOLATION,
+        content: {
+          type: NodeTypes.SIMPLE_EXPRESSION,
+          content: `bar`,
+          isStatic: false
+        }
+      })
+    })
+
     test('end tags are case-insensitive.', () => {
       const ast = baseParse('<div>hello</DIV>after')
       const element = ast.children[0] as ElementNode
@@ -1884,6 +1932,15 @@ foo
       )
     })
 
+    it('self-closing pre tag', () => {
+      const ast = baseParse(`<pre/><span>\n  foo   bar</span>`, {
+        isPreTag: tag => tag === 'pre'
+      })
+      const elementAfterPre = ast.children[1] as ElementNode
+      // should not affect the <span> and condense its whitepsace inside
+      expect((elementAfterPre.children[0] as TextNode).content).toBe(` foo bar`)
+    })
+
     it('should NOT condense whitespaces in RCDATA text mode', () => {
       const ast = baseParse(`<textarea>Text:\n   foo</textarea>`, {
         getTextMode: ({ tag }) =>
index 47c6b4f7728ec07871499ff4bc5e13ab4e608d17..310766347e086a941ada7b8db471ce896680e253 100644 (file)
@@ -430,6 +430,9 @@ function parseElement(
     if (isPreBoundary) {
       context.inPre = false
     }
+    if (isVPreBoundary) {
+      context.inVPre = false
+    }
     return element
   }