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
path: root/lib
diff options
context:
space:
mode:
authorNick Bottomley <nhbottomley@gmail.com>2014-10-25 04:16:54 +0400
committerNick Bottomley <nhbottomley@gmail.com>2014-10-25 04:16:54 +0400
commitad7056daa37b376bdddd990ad117fdd271dbda8d (patch)
tree7add27ff89122ca63ec6bcc132864b3a30cf8c23 /lib
parent3e06f8784c0a08bf3dacf8eb15aff1b6902394a9 (diff)
rewire methods as non-enumerable
Diffstat (limited to 'lib')
-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.