fix(compiler-core): should not generate CLASS/STYLE patch flags on components

ref #677
This commit is contained in:
Evan You
2020-04-10 10:19:11 -04:00
parent cda50ea788
commit a6e2b1052a
3 changed files with 17 additions and 16 deletions

View File

@@ -739,6 +739,15 @@ describe('compiler: element transform', () => {
expect(node.dynamicProps).toBe(`["foo", "baz"]`)
})
// should treat `class` and `style` as PROPS
test('PROPS on component', () => {
const { node } = parseWithBind(
`<Foo :id="foo" :class="cls" :style="styl" />`
)
expect(node.patchFlag).toBe(genFlagText(PatchFlags.PROPS))
expect(node.dynamicProps).toBe(`["id", "class", "style"]`)
})
test('FULL_PROPS (v-bind)', () => {
const { node } = parseWithBind(`<div v-bind="foo" />`)
expect(node.patchFlag).toBe(genFlagText(PatchFlags.FULL_PROPS))

View File

@@ -289,9 +289,9 @@ export function buildProps(
}
if (name === 'ref') {
hasRef = true
} else if (name === 'class') {
} else if (name === 'class' && !isComponent) {
hasClassBinding = true
} else if (name === 'style') {
} else if (name === 'style' && !isComponent) {
hasStyleBinding = true
} else if (name !== 'key' && !dynamicPropNames.includes(name)) {
dynamicPropNames.push(name)