Skip to content

Commit 3b282e7

Browse files
committed
fix(runtime-core): fix boolean props validation
1 parent b716a90 commit 3b282e7

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

packages/runtime-core/__tests__/component.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import {
66
nextTick,
77
defineComponent
88
} from '@vue/runtime-test'
9-
import { mockWarn } from '@vue/shared'
109

1110
describe('renderer: component', () => {
12-
mockWarn()
13-
1411
test.todo('should work')
1512

1613
test.todo('shouldUpdateComponent')
@@ -43,7 +40,6 @@ describe('renderer: component', () => {
4340
expect(b1).toBe(true)
4441
expect(b2).toBe(true)
4542
expect(b3).toBe('')
46-
expect('type check failed for prop "b1"').toHaveBeenWarned()
4743
})
4844
})
4945

packages/runtime-core/src/componentProps.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export function resolveProps(
156156
const key = needCastKeys[i]
157157
let opt = options[key]
158158
if (opt == null) continue
159-
const isAbsent = !hasOwn(props, key)
160159
const hasDefault = hasOwn(opt, 'default')
161160
const currentValue = props[key]
162161
// default values
@@ -166,7 +165,7 @@ export function resolveProps(
166165
}
167166
// boolean casting
168167
if (opt[BooleanFlags.shouldCast]) {
169-
if (isAbsent && !hasDefault) {
168+
if (!hasOwn(props, key) && !hasDefault) {
170169
setProp(key, false)
171170
} else if (
172171
opt[BooleanFlags.shouldCastTrue] &&
@@ -181,13 +180,7 @@ export function resolveProps(
181180
for (const key in options) {
182181
let opt = options[key]
183182
if (opt == null) continue
184-
let rawValue
185-
if (!(key in rawProps) && hyphenate(key) in rawProps) {
186-
rawValue = rawProps[hyphenate(key)]
187-
} else {
188-
rawValue = rawProps[key]
189-
}
190-
validateProp(key, toRaw(rawValue), opt, !hasOwn(props, key))
183+
validateProp(key, props[key], opt, !hasOwn(props, key))
191184
}
192185
}
193186
} else {

0 commit comments

Comments
 (0)