From: Evan You Date: Mon, 16 Mar 2020 14:27:03 +0000 (-0400) Subject: fix(compiler-core): fix property shorthand detection X-Git-Tag: v3.0.0-alpha.9~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=586e5bb8003916ba6be9b3394087df80328657f4;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-core): fix property shorthand detection fix #845 --- diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 0446fa2293..4bab03c00f 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 b62bcefcd6..9ff5b80256 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 ) }