got coffeescript compiling in the browser

This commit is contained in:
Jeremy Ashkenas
2010-02-13 15:25:04 -05:00
parent 79bb0da153
commit a90bf75395
15 changed files with 140 additions and 86 deletions

View File

@@ -1,8 +1,15 @@
(function(){
var compiler, lexer, parser, path;
process.mixin(require('./nodes'));
lexer = new (require('./lexer').Lexer)();
parser = require('./parser').parser;
if ((typeof process !== "undefined" && process !== null)) {
process.mixin(require('./nodes'));
path = require('path');
lexer = new (require('./lexer').Lexer)();
parser = require('./parser').parser;
} else {
this.exports = this;
lexer = new Lexer();
parser = exports.parser;
}
// Thin wrapper for Jison compatibility around the real lexer.
parser.lexer = {
lex: function lex() {
@@ -38,15 +45,15 @@
return parser.parse(lexer.tokenize(code));
};
//---------- Below this line is obsolete, for the Ruby compiler. ----------------
// 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');
compiler = function compiler() {
return path.normalize(path.dirname(__filename) + '/../../bin/coffee');
};
// Compile a string over stdin, with global variables, for the REPL.
exports.ruby_compile = function ruby_compile(code, callback) {
var coffee, js;
js = '';
coffee = process.createChildProcess(compiler, ['--eval', '--no-wrap', '--globals']);
coffee = process.createChildProcess(compiler(), ['--eval', '--no-wrap', '--globals']);
coffee.addListener('output', function(results) {
if ((typeof results !== "undefined" && results !== null)) {
return js += results;
@@ -62,7 +69,7 @@
exports.ruby_compile_files = function ruby_compile_files(paths, callback) {
var coffee, exit_ran, js;
js = '';
coffee = process.createChildProcess(compiler, ['--print'].concat(paths));
coffee = process.createChildProcess(compiler(), ['--print'].concat(paths));
coffee.addListener('output', function(results) {
if ((typeof results !== "undefined" && results !== null)) {
return js += results;