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

@ -34,6 +34,15 @@
exports.nodes = function nodes(code) {
return parser.parse(lexer.tokenize(code));
};
// Compile and execute a string of CoffeeScript (on the server), correctly
// setting `__filename`, `__dirname`, and relative `require()`.
exports.run = function run(code, source, options) {
var __dirname, __filename;
__filename = source;
__dirname = path.dirname(source);
module.filename = source;
return eval(exports.compile(code, options));
};
// The real Lexer produces a generic stream of tokens. This object provides a
// thin wrapper around it, compatible with the Jison API. We can then pass it
// directly as a "Jison lexer".