Created
March 29, 2012 18:02
-
-
Save isaacs/2241076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/module.js b/lib/module.js | |
index f6f6285..ea5a18f 100644 | |
--- a/lib/module.js | |
+++ b/lib/module.js | |
@@ -440,8 +440,22 @@ Module.prototype._compile = function(content, filename) { | |
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0); | |
} | |
} | |
- var args = [self.exports, require, self, filename, dirname]; | |
- return compiledWrapper.apply(self.exports, args); | |
+ var exports = self.exports; | |
+ var args = [exports, require, self, filename, dirname]; | |
+ var ret = compiledWrapper.apply(self.exports, args); | |
+ | |
+ // if the wrapper returns a value, and has not already | |
+ // set module.exports to something different, and has not | |
+ // added any keys to exports, then use the return value as | |
+ // the exported module result. | |
+ if (ret !== undefined && self.exports === exports && | |
+ Object.keys(exports).length === 0) { | |
+ self.exports = ret; | |
+ } | |
+ | |
+ // always return the return of the compilation. | |
+ // this is needed for node --eval | |
+ return ret; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment