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 ) }