TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
573 stars 93 forks source link

Problem with inline if #121

Open ablsc opened 2 years ago

ablsc commented 2 years ago

Didn't see anyone else raising this one, so here goes

Following works

var jexl = require("jexl")

jexl.addFunction("parseInt", (arg) => Number.parseInt(arg));
jexl.addFunction("isNaN", (arg) => Number.isNaN(arg));

jexl.evalSync("isNaN(parseInt(size)) == true ? 0 : parseInt(size)", { "size": "" });

Following throws the error: Token ? (question) unexpected in expression: isNaN(parseInt(size)) ?

var jexl = require("jexl")

jexl.addFunction("parseInt", (arg) => Number.parseInt(arg));
jexl.addFunction("isNaN", (arg) => Number.isNaN(arg));

jexl.evalSync("isNaN(parseInt(size)) ? 0 : parseInt(size)", { "size": "" });
cmdcolin commented 2 years ago

I ran into this also, glad there is a workaround with == true, but that is kind of odd