fix(runtime-core): fix boolean props validation

This commit is contained in:
Evan You 2020-03-17 10:35:32 -04:00
parent b716a906fe
commit 3b282e7e3c
2 changed files with 2 additions and 13 deletions

View File

@ -6,11 +6,8 @@ import {
nextTick, nextTick,
defineComponent defineComponent
} from '@vue/runtime-test' } from '@vue/runtime-test'
import { mockWarn } from '@vue/shared'
describe('renderer: component', () => { describe('renderer: component', () => {
mockWarn()
test.todo('should work') test.todo('should work')
test.todo('shouldUpdateComponent') test.todo('shouldUpdateComponent')
@ -43,7 +40,6 @@ describe('renderer: component', () => {
expect(b1).toBe(true) expect(b1).toBe(true)
expect(b2).toBe(true) expect(b2).toBe(true)
expect(b3).toBe('') expect(b3).toBe('')
expect('type check failed for prop "b1"').toHaveBeenWarned()
}) })
}) })

View File

@ -156,7 +156,6 @@ export function resolveProps(
const key = needCastKeys[i] const key = needCastKeys[i]
let opt = options[key] let opt = options[key]
if (opt == null) continue if (opt == null) continue
const isAbsent = !hasOwn(props, key)
const hasDefault = hasOwn(opt, 'default') const hasDefault = hasOwn(opt, 'default')
const currentValue = props[key] const currentValue = props[key]
// default values // default values
@ -166,7 +165,7 @@ export function resolveProps(
} }
// boolean casting // boolean casting
if (opt[BooleanFlags.shouldCast]) { if (opt[BooleanFlags.shouldCast]) {
if (isAbsent && !hasDefault) { if (!hasOwn(props, key) && !hasDefault) {
setProp(key, false) setProp(key, false)
} else if ( } else if (
opt[BooleanFlags.shouldCastTrue] && opt[BooleanFlags.shouldCastTrue] &&
@ -181,13 +180,7 @@ export function resolveProps(
for (const key in options) { for (const key in options) {
let opt = options[key] let opt = options[key]
if (opt == null) continue if (opt == null) continue
let rawValue validateProp(key, props[key], opt, !hasOwn(props, key))
if (!(key in rawProps) && hyphenate(key) in rawProps) {
rawValue = rawProps[hyphenate(key)]
} else {
rawValue = rawProps[key]
}
validateProp(key, toRaw(rawValue), opt, !hasOwn(props, key))
} }
} }
} else { } else {