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

Commit09dc5be

Browse files
committed
Fix shadowing of internalmodule,exports andrequire when a global counterpart exists
@seejhnns/rewire-webpack#6
1 parent1eede09 commit09dc5be

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎lib/getImportGlobalsSrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function getImportGlobalsSrc(ignore) {
1616
ignore=ignore||[];
1717
// global itself can't be overridden because it's the only reference to our real global objects
1818
ignore.push("global");
19+
// ignore 'module', 'exports' and 'require' on the global scope, because otherwise our code would
20+
// shadow the module-internal variables
21+
//@see https://github.com/jhnns/rewire-webpack/pull/6
22+
ignore.push("module","exports","require");
1923

2024
for(keyinglobalObj){/* jshint forin: false */
2125
if(ignore.indexOf(key)!==-1){

‎test/getImportGlobalsSrc.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@ describe("getImportGlobalsSrc", function () {
77
varcontext={
88
global:global
99
},
10+
expectedGlobals,
1011
src,
11-
actualGlobals,
12-
expectedGlobals=Object.keys(global);
12+
actualGlobals;
13+
14+
// Temporarily set module-internal variables on the global scope to check if getImportGlobalsSrc()
15+
// ignores them properly
16+
global.module=module;
17+
global.exports=exports;
18+
global.require=require;
1319

1420
src=getImportGlobalsSrc();
21+
22+
deleteglobal.module;
23+
deleteglobal.exports;
24+
deleteglobal.require;
25+
26+
expectedGlobals=Object.keys(global);
27+
1528
vm.runInNewContext(src,context);
1629
actualGlobals=Object.keys(context).filter(function(key){
1730
// node v0.10 does not set a constructor property on the context

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp