wip: staticStyle and staticClass

This commit is contained in:
Evan You 2021-04-11 22:21:10 -04:00
parent 62bfdae043
commit 24bab94a72
2 changed files with 50 additions and 2 deletions

View File

@ -60,6 +60,35 @@ describe('compat: render function', () => {
})
})
test('staticClass + class', () => {
expect(
h('div', {
class: { foo: true },
staticClass: 'bar'
})
).toMatchObject({
props: {
class: 'bar foo'
}
})
})
test('staticStyle + style', () => {
expect(
h('div', {
style: { color: 'red' },
staticStyle: { fontSize: '14px' }
})
).toMatchObject({
props: {
style: {
color: 'red',
fontSize: '14px'
}
}
})
})
test('on / nativeOn', () => {
const fn = () => {}
expect(

View File

@ -2,6 +2,8 @@ import {
extend,
isArray,
isObject,
normalizeClass,
normalizeStyle,
ShapeFlags,
toHandlerKey
} from '@vue/shared'
@ -141,7 +143,13 @@ export function compatH(
}
}
function convertLegacyProps(legacyProps?: LegacyVNodeProps): Data & VNodeProps {
function convertLegacyProps(
legacyProps?: LegacyVNodeProps
): Data & VNodeProps | null {
if (!legacyProps) {
return null
}
const converted: Data & VNodeProps = {}
for (const key in legacyProps) {
@ -159,11 +167,22 @@ function convertLegacyProps(legacyProps?: LegacyVNodeProps): Data & VNodeProps {
: incoming
}
}
} else {
} else if (
key !== 'refInFor' &&
key !== 'staticStyle' &&
key !== 'staticClass'
) {
converted[key] = legacyProps[key as keyof LegacyVNodeProps]
}
}
if (legacyProps.staticClass) {
converted.class = normalizeClass([legacyProps.staticClass, converted.class])
}
if (legacyProps.staticStyle) {
converted.style = normalizeStyle([legacyProps.staticStyle, converted.style])
}
return converted
}