jashkenas/coffee-script — Issue #2155: existential ?= operator causes weird behavior if setting to a closure
Author: gfodor
Created: 2012-02-28 07:39:36+00:00
State: open

I'm seeing some weird behavior if using ?= to set a local var to a closure. I narrowed it down to a small case:

Coffeescript

-> x ?= (-> if true then "hi")

Compiled (wrong?)

(function() {
(function() {
return typeof x !== "undefined" && x !== null ? x : x = (function() {
if (!true) {} // BUG
});
});
}).call(this);

vs a working version that doesn't use ?=,

Coffeescript

-> x = (-> if true then "hi")

Compiled (correct)

(function() {
(function() {
var x;
return x = (function() {
if (true) return "hi";
});
});
}).call(this);