Skip to content

Commit

Permalink
fix(runtime-core): fix boolean props validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 17, 2020
1 parent b716a90 commit 3b282e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
4 changes: 0 additions & 4 deletions packages/runtime-core/__tests__/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})
})

Expand Down
11 changes: 2 additions & 9 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] &&
Expand All @@ -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 {
Expand Down

0 comments on commit 3b282e7

Please sign in to comment.