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:
parent
0bc7719572
commit
06b50ecb98
9 changed files with 43 additions and 27 deletions
|
@ -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".
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue