From e32da9169bcad1b811d27695e368a8d996d9cf4a Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Fri, 11 Oct 2019 22:09:37 +0300 Subject: [PATCH] fix(runtime-core): support object syntax for class (#215) --- packages/runtime-core/src/vnode.ts | 7 ++----- packages/vue/__tests__/index.spec.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index c3d50f634..5c5455ff8 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -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 diff --git a/packages/vue/__tests__/index.spec.ts b/packages/vue/__tests__/index.spec.ts index eea111ed0..754b717a6 100644 --- a/packages/vue/__tests__/index.spec.ts +++ b/packages/vue/__tests__/index.spec.ts @@ -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: `
`, + 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) +})