Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rewire.js')
-rw-r--r--lib/rewire.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/rewire.js b/lib/rewire.js
index 086cc27..29ad93f 100644
--- a/lib/rewire.js
+++ b/lib/rewire.js
@@ -9,7 +9,7 @@ var Module = require("module"),
var __get__Src = __get__.toString(),
__set__Src = __set__.toString(),
- __with_Src = __with__.toString();
+ __with__Src = __with__.toString();
/**
* Does actual rewiring the module. For further documentation @see index.js
@@ -18,7 +18,13 @@ function internalRewire(parentModulePath, targetPath) {
var targetModule,
prelude,
appendix,
- src;
+ srcs;
+
+ srcs = {
+ "__get__": __get__Src,
+ "__set__": __set__Src,
+ "__with__": __with__Src
+ };
// Checking params
if (typeof targetPath !== "string") {
@@ -42,11 +48,20 @@ function internalRewire(parentModulePath, targetPath) {
// We prepend a list of all globals declared with var so they can be overridden (without changing original globals)
prelude = getImportGlobalsSrc();
+
// We append our special setter and getter.
appendix = "\n";
- appendix += "module.exports.__set__ = " + __set__Src + "; ";
- appendix += "module.exports.__get__ = " + __get__Src + "; ";
- appendix += "module.exports.__with__ = " + __with_Src + "; ";
+
+ Object.keys(srcs).forEach( function (key) {
+ var str = [
+ "Object.defineProperty(module.exports, '",
+ key,
+ "', {enumerable: false, value: ",
+ srcs[key],
+ "}); "
+ ].join("");
+ appendix += str;
+ });
// Check if the module uses the strict mode.
// If so we must ensure that "use strict"; stays at the beginning of the module.