]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix boolean props validation
authorEvan You <yyx990803@gmail.com>
Tue, 17 Mar 2020 14:35:32 +0000 (10:35 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 17 Mar 2020 14:35:32 +0000 (10:35 -0400)
packages/runtime-core/__tests__/component.spec.ts
packages/runtime-core/src/componentProps.ts

index 4fd8707b6be9ec3d4bddfe326ed60363eb950d30..dad6f8ca8bbce4d394e300d1380dab64338fad3f 100644 (file)
@@ -6,11 +6,8 @@ import {
   nextTick,
   defineComponent
 } from '@vue/runtime-test'
-import { mockWarn } from '@vue/shared'
 
 describe('renderer: component', () => {
-  mockWarn()
-
   test.todo('should work')
 
   test.todo('shouldUpdateComponent')
@@ -43,7 +40,6 @@ describe('renderer: component', () => {
       expect(b1).toBe(true)
       expect(b2).toBe(true)
       expect(b3).toBe('')
-      expect('type check failed for prop "b1"').toHaveBeenWarned()
     })
   })
 
index c2cbb473d6c9cdbb4819497cea8f0394b7ac78dd..c243d5179eda18a16be25ad410deae1921446cbe 100644 (file)
@@ -156,7 +156,6 @@ export function resolveProps(
       const key = needCastKeys[i]
       let opt = options[key]
       if (opt == null) continue
-      const isAbsent = !hasOwn(props, key)
       const hasDefault = hasOwn(opt, 'default')
       const currentValue = props[key]
       // default values
@@ -166,7 +165,7 @@ export function resolveProps(
       }
       // boolean casting
       if (opt[BooleanFlags.shouldCast]) {
-        if (isAbsent && !hasDefault) {
+        if (!hasOwn(props, key) && !hasDefault) {
           setProp(key, false)
         } else if (
           opt[BooleanFlags.shouldCastTrue] &&
@@ -181,13 +180,7 @@ export function resolveProps(
       for (const key in options) {
         let opt = options[key]
         if (opt == null) continue
-        let rawValue
-        if (!(key in rawProps) && hyphenate(key) in rawProps) {
-          rawValue = rawProps[hyphenate(key)]
-        } else {
-          rawValue = rawProps[key]
-        }
-        validateProp(key, toRaw(rawValue), opt, !hasOwn(props, key))
+        validateProp(key, props[key], opt, !hasOwn(props, key))
       }
     }
   } else {