cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
375 stars 47 forks source link

Error subexpressions not found with getSubexpression (or errors getter) #58

Closed shidel-dev closed 1 year ago

shidel-dev commented 2 years ago

In the following example I would expect the errors getter to not return an empty value

parsed = computeEngine.parse("1+++");
parsed.isValid
=> true

evaluated = parsed.evaluate()
evaluated.isValid
=> false

evaluated.errors
=> []

JSON.stringify(evaluated.toJSON())
=> `["Add",["Increment",1],["Error","'missing'",["Latex","'+'"]]]`
hanshs commented 2 years ago

I'll use this issue, I have a similar case where the json includes an error, but the errors getter returns empty

boxed = ce.parse('x=')
boxed.json // ["Equal","x",["Error","'missing'"]]
boxed.errors // []
arnog commented 1 year ago

Pro tip: JSON.stringify(evaluated.toJSON()) is equivalent to evaluated.toString().