Skip to content

Commit 92d9a33

Browse files
committed
Merge branch 'master' into fix-167-global-var-leakage
2 parents 7bec7f8 + d1474b3 commit 92d9a33

11 files changed

+1497
-961
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- "6"
43
- "8"
5-
- "9"
4+
- "10"
5+
- "12"
66

77
script:
88
- npm test

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
---------
33

4+
### 5.0.0
5+
- **Breaking**: Remove Node v6 support. We had to do this because one of our dependencies had security issues and the version with the fix dropped Node v6 as well.
6+
- Update dependencies [#159](https://github.com/jhnns/rewire/pull/159) [#172](https://github.com/jhnns/rewire/issues/172) [#154](https://github.com/jhnns/rewire/issues/154) [#166](https://github.com/jhnns/rewire/issues/166)
7+
8+
### 4.0.1
9+
- Fix a bug where `const` was not properly detected [#139](https://github.com/jhnns/rewire/pull/139)
10+
411
### 4.0.0
512
- **Breaking**: Remove official node v4 support. It probably still works with node v4, but no guarantees anymore.
613
- **Potentially breaking**: Replace babel with regex-based transformation [9b77ed9a293c538ec3eb5160bcb933e012ce517f](https://github.com/jhnns/rewire/commit/9b77ed9a293c538ec3eb5160bcb933e012ce517f).

LICENSE

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
Copyright (c) 2012 Johannes Ewald
2-
3-
Permission is hereby granted, free of charge, to any person obtaining a copy of
4-
this software and associated documentation files (the "Software"), to deal in
5-
the Software without restriction, including without limitation the rights to
6-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7-
the Software, and to permit persons to whom the Software is furnished to do so,
8-
subject to the following conditions:
9-
10-
The above copyright notice and this permission notice shall be included in all
11-
copies or substantial portions of the Software.
12-
13-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
Copyright (c) 2012 Johannes Ewald
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lib/__get__.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
/**
2-
* This function will be stringified and then injected into every rewired module.
3-
* Then you can leak private variables by calling myModule.__get__("myPrivateVar");
4-
*
5-
* All variables within this function are namespaced in the arguments array because every
6-
* var declaration could possibly clash with a variable in the module scope.
7-
*
8-
* @param {!String} name name of the variable to retrieve
9-
* @throws {TypeError}
10-
* @return {*}
11-
*/
12-
function __get__() {
13-
arguments.varName = arguments[0];
14-
if (arguments.varName && typeof arguments.varName === "string") {
15-
return eval(arguments.varName);
16-
} else {
17-
throw new TypeError("__get__ expects a non-empty string");
18-
}
19-
}
20-
1+
/**
2+
* This function will be stringified and then injected into every rewired module.
3+
* Then you can leak private variables by calling myModule.__get__("myPrivateVar");
4+
*
5+
* All variables within this function are namespaced in the arguments array because every
6+
* var declaration could possibly clash with a variable in the module scope.
7+
*
8+
* @param {!String} name name of the variable to retrieve
9+
* @throws {TypeError}
10+
* @return {*}
11+
*/
12+
function __get__() {
13+
arguments.varName = arguments[0];
14+
if (arguments.varName && typeof arguments.varName === "string") {
15+
return eval(arguments.varName);
16+
} else {
17+
throw new TypeError("__get__ expects a non-empty string");
18+
}
19+
}
20+
2121
module.exports = __get__;

lib/detectStrictMode.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
var multiLineComment = /^\s*\/\*.*?\*\//;
2-
var singleLineComment = /^\s*\/\/.*?[\r\n]/;
3-
var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/;
4-
5-
/**
6-
* Returns true if the source code is intended to run in strict mode. Does not detect
7-
* "use strict" if it occurs in a nested function.
8-
*
9-
* @param {String} src
10-
* @return {Boolean}
11-
*/
12-
function detectStrictMode(src) {
13-
var singleLine;
14-
var multiLine;
15-
16-
while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) {
17-
if (singleLine) {
18-
src = src.replace(singleLineComment, "");
19-
}
20-
if (multiLine) {
21-
src = src.replace(multiLineComment, "");
22-
}
23-
}
24-
25-
return strictMode.test(src);
26-
}
27-
28-
module.exports = detectStrictMode;
1+
var multiLineComment = /^\s*\/\*.*?\*\//;
2+
var singleLineComment = /^\s*\/\/.*?[\r\n]/;
3+
var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/;
4+
5+
/**
6+
* Returns true if the source code is intended to run in strict mode. Does not detect
7+
* "use strict" if it occurs in a nested function.
8+
*
9+
* @param {String} src
10+
* @return {Boolean}
11+
*/
12+
function detectStrictMode(src) {
13+
var singleLine;
14+
var multiLine;
15+
16+
while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) {
17+
if (singleLine) {
18+
src = src.replace(singleLineComment, "");
19+
}
20+
if (multiLine) {
21+
src = src.replace(multiLineComment, "");
22+
}
23+
}
24+
25+
return strictMode.test(src);
26+
}
27+
28+
module.exports = detectStrictMode;

lib/moduleEnv.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var moduleWrapper0 = Module.wrapper[0],
4343
// errors anyway, it's probably still a reasonable trade-off.
4444
// Test the regular expresssion at https://regex101.com/r/dvnZPv/2 and also check out testLib/constModule.js.
4545
matchConst = /(^|\s|\}|;)const(\/\*|\s|{)/gm,
46+
// Required for importing modules with shebang declarations, since NodeJS 12.16.0
47+
shebang = /^#!.+/,
4648
nodeRequire,
4749
currentModule;
4850

@@ -123,7 +125,9 @@ function jsExtension(module, filename) {
123125

124126
_compile.call(
125127
module,
126-
content.replace(matchConst, "$1let $2"), // replace const with let, while maintaining the column width
128+
content
129+
.replace(shebang, '') // Remove shebang declarations
130+
.replace(matchConst, "$1let $2"), // replace const with let, while maintaining the column width
127131
filename
128132
);
129133
};

0 commit comments

Comments
 (0)