From 97ee51d5dede9ccaed5ca43a7b50600a4d4c6bb1 Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Mon, 15 Jun 2020 17:33:34 +0800 Subject: [PATCH 1/2] fix(compiler-core): should not prefix an object property key when value is function fix #1373 --- .../__tests__/transforms/transformExpressions.spec.ts | 4 ++-- packages/compiler-core/src/transforms/transformExpression.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 4bab03c00f3..055e9f32c90 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -309,11 +309,11 @@ describe('compiler: expression transform', () => { test('should not prefix an object property key', () => { const node = parseWithExpressionTransform( - `{{ { foo: bar } }}` + `{{ { foo: () => {}, value: bar } }}` ) as InterpolationNode expect(node.content).toMatchObject({ type: NodeTypes.COMPOUND_EXPRESSION, - children: [`{ foo: `, { content: `_ctx.bar` }, ` }`] + children: [`{ foo: () => {}, value: `, { content: `_ctx.bar` }, ` }`] }) }) diff --git a/packages/compiler-core/src/transforms/transformExpression.ts b/packages/compiler-core/src/transforms/transformExpression.ts index 0d3f145e77b..b1da05b4589 100644 --- a/packages/compiler-core/src/transforms/transformExpression.ts +++ b/packages/compiler-core/src/transforms/transformExpression.ts @@ -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 ( From 887254bbb93b8146da20a5fab047e583a758b5d7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 15 Jun 2020 11:19:06 -0400 Subject: [PATCH 2/2] Update transformExpressions.spec.ts --- .../__tests__/transforms/transformExpressions.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 055e9f32c90..870024a4b9c 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -306,14 +306,19 @@ describe('compiler: expression transform', () => { ] }) }) - test('should not prefix an object property key', () => { const node = parseWithExpressionTransform( - `{{ { foo: () => {}, value: bar } }}` + `{{ { foo() { baz() }, value: bar } }}` ) as InterpolationNode expect(node.content).toMatchObject({ type: NodeTypes.COMPOUND_EXPRESSION, - children: [`{ foo: () => {}, value: `, { content: `_ctx.bar` }, ` }`] + children: [ + `{ foo() { `, + { content: `_ctx.baz` }, + `() }, value: `, + { content: `_ctx.bar` }, + ` }` + ] }) })