Skip to content

Commit

Permalink
Small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Oct 28, 2014
1 parent ac3af23 commit ef5f0eb
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions lib/rewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ var Module = require("module"),
detectStrictMode = require("./detectStrictMode.js"),
moduleEnv = require("./moduleEnv.js");

var __get__Src = __get__.toString(),
__set__Src = __set__.toString(),
__with__Src = __with__.toString();
var srcs = {
"__get__": __get__.toString(),
"__set__": __set__.toString(),
"__with__": __with__.toString()
};

/**
* Does actual rewiring the module. For further documentation @see index.js
*/
function internalRewire(parentModulePath, targetPath) {
var targetModule,
prelude,
appendix,
srcs;

srcs = {
"__get__": __get__Src,
"__set__": __set__Src,
"__with__": __with__Src
};
appendix;

// Checking params
if (typeof targetPath !== "string") {
Expand All @@ -48,19 +43,15 @@ 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";

Object.keys(srcs).forEach( function (key) {
var str = [
"Object.defineProperty(module.exports, '",
key,
"', {enumerable: false, value: ",
srcs[key],
"}); "
].join("");
appendix += str;
Object.keys(srcs).forEach(function forEachSrc(key) {
appendix += "Object.defineProperty(module.exports, '" +
key +
"', {enumerable: false, value: " +
srcs[key] +
"}); ";
});

// Check if the module uses the strict mode.
Expand Down

0 comments on commit ef5f0eb

Please sign in to comment.