]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: staticStyle and staticClass
authorEvan You <yyx990803@gmail.com>
Mon, 12 Apr 2021 02:21:10 +0000 (22:21 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 12 Apr 2021 02:21:10 +0000 (22:21 -0400)
packages/runtime-core/src/compat/__tests__/renderFn.spec.ts
packages/runtime-core/src/compat/renderFn.ts

index f67e25cd6de2ecd37e11e182aad1bdada9512fc9..7c2059d7fe06f6228aaaf443469b253fee32fd0a 100644 (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(
index 69e773f3c9be6f611c8bca6b5caff645880be059..945c2c2fdfa43e435c10a548cc9b6f3373b894f5 100644 (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
 }