]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): support object syntax for class (#215)
authorIllya Klymov <xanf@xanf.me>
Fri, 11 Oct 2019 19:09:37 +0000 (22:09 +0300)
committerEvan You <yyx990803@gmail.com>
Fri, 11 Oct 2019 19:09:37 +0000 (15:09 -0400)
packages/runtime-core/src/vnode.ts
packages/vue/__tests__/index.spec.ts

index c3d50f63472f0d4fb7128f8e7c04af335c72d189..5c5455ff82fc47995a7d1df8cf1d181d9781efb9 100644 (file)
@@ -4,8 +4,7 @@ import {
   isString,
   isObject,
   EMPTY_ARR,
-  extend,
-  PatchFlags
+  extend
 } from '@vue/shared'
 import {
   ComponentInternalInstance,
@@ -146,9 +145,7 @@ export function createVNode(
     if (isReactive(props) || SetupProxySymbol in props) {
       props = extend({}, props)
     }
-    // class normalization only needed if the vnode isn't generated by
-    // compiler-optimized code
-    if (props.class != null && !(patchFlag & PatchFlags.CLASS)) {
+    if (props.class != null) {
       props.class = normalizeClass(props.class)
     }
     let { style } = props
index eea111ed049ed7f73a80c162350e966ac5d1aa05..754b717a69b652644d699fd6595fc0c8dfec919c 100644 (file)
@@ -13,3 +13,19 @@ it('should support on-the-fly template compilation', () => {
   createApp().mount(App, container)
   expect(container.innerHTML).toBe(`0`)
 })
+
+it('should correctly normalize class with on-the-fly template compilation', () => {
+  const container = document.createElement('div')
+  const App = {
+    template: `<div :class="{ test: demoValue, test2: !demoValue }"></div>`,
+    data() {
+      return {
+        demoValue: true
+      }
+    }
+  }
+  createApp().mount(App, container)
+  const classes = container.firstElementChild!.classList
+  expect(classes.contains('test')).toBe(true)
+  expect(classes.contains('test2')).toBe(false)
+})