Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb752ffb

Browse files
committed
Should not blow up on modules that export primitives
1 parenta4fc3a8 commitb752ffb

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

‎lib/getDefinePropertySrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ var srcs = {
1111
};
1212

1313
functiongetDefinePropertySrc(){
14-
varsrc;
14+
varsrc="if (typeof(module.exports) === 'function' || \n"+
15+
"(typeof(module.exports) === 'object' && module.exports !== null && Object.isExtensible(module.exports))) {\n";
1516

16-
src=Object.keys(srcs).reduce(functionforEachSrc(preValue,value){
17+
src+=Object.keys(srcs).reduce(functionforEachSrc(preValue,value){
1718
returnpreValue+="Object.defineProperty(module.exports, '"+
1819
value+
1920
"', {enumerable: false, value: "+
@@ -22,6 +23,8 @@ function getDefinePropertySrc() {
2223
"writable: true}); ";
2324
},"");
2425

26+
src+="\n}";
27+
2528
returnsrc;
2629
}
2730

‎testLib/boolean.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports=true;

‎testLib/null.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports=null;

‎testLib/sealedObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
varobj={};
2+
Object.seal(obj);
3+
4+
module.exports=obj;

‎testLib/sharedTestCases.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
220220
expect(rewired.__get__("someVar")).to.be("hello");
221221
});
222222

223+
it("should not be a problem to have a module that exports a boolean",function(){
224+
expect(function(){
225+
varrewired=rewire("./boolean.js");
226+
}).to.not.throwException();
227+
});
228+
229+
it("should not be a problem to have a module that exports null",function(){
230+
expect(function(){
231+
varrewired=rewire("./null.js");
232+
}).to.not.throwException();
233+
});
234+
235+
it("should not be a problem to have a module that exports a sealed object",function(){
236+
expect(function(){
237+
varrewired=rewire("./sealedObject.js");
238+
}).to.not.throwException();
239+
});
240+
223241
it("should not influence the original require if nothing has been required within the rewired module",function(){
224242
rewire("./emptyModule.js");// nothing happens here because emptyModule doesn't require anything
225243
expect(require("./moduleA.js").__set__).to.be(undefined);// if restoring the original node require didn't worked, the module would have a setter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp