]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): avoid prefixing empty interpolations (#290)
authorHcySunYang <HcySunYang@outlook.com>
Tue, 15 Oct 2019 20:58:01 +0000 (04:58 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 15 Oct 2019 20:58:01 +0000 (16:58 -0400)
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/src/transforms/transformExpression.ts

index e4d6d24e10f20db1400d6b2db5de02b11894c681..3b2c70de7117b10e672c68876af1781128c8efb4 100644 (file)
@@ -32,6 +32,24 @@ describe('compiler: expression transform', () => {
     })
   })
 
+  test('empty interpolation', () => {
+    const node = parseWithExpressionTransform(`{{}}`) as InterpolationNode
+    const node2 = parseWithExpressionTransform(`{{ }}`) as InterpolationNode
+    const node3 = parseWithExpressionTransform(
+      `<div>{{ }}</div>`
+    ) as ElementNode
+
+    const objectToBeMatched = {
+      type: NodeTypes.SIMPLE_EXPRESSION,
+      content: ``
+    }
+    expect(node.content).toMatchObject(objectToBeMatched)
+    expect(node2.content).toMatchObject(objectToBeMatched)
+    expect((node3.children[0] as InterpolationNode).content).toMatchObject(
+      objectToBeMatched
+    )
+  })
+
   test('interpolation (children)', () => {
     const el = parseWithExpressionTransform(
       `<div>{{ foo }}</div>`
index 84bb35ef4d7bcf32dba03d96834f8c3d9d14be49..2894e33e6bb6878ebef32f419b6a64628c1d1a8c 100644 (file)
@@ -77,7 +77,7 @@ export function processExpression(
   // function params
   asParams: boolean = false
 ): ExpressionNode {
-  if (!context.prefixIdentifiers) {
+  if (!context.prefixIdentifiers || !node.content.trim()) {
     return node
   }