Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef5f0eb

Browse files
committed
Small refactorings
1 parent ac3af23 commit ef5f0eb

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

lib/rewire.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@ var Module = require("module"),
77
detectStrictMode = require("./detectStrictMode.js"),
88
moduleEnv = require("./moduleEnv.js");
99

10-
var __get__Src = __get__.toString(),
11-
__set__Src = __set__.toString(),
12-
__with__Src = __with__.toString();
10+
var srcs = {
11+
"__get__": __get__.toString(),
12+
"__set__": __set__.toString(),
13+
"__with__": __with__.toString()
14+
};
1315

1416
/**
1517
* Does actual rewiring the module. For further documentation @see index.js
1618
*/
1719
function internalRewire(parentModulePath, targetPath) {
1820
var targetModule,
1921
prelude,
20-
appendix,
21-
srcs;
22-
23-
srcs = {
24-
"__get__": __get__Src,
25-
"__set__": __set__Src,
26-
"__with__": __with__Src
27-
};
22+
appendix;
2823

2924
// Checking params
3025
if (typeof targetPath !== "string") {
@@ -48,19 +43,15 @@ function internalRewire(parentModulePath, targetPath) {
4843
// We prepend a list of all globals declared with var so they can be overridden (without changing original globals)
4944
prelude = getImportGlobalsSrc();
5045

51-
5246
// We append our special setter and getter.
5347
appendix = "\n";
5448

55-
Object.keys(srcs).forEach( function (key) {
56-
var str = [
57-
"Object.defineProperty(module.exports, '",
58-
key,
59-
"', {enumerable: false, value: ",
60-
srcs[key],
61-
"}); "
62-
].join("");
63-
appendix += str;
49+
Object.keys(srcs).forEach(function forEachSrc(key) {
50+
appendix += "Object.defineProperty(module.exports, '" +
51+
key +
52+
"', {enumerable: false, value: " +
53+
srcs[key] +
54+
"}); ";
6455
});
6556

6657
// Check if the module uses the strict mode.

0 commit comments

Comments
 (0)