Skip to content

Commit

Permalink
Numbas.jme.display.simplify returns '' if expression is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Aug 15, 2023
1 parent 6387d40 commit 8311eeb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions runtime/scripts/jme-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ jme.display = /** @lends Numbas.jme.display */ {
parser = parser || Numbas.jme.standardParser;
try {
var exprTree = parser.compile(expr,{},true); //compile the expression to a tree. notypecheck is true, so undefined function names can be used.
if(!exprTree) {
return '';
}
return jme.display.simplifyTree(exprTree,ruleset,scope); // simplify the tree
} catch(e) {
//e.message += '\nSimplifying expression failed. Expression was: '+expr;
Expand Down
3 changes: 3 additions & 0 deletions tests/jme-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -15914,6 +15914,9 @@ jme.display = /** @lends Numbas.jme.display */ {
parser = parser || Numbas.jme.standardParser;
try {
var exprTree = parser.compile(expr,{},true); //compile the expression to a tree. notypecheck is true, so undefined function names can be used.
if(!exprTree) {
return '';
}
return jme.display.simplifyTree(exprTree,ruleset,scope); // simplify the tree
} catch(e) {
//e.message += '\nSimplifying expression failed. Expression was: '+expr;
Expand Down
3 changes: 3 additions & 0 deletions tests/numbas-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -15903,6 +15903,9 @@ jme.display = /** @lends Numbas.jme.display */ {
parser = parser || Numbas.jme.standardParser;
try {
var exprTree = parser.compile(expr,{},true); //compile the expression to a tree. notypecheck is true, so undefined function names can be used.
if(!exprTree) {
return '';
}
return jme.display.simplifyTree(exprTree,ruleset,scope); // simplify the tree
} catch(e) {
//e.message += '\nSimplifying expression failed. Expression was: '+expr;
Expand Down

0 comments on commit 8311eeb

Please sign in to comment.