mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removing the special-case std-reading in favor of '--eval'
This commit is contained in:
parent
42ca566d26
commit
a80b532a05
2 changed files with 15 additions and 19 deletions
|
@ -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 + ")");
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue