diff --git a/lib-js/coffee-script.js b/lib-js/coffee-script.js index 266f1309..dc7c32a0 100644 --- a/lib-js/coffee-script.js +++ b/lib-js/coffee-script.js @@ -3,14 +3,14 @@ var OS = require("os"); exports.run = function(args) { // TODO: non-REPL - + args.shift(); - + if (args.length) { require(FILE.absolute(args[0])); return; } - + while (true) { try { @@ -20,7 +20,7 @@ exports.run = function(args) { if (result !== undefined) print(result); - + } catch (e) { print(e); } @@ -41,7 +41,7 @@ exports.compileFile = function(path) { } exports.compile = function(source) { - var coffee = OS.popen([coffeePath, "-"]); + var coffee = OS.popen([coffeePath, "-e"]); coffee.stdin.write(source).flush().close(); @@ -55,30 +55,30 @@ exports.compile = function(source) { // implemented as a call to coffee and objj_eval/make_narwhal_factory exports.cs_eval = function(source) { init(); - + var code = exports.compile(source); - + // strip the function wrapper, we add our own. // TODO: this is very fragile code = code.split("\n").slice(1,-2).join("\n"); - + return eval(code); } exports.make_narwhal_factory = function(path) { init(); - + var code = exports.compileFile(path); - + // strip the function wrapper, we add our own. // TODO: this is very fragile code = code.split("\n").slice(1,-2).join("\n"); - + var factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}"; if (system.engine === "rhino") return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null); - + // eval requires parenthesis, but parenthesis break compileFunction. else return eval("(" + factoryText + ")"); diff --git a/lib/coffee_script/command_line.rb b/lib/coffee_script/command_line.rb index 8fef1943..eb749d93 100644 --- a/lib/coffee_script/command_line.rb +++ b/lib/coffee_script/command_line.rb @@ -41,15 +41,11 @@ Usage: # Compiles (or partially compiles) the source CoffeeScript file, returning # the desired JS, tokens, or lint results. def compile_javascript(source) - if source == "-" - script = STDIN.read - else - script = File.read(source) - end + script = File.read(source) return tokens(script) if @options[:tokens] js = compile(script, source) return unless js - return puts(js) if @options[:print] or source == "-" + return puts(js) if @options[:print] return lint(js) if @options[:lint] File.open(path_for(source), 'w+') {|f| f.write(js) } end @@ -77,7 +73,7 @@ Usage: # Ensure that all of the source files exist. def check_sources usage if @sources.empty? - missing = @sources.detect {|s| !File.exists?(s) and s != "-" } + missing = @sources.detect {|s| !File.exists?(s) } if missing STDERR.puts("File not found: '#{missing}'") exit(1)