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:
authorJohannes Ewald <johannes.ewald@peerigon.com>2014-11-04 11:51:18 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2014-11-04 11:51:18 +0300
commit8b8fde8dc999051df0c5f70a4c4407859e3ddae0 (patch)
tree9d51e784ac4799b094ed91936fb8e31987ba3dcf /lib
parent09dc5be9128bb07766b01bda9e053046478f9a03 (diff)
Put src generator into dedicated module `getDefinePropertySrc()`
Diffstat (limited to 'lib')
-rw-r--r--lib/getDefinePropertySrc.js27
-rw-r--r--lib/rewire.js20
2 files changed, 29 insertions, 18 deletions
diff --git a/lib/getDefinePropertySrc.js b/lib/getDefinePropertySrc.js
new file mode 100644
index 0000000..95dd9f2
--- /dev/null
+++ b/lib/getDefinePropertySrc.js
@@ -0,0 +1,27 @@
+"use strict";
+
+var __get__ = require("./__get__.js");
+var __set__ = require ("./__set__.js");
+var __with__ = require("./__with__.js");
+
+var srcs = {
+ "__get__": __get__.toString(),
+ "__set__": __set__.toString(),
+ "__with__": __with__.toString()
+};
+
+function getDefinePropertySrc() {
+ var src;
+
+ src = Object.keys(srcs).reduce(function forEachSrc(preValue, value) {
+ return preValue += "Object.defineProperty(module.exports, '" +
+ value +
+ "', {enumerable: false, value: " +
+ srcs[value] +
+ "}); ";
+ }, "");
+
+ return src;
+}
+
+module.exports = getDefinePropertySrc; \ No newline at end of file
diff --git a/lib/rewire.js b/lib/rewire.js
index 167d7b3..7d0b138 100644
--- a/lib/rewire.js
+++ b/lib/rewire.js
@@ -1,18 +1,10 @@
var Module = require("module"),
fs = require("fs"),
- __get__ = require("./__get__.js"),
- __set__ = require ("./__set__.js"),
- __with__ = require("./__with__.js"),
getImportGlobalsSrc = require("./getImportGlobalsSrc.js"),
+ getDefinePropertySrc = require("./getDefinePropertySrc.js"),
detectStrictMode = require("./detectStrictMode.js"),
moduleEnv = require("./moduleEnv.js");
-var srcs = {
- "__get__": __get__.toString(),
- "__set__": __set__.toString(),
- "__with__": __with__.toString()
-};
-
/**
* Does actual rewiring the module. For further documentation @see index.js
*/
@@ -45,15 +37,7 @@ function internalRewire(parentModulePath, targetPath) {
prelude = getImportGlobalsSrc();
// We append our special setter and getter.
- appendix = "\n";
-
- Object.keys(srcs).forEach(function forEachSrc(key) {
- appendix += "Object.defineProperty(module.exports, '" +
- key +
- "', {enumerable: false, value: " +
- srcs[key] +
- "}); ";
- });
+ appendix = "\n" + getDefinePropertySrc();
// Check if the module uses the strict mode.
// If so we must ensure that "use strict"; stays at the beginning of the module.