jsep icon indicating copy to clipboard operation
jsep copied to clipboard

JSEP does not throw when binary operators are used as unary

Open ggetz opened this issue 10 years ago • 1 comments

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.

ggetz avatar Feb 17 '16 14:02 ggetz

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?

LeaVerou avatar Sep 18 '17 21:09 LeaVerou