(
key,
propOptions,
propsData,
vm
)
| 1604 | |
| 1605 | |
| 1606 | function validateProp ( |
| 1607 | key, |
| 1608 | propOptions, |
| 1609 | propsData, |
| 1610 | vm |
| 1611 | ) { |
| 1612 | var prop = propOptions[key]; |
| 1613 | var absent = !hasOwn(propsData, key); |
| 1614 | var value = propsData[key]; |
| 1615 | // boolean casting |
| 1616 | var booleanIndex = getTypeIndex(Boolean, prop.type); |
| 1617 | if (booleanIndex > -1) { |
| 1618 | if (absent && !hasOwn(prop, 'default')) { |
| 1619 | value = false; |
| 1620 | } else if (value === '' || value === hyphenate(key)) { |
| 1621 | // only cast empty string / same name to boolean if |
| 1622 | // boolean has higher priority |
| 1623 | var stringIndex = getTypeIndex(String, prop.type); |
| 1624 | if (stringIndex < 0 || booleanIndex < stringIndex) { |
| 1625 | value = true; |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | // check default value |
| 1630 | if (value === undefined) { |
| 1631 | value = getPropDefaultValue(vm, prop, key); |
| 1632 | // since the default value is a fresh copy, |
| 1633 | // make sure to observe it. |
| 1634 | var prevShouldObserve = shouldObserve; |
| 1635 | toggleObserving(true); |
| 1636 | observe(value); |
| 1637 | toggleObserving(prevShouldObserve); |
| 1638 | } |
| 1639 | { |
| 1640 | assertProp(prop, key, value, vm, absent); |
| 1641 | } |
| 1642 | return value |
| 1643 | } |
| 1644 | |
| 1645 | /** |
| 1646 | * Get the default value of a prop. |
no test coverage detected