Weird transpiling of coffeescript to javascript
Hi,
I just setup the webstorm environement to work with coffeescript transpiling to javascript, this is installing node,npm,coffeescript on my mac.
All seems fine, I created a coffeescript file, added a watcher to it which creates and updates the corresponding js file.
I tried with very simple code in coffeescript file, declaring variables:
coffeescript code:
myamount = 5
javascript code:
// Generated by CoffeeScript 1.6.3
(function() {
var myamount;
myamount = 5;
}).call(this);
Why does it put everything into a function ?? There is no way I can get rid of this function
请先登录再写评论。
Hello!
this is the way the coffeescripty transpiler works - it wraps each file in a function. See http://stackoverflow.com/questions/7082373/coffeescript-wrapping-files-in-a-function for more info
You can modify the 'arguments' field of your file watcher to pass a --bare option to compiler to avoid this wrapping:
'-b', '--bare', 'compile without a top-level function wrapper'
Thanks for your answer.
And to enable the bare option, should I just run coffee --bare from the mac command line ? Or should I recompile it ?
no and no. You need to add --bare to transpiler arguments in your file watcher (Settings/File Watchers, select you coffeescript watcher)
Attachment(s):
bare.png