]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix property shorthand detection
authorEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 14:27:03 +0000 (10:27 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 14:27:03 +0000 (10:27 -0400)
fix #845

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/src/transforms/transformExpression.ts

index 0446fa2293600db447af959d79d61c38310d5c99..4bab03c00f319b1d5608bff3fdb74e65432e5c66 100644 (file)
@@ -317,6 +317,16 @@ describe('compiler: expression transform', () => {
     })
   })
 
+  test('should not duplicate object key with same name as value', () => {
+    const node = parseWithExpressionTransform(
+      `{{ { foo: foo } }}`
+    ) as InterpolationNode
+    expect(node.content).toMatchObject({
+      type: NodeTypes.COMPOUND_EXPRESSION,
+      children: [`{ foo: `, { content: `_ctx.foo` }, ` }`]
+    })
+  })
+
   test('should prefix a computed object property key', () => {
     const node = parseWithExpressionTransform(
       `{{ { [foo]: bar } }}`
index b62bcefcd63a31215a8597827e102be67a975bb4..9ff5b8025648eab224bcacf543c45ceb4a3bfc67 100644 (file)
@@ -271,7 +271,8 @@ const isPropertyShorthand = (node: Node, parent: Node) => {
     isStaticProperty(parent) &&
     parent.value === node &&
     parent.key.type === 'Identifier' &&
-    parent.key.name === (node as Identifier).name
+    parent.key.name === (node as Identifier).name &&
+    parent.key.start === node.start
   )
 }