jsep
jsep copied to clipboard
JSEP does not throw when binary operators are used as unary
Removing the unary operator "+" using jsep.removeUnaryOp("+"), but not removing "+" as a binary operator causes unary expressions such as +1 to be interpreted as binary expressions.
I think the actual issue here is that binary operators can be parsed as unary ones. E.g. jsep("*1") returns:
{
type: "BinaryExpression",
operator: "*",
left: false,
right: {type: "Literal", value: 1, raw: "1"}
type: "BinaryExpression"
}
Is this a bug or a feature? I'm leaning towards the latter, since you can always detect and reject such cases if this behavior is not desirable. What do you think @EricSmekens?