如何在coffeescript中启用和谐语法支持? [英] How to enable harmony syntax support in coffeescript?
问题描述
我使用node.js(0.11.13)与 - harmony
标志并使用 function *()
和 yield
关键字。
I used node.js(0.11.13) with --harmony
flag and used function *()
and yield
keywords.
我尝试通过coffeescript帮助简化我在node.js上的开发,效果非常好,但我遇到了 yield
的麻烦,并声明了一个生成器 - 它抱怨'保留关键字yield'。
I tried to simplify my development on node.js with help of coffeescript, so far it works great but I went into troubles with yield
and declaring a generator - it complains about 'reserved keyword yield'.
任何想法?
推荐答案
另一种打开黑色门的方法是: p>
Another way to open the gate to the black dimension is:
co = require 'co'
sleep = require 'co-sleep'
co(`function*(){1`
console.log 'hi!'
`yield sleep(1000)`
console.log 'bye!'
`1}`)()
这似乎是完全有效的咖啡脚本,虽然,webstorm cofeescript插件哭泣的错误,但它的工作原理。
It's seems to be perfectly valid coffee-script, though, webstorm cofeescript plugin cries about errors, but it works.
也可以使用以下解决方案(vanilla coffeescript和gulp):
Also the following solution(vanilla coffeescript and gulp) is possible:
co = require 'co'
sleep = require 'co-sleep'
$ = (cor) -> cor
$yield = (cor) -> cor
do co $ ->
console.log "hi!"
$yield sleep(1000)
console.log "bye!"
gulp.task 'node-js', ->
gulp.src config.srcServerJs, {base: config.srcServerJsBase}
.pipe plumb()
.pipe coffee()
.pipe replace(/\$\(function\(/g, '\$(function*(')
.pipe replace(/\$yield\(/g, 'yield (')
.pipe gulp.dest(config.dstServerJs)
魔术:IDE中没有错误:)
magic: no errors in IDE :)
更新
在尝试并阅读了很多关于咖啡,ecma6及其未来的东西之后,我决定放弃coffeescript,并与traceur支持ECMA6对于node.js和客户端
Update After trying and reading a lot of stuff about coffee, ecma6 and its future I decided to give up on coffeescript and go with ECMA6 with support of traceur for both node.js and client-side
这篇关于如何在coffeescript中启用和谐语法支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!