* 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)
| 4255 | * Some properties have multiple equivalent values. |
| 4256 | */ |
| 4257 | function getValueForProperty(node, name, expected, propertyInfo) { |
| 4258 | { |
| 4259 | if (propertyInfo.mustUseProperty) { |
| 4260 | var propertyName = propertyInfo.propertyName; |
| 4261 | |
| 4262 | return node[propertyName]; |
| 4263 | } else { |
| 4264 | var attributeName = propertyInfo.attributeName; |
| 4265 | |
| 4266 | var stringValue = null; |
| 4267 | |
| 4268 | if (propertyInfo.type === OVERLOADED_BOOLEAN) { |
| 4269 | if (node.hasAttribute(attributeName)) { |
| 4270 | var value = node.getAttribute(attributeName); |
| 4271 | if (value === '') { |
| 4272 | return true; |
| 4273 | } |
| 4274 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4275 | return value; |
| 4276 | } |
| 4277 | if (value === '' + expected) { |
| 4278 | return expected; |
| 4279 | } |
| 4280 | return value; |
| 4281 | } |
| 4282 | } else if (node.hasAttribute(attributeName)) { |
| 4283 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4284 | // We had an attribute but shouldn't have had one, so read it |
| 4285 | // for the error message. |
| 4286 | return node.getAttribute(attributeName); |
| 4287 | } |
| 4288 | if (propertyInfo.type === BOOLEAN) { |
| 4289 | // If this was a boolean, it doesn't matter what the value is |
| 4290 | // the fact that we have it is the same as the expected. |
| 4291 | return expected; |
| 4292 | } |
| 4293 | // Even if this property uses a namespace we use getAttribute |
| 4294 | // because we assume its namespaced name is the same as our config. |
| 4295 | // To use getAttributeNS we need the local name which we don't have |
| 4296 | // in our config atm. |
| 4297 | stringValue = node.getAttribute(attributeName); |
| 4298 | } |
| 4299 | |
| 4300 | if (shouldRemoveAttribute(name, expected, propertyInfo, false)) { |
| 4301 | return stringValue === null ? expected : stringValue; |
| 4302 | } else if (stringValue === '' + expected) { |
| 4303 | return expected; |
| 4304 | } else { |
| 4305 | return stringValue; |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | /** |
| 4312 | * Get the value for a attribute on a node. Only used in DEV for SSR validation. |
no test coverage detected