MCPcopy
hub / github.com/josdejong/mathjs / getAssociativity

Function getAssociativity

src/expression/operators.js:329–357  ·  view source on GitHub ↗
(_node, parenthesis)

Source from the content-addressed store, hash-verified

327 * @throws {Error}
328 */
329export 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.

Callers 5

operators.test.jsFile · 0.90
_toStringMethod · 0.90
_toHTMLMethod · 0.90
_toTexMethod · 0.90

Calls 4

hasOwnPropertyFunction · 0.90
getPrecedenceFunction · 0.85
getContentMethod · 0.45
getIdentifierMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…