Skip to content

Commit

Permalink
fix(compiler-core): fix property shorthand detection
Browse files Browse the repository at this point in the history
fix #845
  • Loading branch information
yyx990803 committed Mar 16, 2020
1 parent c7ae269 commit 586e5bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }}`
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-core/src/transforms/transformExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down

0 comments on commit 586e5bb

Please sign in to comment.