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

Skip to content

Commit 5b237d9

Browse files
committed
fix leak, add test, for jhnns#33
1 parent 93d3907 commit 5b237d9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/rewire.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function internalRewire(parentModulePath, targetPath) {
5656

5757
// Check if the module uses the strict mode.
5858
// If so we must ensure that "use strict"; stays at the beginning of the module.
59-
src = fs.readFileSync(targetPath, "utf8");
59+
var src = fs.readFileSync(targetPath, "utf8");
6060
if (detectStrictMode(src) === true) {
6161
prelude = ' "use strict"; ' + prelude;
6262
}

test/rewire.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ describe("rewire", function () {
3131
});
3232
expect(coffeeModule.readFileSync()).to.be("It works!");
3333
});
34+
it("should keep src variable in function scope", function () {
35+
//expect(src).to.be(undefined);
36+
// detectStrictMode();
37+
// console.dir(global);
38+
expect(global.src).to.be(undefined);
39+
});
3440
});

0 commit comments

Comments
 (0)