Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-core): should not prefix an object property key when val… #1375

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,19 @@ describe('compiler: expression transform', () => {
]
})
})

test('should not prefix an object property key', () => {
const node = parseWithExpressionTransform(
`{{ { foo: bar } }}`
`{{ { foo() { baz() }, value: bar } }}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note only foo() {} syntax results in ObjectMethod type, foo: () => {} is still considered ObjectProperty so original test case was incorrect.

) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`{ foo: `, { content: `_ctx.bar` }, ` }`]
children: [
`{ foo() { `,
{ content: `_ctx.baz` },
`() }, value: `,
{ content: `_ctx.bar` },
` }`
]
})
})

Expand Down
4 changes: 3 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,9 @@ const isFunction = (node: Node): node is Function =>
/Function(Expression|Declaration)$/.test(node.type)

const isStaticProperty = (node: Node): node is ObjectProperty =>
node && node.type === 'ObjectProperty' && !node.computed
node &&
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
!node.computed

const isPropertyShorthand = (node: Node, parent: Node) => {
return (
Expand Down