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

Renaming root to mainModule in run method

This commit is contained in:
Trevor Burnham 2011-05-03 15:53:10 -04:00
parent ea4a723379
commit fa2ed81485
2 changed files with 16 additions and 16 deletions

View file

@ -45,20 +45,20 @@
}
};
exports.run = function(code, options) {
var Module, root;
root = require.main;
root.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
if (root.moduleCache) {
root.moduleCache = {};
var Module, mainModule;
mainModule = require.main;
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
if (mainModule.moduleCache) {
mainModule.moduleCache = {};
}
if (process.binding('natives').module) {
Module = require('module').Module;
root.paths = Module._nodeModulePaths(path.dirname(options.filename));
mainModule.paths = Module._nodeModulePaths(path.dirname(options.filename));
}
if (path.extname(root.filename) !== '.coffee' || require.extensions) {
return root._compile(compile(code, options), root.filename);
if (path.extname(mainModule.filename) !== '.coffee' || require.extensions) {
return mainModule._compile(compile(code, options), mainModule.filename);
} else {
return root._compile(code, root.filename);
return mainModule._compile(code, mainModule.filename);
}
};
exports.eval = function(code, options) {

View file

@ -54,25 +54,25 @@ exports.nodes = (source, options) ->
# Compile and execute a string of CoffeeScript (on the server), correctly
# setting `__filename`, `__dirname`, and relative `require()`.
exports.run = (code, options) ->
root = require.main
mainModule = require.main
# Set the filename.
root.filename = process.argv[1] =
mainModule.filename = process.argv[1] =
if options.filename then fs.realpathSync(options.filename) else '.'
# Clear the module cache.
root.moduleCache = {} if root.moduleCache
mainModule.moduleCache = {} if mainModule.moduleCache
# Assign paths for node_modules loading
if process.binding('natives').module
{Module} = require 'module'
root.paths = Module._nodeModulePaths path.dirname options.filename
mainModule.paths = Module._nodeModulePaths path.dirname options.filename
# Compile.
if path.extname(root.filename) isnt '.coffee' or require.extensions
root._compile compile(code, options), root.filename
if path.extname(mainModule.filename) isnt '.coffee' or require.extensions
mainModule._compile compile(code, options), mainModule.filename
else
root._compile code, root.filename
mainModule._compile code, mainModule.filename
# Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
# The CoffeeScript REPL uses this to run the input.