* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 4475 | * @param {*} value |
| 4476 | */ |
| 4477 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 4478 | var propertyInfo = getPropertyInfo(name); |
| 4479 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 4480 | return; |
| 4481 | } |
| 4482 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 4483 | value = null; |
| 4484 | } |
| 4485 | // If the prop isn't in the special list, treat it as a simple attribute. |
| 4486 | if (isCustomComponentTag || propertyInfo === null) { |
| 4487 | if (isAttributeNameSafe(name)) { |
| 4488 | var _attributeName = name; |
| 4489 | if (value === null) { |
| 4490 | node.removeAttribute(_attributeName); |
| 4491 | } else { |
| 4492 | node.setAttribute(_attributeName, '' + value); |
| 4493 | } |
| 4494 | } |
| 4495 | return; |
| 4496 | } |
| 4497 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 4498 | |
| 4499 | if (mustUseProperty) { |
| 4500 | var propertyName = propertyInfo.propertyName; |
| 4501 | |
| 4502 | if (value === null) { |
| 4503 | var type = propertyInfo.type; |
| 4504 | |
| 4505 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 4506 | } else { |
| 4507 | // Contrary to `setAttribute`, object properties are properly |
| 4508 | // `toString`ed by IE8/9. |
| 4509 | node[propertyName] = value; |
| 4510 | } |
| 4511 | return; |
| 4512 | } |
| 4513 | // The rest are treated as attributes with special cases. |
| 4514 | var attributeName = propertyInfo.attributeName, |
| 4515 | attributeNamespace = propertyInfo.attributeNamespace; |
| 4516 | |
| 4517 | if (value === null) { |
| 4518 | node.removeAttribute(attributeName); |
| 4519 | } else { |
| 4520 | var _type = propertyInfo.type; |
| 4521 | |
| 4522 | var attributeValue = void 0; |
| 4523 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 4524 | attributeValue = ''; |
| 4525 | } else { |
| 4526 | // `setAttribute` with objects becomes only `[object]` in IE8/9, |
| 4527 | // ('' + value) makes it output the correct toString()-value. |
| 4528 | attributeValue = '' + value; |
| 4529 | } |
| 4530 | if (attributeNamespace) { |
| 4531 | node.setAttributeNS(attributeNamespace, attributeName, attributeValue); |
| 4532 | } else { |
| 4533 | node.setAttribute(attributeName, attributeValue); |
| 4534 | } |
no test coverage detected