* Get the value for a property on a node. Only used in DEV for SSR validation. * The "expected" argument is used as a hint of what the expected value is. * Some properties have multiple equivalent values.
(node, name, expected, propertyInfo)
| 4393 | * Some properties have multiple equivalent values. |
| 4394 | */ |
| 4395 | function getValueForProperty(node, name, expected, propertyInfo) { |
| 4396 | { |
| 4397 | if (propertyInfo.mustUseProperty) { |
| 4398 | var propertyName = propertyInfo.propertyName; |
| 4399 | |
| 4400 | return node[propertyName]; |
| 4401 | } else { |
| 4402 | var attributeName = propertyInfo.attributeName; |
| 4403 | |
| 4404 | var stringValue = null; |
| 4405 | |
| 4406 | if (propertyInfo.type === OVERLOADED_BOOLEAN) { |
| 4407 | if (node.hasAttribute(attributeName)) { |
| 4408 | var value = node.getAttribute(attributeName); |
| 4409 | if (value === '') { |
| 4410 | return true; |
| 4411 | } |
| 4412 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4413 | return value; |
| 4414 | } |
| 4415 | if (value === '' + expected) { |
| 4416 | return expected; |
| 4417 | } |
| 4418 | return value; |
| 4419 | } |
| 4420 | } else if (node.hasAttribute(attributeName)) { |
| 4421 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4422 | // We had an attribute but shouldn't have had one, so read it |
| 4423 | // for the error message. |
| 4424 | return node.getAttribute(attributeName); |
| 4425 | } |
| 4426 | if (propertyInfo.type === BOOLEAN) { |
| 4427 | // If this was a boolean, it doesn't matter what the value is |
| 4428 | // the fact that we have it is the same as the expected. |
| 4429 | return expected; |
| 4430 | } |
| 4431 | // Even if this property uses a namespace we use getAttribute |
| 4432 | // because we assume its namespaced name is the same as our config. |
| 4433 | // To use getAttributeNS we need the local name which we don't have |
| 4434 | // in our config atm. |
| 4435 | stringValue = node.getAttribute(attributeName); |
| 4436 | } |
| 4437 | |
| 4438 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4439 | return stringValue === null ? expected : stringValue; |
| 4440 | } else if (stringValue === '' + expected) { |
| 4441 | return expected; |
| 4442 | } else { |
| 4443 | return stringValue; |
| 4444 | } |
| 4445 | } |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | /** |
| 4450 | * Get the value for a attribute on a node. Only used in DEV for SSR validation. |
no test coverage detected