diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 55fdd6ef..00591410 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -724,7 +724,8 @@ module CoffeeScript end def compile(o={}) - write("(#{@expression.compile(super(o))} != undefined)") + val = @expression.compile(super(o)) + write("(typeof #{val} !== 'undefined' && #{val} !== null)") end end diff --git a/test/fixtures/execution/test_existence.coffee b/test/fixtures/execution/test_existence.coffee new file mode 100644 index 00000000..47bfbfab --- /dev/null +++ b/test/fixtures/execution/test_existence.coffee @@ -0,0 +1,5 @@ +print(if my_special_variable? then false else true) + +my_special_variable: false + +print(if my_special_variable? then true else false) \ No newline at end of file