fix(compiler-core): should not prefix object method (#1375)

This commit is contained in:
underfin 2020-06-15 23:20:00 +08:00 committed by GitHub
parent 68e2d6c68a
commit 35dbef268c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -306,14 +306,19 @@ describe('compiler: expression transform', () => {
] ]
}) })
}) })
test('should not prefix an object property key', () => { test('should not prefix an object property key', () => {
const node = parseWithExpressionTransform( const node = parseWithExpressionTransform(
`{{ { foo: bar } }}` `{{ { foo() { baz() }, value: bar } }}`
) as InterpolationNode ) as InterpolationNode
expect(node.content).toMatchObject({ expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION, type: NodeTypes.COMPOUND_EXPRESSION,
children: [`{ foo: `, { content: `_ctx.bar` }, ` }`] children: [
`{ foo() { `,
{ content: `_ctx.baz` },
`() }, value: `,
{ content: `_ctx.bar` },
` }`
]
}) })
}) })

View File

@ -271,7 +271,9 @@ const isFunction = (node: Node): node is Function =>
/Function(Expression|Declaration)$/.test(node.type) /Function(Expression|Declaration)$/.test(node.type)
const isStaticProperty = (node: Node): node is ObjectProperty => 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) => { const isPropertyShorthand = (node: Node, parent: Node) => {
return ( return (