merging node into master -- you can now pass the --narwhal flag to use narwhal instead. All tests are executing successfully against both Node.js and Narwhal/Rhino backends

This commit is contained in:
Jeremy Ashkenas
2010-02-07 12:52:07 -05:00
61 changed files with 3918 additions and 1236 deletions

45
src/coffee-script.coffee Normal file
View File

@@ -0,0 +1,45 @@
# Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
path: require('path')
# The path to the CoffeeScript executable.
compiler: path.normalize(path.dirname(__filename) + '/../../bin/coffee')
# Compile a string over stdin, with global variables, for the REPL.
exports.compile: (code, callback) ->
js: ''
coffee: process.createChildProcess compiler, ['--eval', '--no-wrap', '--globals']
coffee.addListener 'output', (results) ->
js += results if results?
coffee.addListener 'exit', ->
callback(js)
coffee.write(code)
coffee.close()
# Compile a list of CoffeeScript files on disk.
exports.compile_files: (paths, callback) ->
js: ''
coffee: process.createChildProcess compiler, ['--print'].concat(paths)
coffee.addListener 'output', (results) ->
js += results if results?
# NB: we have to add a mutex to make sure it doesn't get called twice.
exit_ran: false
coffee.addListener 'exit', ->
return if exit_ran
exit_ran: true
callback(js)
coffee.addListener 'error', (message) ->
return unless message
puts message
throw new Error "CoffeeScript compile error"