(_node, parenthesis)
| 327 | * @throws {Error} |
| 328 | */ |
| 329 | export function getAssociativity (_node, parenthesis) { |
| 330 | let node = _node |
| 331 | if (parenthesis !== 'keep') { |
| 332 | // ParenthesisNodes are only ignored when not in 'keep' mode |
| 333 | node = _node.getContent() |
| 334 | } |
| 335 | const identifier = node.getIdentifier() |
| 336 | const index = getPrecedence(node, parenthesis) |
| 337 | if (index === null) { |
| 338 | // node isn't in the list |
| 339 | return null |
| 340 | } |
| 341 | const property = properties[index][identifier] |
| 342 | |
| 343 | if (hasOwnProperty(property, 'associativity')) { |
| 344 | if (property.associativity === 'left') { |
| 345 | return 'left' |
| 346 | } |
| 347 | if (property.associativity === 'right') { |
| 348 | return 'right' |
| 349 | } |
| 350 | // associativity is invalid |
| 351 | throw Error('\'' + identifier + '\' has the invalid associativity \'' + |
| 352 | property.associativity + '\'.') |
| 353 | } |
| 354 | |
| 355 | // associativity is undefined |
| 356 | return null |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Check if an operator is associative with another operator. |
no test coverage detected
searching dependent graphs…