mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Fixed an issue in the Parser not resolving variables later on when undefined in first instance.
This commit is contained in:
parent
6faacfb120
commit
c1fa8d8231
17
math.js
17
math.js
@ -4250,13 +4250,6 @@ FunctionAssignment.prototype.toString = function() {
|
||||
return this.def.toString();
|
||||
};
|
||||
|
||||
/**
|
||||
* @License Apache 2.0 License
|
||||
*
|
||||
* @Author Jos de Jong
|
||||
* @Date 2012-07-10
|
||||
*/
|
||||
|
||||
/**
|
||||
* Scope
|
||||
* A scope stores functions.
|
||||
@ -4278,6 +4271,8 @@ function Scope(parentScope) {
|
||||
|
||||
math.parser.node.Scope = Scope;
|
||||
|
||||
// TODO: rethink the whole scoping solution again. Try to simplify
|
||||
|
||||
/**
|
||||
* Create a nested scope
|
||||
* The variables in a nested scope are not accessible from the parent scope
|
||||
@ -4339,9 +4334,15 @@ Scope.prototype.createSymbol = function (name) {
|
||||
*/
|
||||
Scope.prototype.newSymbol = function (name, value) {
|
||||
// create a new symbol
|
||||
var scope = this;
|
||||
var symbol = function () {
|
||||
if (!symbol.value) {
|
||||
throw new Error('Undefined symbol ' + name);
|
||||
// try to resolve again
|
||||
symbol.value = scope.findDef(name);
|
||||
|
||||
if (!symbol.value) {
|
||||
throw new Error('Undefined symbol ' + name);
|
||||
}
|
||||
}
|
||||
if (typeof symbol.value == 'function') {
|
||||
return symbol.value.apply(null, arguments);
|
||||
|
||||
2
math.min.js
vendored
2
math.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,10 +1,3 @@
|
||||
/**
|
||||
* @License Apache 2.0 License
|
||||
*
|
||||
* @Author Jos de Jong
|
||||
* @Date 2012-07-10
|
||||
*/
|
||||
|
||||
/**
|
||||
* Scope
|
||||
* A scope stores functions.
|
||||
@ -26,6 +19,8 @@ function Scope(parentScope) {
|
||||
|
||||
math.parser.node.Scope = Scope;
|
||||
|
||||
// TODO: rethink the whole scoping solution again. Try to simplify
|
||||
|
||||
/**
|
||||
* Create a nested scope
|
||||
* The variables in a nested scope are not accessible from the parent scope
|
||||
@ -87,9 +82,15 @@ Scope.prototype.createSymbol = function (name) {
|
||||
*/
|
||||
Scope.prototype.newSymbol = function (name, value) {
|
||||
// create a new symbol
|
||||
var scope = this;
|
||||
var symbol = function () {
|
||||
if (!symbol.value) {
|
||||
throw new Error('Undefined symbol ' + name);
|
||||
// try to resolve again
|
||||
symbol.value = scope.findDef(name);
|
||||
|
||||
if (!symbol.value) {
|
||||
throw new Error('Undefined symbol ' + name);
|
||||
}
|
||||
}
|
||||
if (typeof symbol.value == 'function') {
|
||||
return symbol.value.apply(null, arguments);
|
||||
|
||||
@ -15,3 +15,7 @@ require('./function/probability.js');
|
||||
require('./function/statistics.js');
|
||||
require('./function/trigonometry.js');
|
||||
require('./function/units.js');
|
||||
|
||||
// TODO: test Parser
|
||||
// TODO: test Scope
|
||||
// TODO: test Node, Assignment, Block, Constant, FunctionAssignment, Symbol
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user