* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 4337 | * @param {*} value |
| 4338 | */ |
| 4339 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 4340 | var propertyInfo = getPropertyInfo(name); |
| 4341 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 4342 | return; |
| 4343 | } |
| 4344 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 4345 | value = null; |
| 4346 | } |
| 4347 | // If the prop isn't in the special list, treat it as a simple attribute. |
| 4348 | if (isCustomComponentTag || propertyInfo === null) { |
| 4349 | if (isAttributeNameSafe(name)) { |
| 4350 | var _attributeName = name; |
| 4351 | if (value === null) { |
| 4352 | node.removeAttribute(_attributeName); |
| 4353 | } else { |
| 4354 | node.setAttribute(_attributeName, '' + value); |
| 4355 | } |
| 4356 | } |
| 4357 | return; |
| 4358 | } |
| 4359 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 4360 | |
| 4361 | if (mustUseProperty) { |
| 4362 | var propertyName = propertyInfo.propertyName; |
| 4363 | |
| 4364 | if (value === null) { |
| 4365 | var type = propertyInfo.type; |
| 4366 | |
| 4367 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 4368 | } else { |
| 4369 | // Contrary to `setAttribute`, object properties are properly |
| 4370 | // `toString`ed by IE8/9. |
| 4371 | node[propertyName] = value; |
| 4372 | } |
| 4373 | return; |
| 4374 | } |
| 4375 | // The rest are treated as attributes with special cases. |
| 4376 | var attributeName = propertyInfo.attributeName, |
| 4377 | attributeNamespace = propertyInfo.attributeNamespace; |
| 4378 | |
| 4379 | if (value === null) { |
| 4380 | node.removeAttribute(attributeName); |
| 4381 | } else { |
| 4382 | var _type = propertyInfo.type; |
| 4383 | |
| 4384 | var attributeValue = void 0; |
| 4385 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 4386 | attributeValue = ''; |
| 4387 | } else { |
| 4388 | // `setAttribute` with objects becomes only `[object]` in IE8/9, |
| 4389 | // ('' + value) makes it output the correct toString()-value. |
| 4390 | attributeValue = '' + value; |
| 4391 | } |
| 4392 | if (attributeNamespace) { |
| 4393 | node.setAttributeNS(attributeNamespace, attributeName, attributeValue); |
| 4394 | } else { |
| 4395 | node.setAttribute(attributeName, attributeValue); |
| 4396 | } |
no test coverage detected