Skip to content

Commit 586e5bb

Browse files
committed
fix(compiler-core): fix property shorthand detection
fix #845
1 parent c7ae269 commit 586e5bb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ describe('compiler: expression transform', () => {
317317
})
318318
})
319319

320+
test('should not duplicate object key with same name as value', () => {
321+
const node = parseWithExpressionTransform(
322+
`{{ { foo: foo } }}`
323+
) as InterpolationNode
324+
expect(node.content).toMatchObject({
325+
type: NodeTypes.COMPOUND_EXPRESSION,
326+
children: [`{ foo: `, { content: `_ctx.foo` }, ` }`]
327+
})
328+
})
329+
320330
test('should prefix a computed object property key', () => {
321331
const node = parseWithExpressionTransform(
322332
`{{ { [foo]: bar } }}`

packages/compiler-core/src/transforms/transformExpression.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ const isPropertyShorthand = (node: Node, parent: Node) => {
271271
isStaticProperty(parent) &&
272272
parent.value === node &&
273273
parent.key.type === 'Identifier' &&
274-
parent.key.name === (node as Identifier).name
274+
parent.key.name === (node as Identifier).name &&
275+
parent.key.start === node.start
275276
)
276277
}
277278

0 commit comments

Comments
 (0)