如何在coffeescript中启用和声语法支持?

let*_*4be 5 javascript yield coffeescript ecmascript-harmony

我用的Node.js(0.11.13)与--harmony标志和使用function *()yield关键字.

我试图在coffeescript的帮助下简化我在node.js上的开发,到目前为止它工作得很好但我遇到麻烦yield并声明了一个生成器 - 它抱怨'保留关键字产量'.

有任何想法吗?

let*_*4be 5

打开黑色维度的另一种方法是:

co = require 'co'
sleep = require 'co-sleep'

co(`function*(){1`
    console.log 'hi!'
    `yield sleep(1000)`
    console.log 'bye!'
`1}`)()
Run Code Online (Sandbox Code Playgroud)

它似乎是完全有效的咖啡脚本,但是,webstorm cofeescript插件会对错误发出呐喊,但它确实有效.

以下解决方案(香草coffeescript和gulp)也是可能的:

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)
Run Code Online (Sandbox Code Playgroud)

魔术:IDE中没有错误:)

更新 尝试和阅读了大量有关咖啡,ecma6和未来的东西后,我决定放弃对CoffeeScript的去与ECMA6与支持traceur的两个node.js的和客户端