diff options
-rw-r--r-- | lib/rewire.js | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/rewire.js b/lib/rewire.js index 6d52aac..c52bbeb 100644 --- a/lib/rewire.js +++ b/lib/rewire.js @@ -36,19 +36,14 @@ 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(); - // The module src is wrapped inside a self-executing function. - // This is necessary to separate the module src from the preceding importGlobalsSrc, - // because the module src can be in strict mode. - // In strict mode eval() can only declare vars in the current scope. In this case our setters - // and getters won't work. - // @see http://whereswalden.com/2011/01/10/new-es5-strict-mode-support-new-vars-created-by-strict-mode-eval-code-are-local-to-that-code-only/ - // It also circumvents a problem with identical global variables and function declarations + // Wrap module src inside IIFE so that function declarations do not clash with global variables // @see https://github.com/jhnns/rewire/issues/56 prelude += "(function () { "; // We append our special setter and getter. appendix = "\n" + getDefinePropertySrc(); - // End of self-executing function + + // End of IIFE appendix += "})();"; // Check if the module uses the strict mode. |