Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Apr 27, 2015
1 parent 88f6024 commit 839e62b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rewire.js
Expand Up @@ -36,8 +36,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();

// 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
// @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
appendix += "})();";

// Check if the module uses the strict mode.
// If so we must ensure that "use strict"; stays at the beginning of the module.
Expand Down

0 comments on commit 839e62b

Please sign in to comment.