Skip to content

Commit 0f00cf4

Browse files
committed
fix(compiler-core): normalize v-bind:style with array literal value
fix #5106
1 parent 59cf295 commit 0f00cf4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/compiler-core/__tests__/transforms/transformElement.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,37 @@ describe('compiler: element transform', () => {
807807
})
808808
})
809809

810+
test(':style with array literal', () => {
811+
const { node, root } = parseWithElementTransform(
812+
`<div :style="[{ color: 'red' }]" />`,
813+
{
814+
nodeTransforms: [transformExpression, transformStyle, transformElement],
815+
directiveTransforms: {
816+
bind: transformBind
817+
},
818+
prefixIdentifiers: true
819+
}
820+
)
821+
expect(root.helpers).toContain(NORMALIZE_STYLE)
822+
expect(node.props).toMatchObject({
823+
type: NodeTypes.JS_OBJECT_EXPRESSION,
824+
properties: [
825+
{
826+
type: NodeTypes.JS_PROPERTY,
827+
key: {
828+
type: NodeTypes.SIMPLE_EXPRESSION,
829+
content: `style`,
830+
isStatic: true
831+
},
832+
value: {
833+
type: NodeTypes.JS_CALL_EXPRESSION,
834+
callee: NORMALIZE_STYLE
835+
}
836+
}
837+
]
838+
})
839+
})
840+
810841
test(`props merging: class`, () => {
811842
const { node, root } = parseWithElementTransform(
812843
`<div class="foo" :class="{ bar: isBar }" />`,

packages/compiler-core/src/transforms/transformElement.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,11 @@ export function buildProps(
767767
}
768768
if (
769769
styleProp &&
770-
!isStaticExp(styleProp.value) &&
771770
// the static style is compiled into an object,
772771
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
773772
(hasStyleBinding ||
773+
(styleProp.value.type === NodeTypes.SIMPLE_EXPRESSION &&
774+
styleProp.value.content.trim()[0] === `[`) ||
774775
// v-bind:style and style both exist,
775776
// v-bind:style with static literal object
776777
styleProp.value.type === NodeTypes.JS_ARRAY_EXPRESSION)

0 commit comments

Comments
 (0)