From 586e5bb8003916ba6be9b3394087df80328657f4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 16 Mar 2020 10:27:03 -0400 Subject: [PATCH] fix(compiler-core): fix property shorthand detection fix #845 --- .../__tests__/transforms/transformExpressions.spec.ts | 10 ++++++++++ .../src/transforms/transformExpression.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 0446fa22..4bab03c0 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -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 } }}` diff --git a/packages/compiler-core/src/transforms/transformExpression.ts b/packages/compiler-core/src/transforms/transformExpression.ts index b62bcefc..9ff5b802 100644 --- a/packages/compiler-core/src/transforms/transformExpression.ts +++ b/packages/compiler-core/src/transforms/transformExpression.ts @@ -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 ) }