mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Node: add method 'getContent()'
The 'getContent' method returns the next node down the node tree that isn't a ParenthesisNode.
This commit is contained in:
parent
dd0a5e3a68
commit
6c2cd7f7b7
@ -299,6 +299,14 @@ function factory (type, config, load, typed) {
|
||||
return this.type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the content of the current Node.
|
||||
* @return {Node} node
|
||||
**/
|
||||
Node.prototype.getContent = function () {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the symbol names of a scope.
|
||||
* Throws an error when the scope contains an illegal symbol.
|
||||
|
||||
@ -27,6 +27,8 @@ function factory (type, config, load, typed) {
|
||||
|
||||
ParenthesisNode.prototype.type = 'ParenthesisNode';
|
||||
|
||||
ParenthesisNode.prototype.isParenthesisNode = true;
|
||||
|
||||
/**
|
||||
* Compile the node to javascript code
|
||||
* @param {Object} defs Object which can be used to define functions
|
||||
@ -39,6 +41,15 @@ function factory (type, config, load, typed) {
|
||||
return this.content._compile(defs);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the content of the current Node.
|
||||
* @return {Node} content
|
||||
* @override
|
||||
**/
|
||||
ParenthesisNode.prototype.getContent = function () {
|
||||
return this.content.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a callback for each of the child nodes of this node
|
||||
* @param {function(child: Node, path: string, parent: Node)} callback
|
||||
|
||||
@ -118,4 +118,10 @@ describe('Node', function() {
|
||||
assert.equal(node.getIdentifier(), 'Node');
|
||||
});
|
||||
|
||||
it ('should get the content of a Node', function () {
|
||||
var c = new math.expression.node.ConstantNode(1);
|
||||
|
||||
assert.equal(c.getContent(), c);
|
||||
assert.deepEqual(c.getContent(), c);
|
||||
});
|
||||
});
|
||||
|
||||
@ -112,6 +112,18 @@ describe('ParenthesisNode', function() {
|
||||
assert.equal(n.content, clone.content);
|
||||
});
|
||||
|
||||
it ('should get the content of a ParenthesisNode', function () {
|
||||
var c = new math.expression.node.ConstantNode(1);
|
||||
var p1 = new math.expression.node.ParenthesisNode(c);
|
||||
var p2 = new math.expression.node.ParenthesisNode(p1);
|
||||
|
||||
assert.equal(p1.content, c);
|
||||
assert.equal(p1.getContent(), c);
|
||||
assert.deepEqual(p1.getContent(), c);
|
||||
assert.equal(p2.getContent(), c);
|
||||
assert.deepEqual(p2.getContent(), c);
|
||||
});
|
||||
|
||||
it ('should stringify a ParenthesisNode', function () {
|
||||
var a = new ConstantNode(1);
|
||||
var n = new ParenthesisNode(a);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user