* 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)
| 4290 | * Some properties have multiple equivalent values. |
| 4291 | */ |
| 4292 | function getValueForProperty(node, name, expected, propertyInfo) { |
| 4293 | { |
| 4294 | if (propertyInfo.mustUseProperty) { |
| 4295 | var propertyName = propertyInfo.propertyName; |
| 4296 | |
| 4297 | return node[propertyName]; |
| 4298 | } else { |
| 4299 | var attributeName = propertyInfo.attributeName; |
| 4300 | |
| 4301 | var stringValue = null; |
| 4302 | |
| 4303 | if (propertyInfo.type === OVERLOADED_BOOLEAN) { |
| 4304 | if (node.hasAttribute(attributeName)) { |
| 4305 | var value = node.getAttribute(attributeName); |
| 4306 | if (value === '') { |
| 4307 | return true; |
| 4308 | } |
| 4309 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4310 | return value; |
| 4311 | } |
| 4312 | if (value === '' + expected) { |
| 4313 | return expected; |
| 4314 | } |
| 4315 | return value; |
| 4316 | } |
| 4317 | } else if (node.hasAttribute(attributeName)) { |
| 4318 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4319 | // We had an attribute but shouldn't have had one, so read it |
| 4320 | // for the error message. |
| 4321 | return node.getAttribute(attributeName); |
| 4322 | } |
| 4323 | if (propertyInfo.type === BOOLEAN) { |
| 4324 | // If this was a boolean, it doesn't matter what the value is |
| 4325 | // the fact that we have it is the same as the expected. |
| 4326 | return expected; |
| 4327 | } |
| 4328 | // Even if this property uses a namespace we use getAttribute |
| 4329 | // because we assume its namespaced name is the same as our config. |
| 4330 | // To use getAttributeNS we need the local name which we don't have |
| 4331 | // in our config atm. |
| 4332 | stringValue = node.getAttribute(attributeName); |
| 4333 | } |
| 4334 | |
| 4335 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4336 | return stringValue === null ? expected : stringValue; |
| 4337 | } else if (stringValue === '' + expected) { |
| 4338 | return expected; |
| 4339 | } else { |
| 4340 | return stringValue; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * Get the value for a attribute on a node. Only used in DEV for SSR validation. |
no test coverage detected