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

Method constructor

src/expression/node/AssignmentNode.js:69–88  ·  view source on GitHub ↗

* @constructor AssignmentNode * @extends {Node} * * Define a symbol, like `a=3.2`, update a property like `a.b=3.2`, or * replace a subset of a matrix like `A[2,2]=42`. * * Syntax: * * new AssignmentNode(symbol, value) * new AssignmentNode(object,

(object, index, value)

Source from the content-addressed store, hash-verified

67 * The value to be assigned
68 */
69 constructor (object, index, value) {
70 super()
71 this.object = object
72 this.index = value ? index : null
73 this.value = value || index
74
75 // validate input
76 if (!isSymbolNode(object) && !isAccessorNode(object)) {
77 throw new TypeError('SymbolNode or AccessorNode expected as "object"')
78 }
79 if (isSymbolNode(object) && object.name === 'end') {
80 throw new Error('Cannot assign to symbol "end"')
81 }
82 if (this.index && !isIndexNode(this.index)) { // index is optional
83 throw new TypeError('IndexNode expected as "index"')
84 }
85 if (!isNode(this.value)) {
86 throw new TypeError('Node expected as "value"')
87 }
88 }
89
90 // class name for typing purposes:
91 static name = name

Callers

nothing calls this directly

Calls 4

isSymbolNodeFunction · 0.90
isAccessorNodeFunction · 0.90
isIndexNodeFunction · 0.90
isNodeFunction · 0.90

Tested by

no test coverage detected