benmarch / spel2js

Parse Spring Expression Language in JavaScript
Other
69 stars 19 forks source link

object.property throws null pointer exception. #11

Open chetanjanadri opened 3 years ago

chetanjanadri commented 3 years ago

object.property throws null pointer exception when object is defined and there is no property. Ideally it should not throw an exception instead return null or undefined.

example: let obj = {a: 1, b: 2} is present in the context and when I try to evaluate the expression like "obj.c == 3 ? true : false" it throws null pointer exception.

I can see nullSafeNavigation is false for me. is there a way I can make it true so that it returns null.

krailler commented 3 years ago

Can you try obj?.c == 3 or obj.c? == 3?

Cicko commented 3 years ago

I had that problem too. What I had to do is to manually check for the property before its evaluation and set obj.c = null. This library still has a lot of things to improve. But it seems pretty dead :/