js2coffee / js2coffee

Compile JavaScript to CoffeeScript

Home Page:http://js2.coffee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wrong conversion of IIFE syntax

jpillora opened this issue · comments

window.foo = (function() {
    return 42;
}());

converts to:

window.foo = (->
  42
())

end braces should be: )()

from #150
other syntax, but also broken:

foo = function(){
  thing();
}();

gets compiled to

foo = ->
  thing()
()

when it should be

foo = (->
  thing()
)()

Workaround

Use this syntax and you're safe in js2coffee

// jQuery syntax: (outies)
(function (w,d) {
  // your code here
})(window, document);

now gets converted to:

window.foo = do ->
  42

demo

nice work with the new version, what's the purpose of the "preview" window? did people not like the two-way conversion?

mostly i felt it was ambiguous—you weren't sure if you were in js->coffee mode or coffee->js mode. moreso, i dont want to encourage the behavior of getting CoffeeScript output and passing it back to js2coffee :)