1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

unifying all of the server-side evaluation under CoffeeScript.run -- this means that __filename and __dirname and relative requires should work from all angles under Node.js

This commit is contained in:
Jeremy Ashkenas 2010-03-07 21:49:08 -05:00
parent 0bc7719572
commit 06b50ecb98
9 changed files with 43 additions and 27 deletions

View file

@ -80,13 +80,15 @@
// in common. If evaluating the script directly sets `__filename`, `__dirname`
// and `module.filename` to be correct relative to the script's path.
compile_script = function compile_script(source, code) {
var __dirname, __filename, js, o;
var js, o;
o = options;
try {
if (o.tokens) {
return print_tokens(CoffeeScript.tokens(code));
} else if (o.nodes) {
return puts(CoffeeScript.nodes(code).toString());
} else if (o.run) {
return CoffeeScript.run(code, source, compile_options());
} else {
js = CoffeeScript.compile(code, compile_options());
if (o.compile) {
@ -95,11 +97,6 @@
return lint(js);
} else if (o.print || o.eval) {
return print(js);
} else {
__filename = source;
__dirname = path.dirname(source);
module.filename = source;
return eval(js);
}
}
} catch (err) {
@ -199,8 +196,10 @@
// Use the [OptionParser module](optparse.html) to extract all options from
// `process.argv` that are specified in `SWITCHES`.
parse_options = function parse_options() {
var o;
option_parser = new optparse.OptionParser(SWITCHES, BANNER);
options = option_parser.parse(process.argv);
o = (options = option_parser.parse(process.argv));
options.run = !(o.compile || o.print || o.lint || o.eval);
return sources = options.arguments.slice(2, options.arguments.length);
};
// The compile-time options to pass to the CoffeeScript compiler.