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

@@ -35,6 +35,14 @@ exports.tokens: (code) ->
exports.nodes: (code) ->
parser.parse lexer.tokenize code
# Compile and execute a string of CoffeeScript (on the server), correctly
# setting `__filename`, `__dirname`, and relative `require()`.
exports.run: (code, source, options) ->
__filename: source
__dirname: path.dirname source
module.filename: source
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".