diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index 811e56013c9..d2780f35fa7 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -4,7 +4,8 @@ import { transform, ErrorCodes, BindingTypes, - NodeTransform + NodeTransform, + transformExpression } from '../../src' import { RESOLVE_COMPONENT, @@ -773,6 +774,37 @@ describe('compiler: element transform', () => { }) }) + test(`props merging: style w/ transformExpression`, () => { + const { node, root } = parseWithElementTransform( + `
`, + { + nodeTransforms: [transformExpression, transformStyle, transformElement], + directiveTransforms: { + bind: transformBind + }, + prefixIdentifiers: true + } + ) + expect(root.helpers).toContain(NORMALIZE_STYLE) + expect(node.props).toMatchObject({ + type: NodeTypes.JS_OBJECT_EXPRESSION, + properties: [ + { + type: NodeTypes.JS_PROPERTY, + key: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: `style`, + isStatic: true + }, + value: { + type: NodeTypes.JS_CALL_EXPRESSION, + callee: NORMALIZE_STYLE + } + } + ] + }) + }) + test(`props merging: class`, () => { const { node, root } = parseWithElementTransform( `
`, diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 90d33aa8b1f..4b142564f0a 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -738,7 +738,10 @@ export function buildProps( !isStaticExp(styleProp.value) && // the static style is compiled into an object, // so use `hasStyleBinding` to ensure that it is a dynamic style binding - hasStyleBinding + (hasStyleBinding || + // v-bind:style and style both exist, + // v-bind:style with static literal object + styleProp.value.type === NodeTypes.JS_ARRAY_EXPRESSION) ) { styleProp.value = createCallExpression( context.helper(NORMALIZE_STYLE),