Comparing version 2.3.2 to 2.3.3
Changelog | ||
--------- | ||
### 2.3.3 | ||
- Fix issue where the strict mode was not detected when a comment was before "strict mode"; [#54](https://github.com/jhnns/rewire/issues/54) | ||
### 2.3.2 | ||
@@ -5,0 +8,0 @@ - Fix a problem when a function declaration had the same name as a global variable [#56](https://github.com/jhnns/rewire/issues/56) |
@@ -0,1 +1,5 @@ | ||
var multiLineComment = /^\s*\/\*.*?\*\//; | ||
var singleLineComment = /^\s*\/\/.*?[\r\n]/; | ||
var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/; | ||
/** | ||
@@ -9,5 +13,17 @@ * Returns true if the source code is intended to run in strict mode. Does not detect | ||
function detectStrictMode(src) { | ||
return (/^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/g).test(src); | ||
var singleLine; | ||
var multiLine; | ||
while ((singleLine = singleLineComment.test(src)) || (multiLine = multiLineComment.test(src))) { | ||
if (singleLine) { | ||
src = src.replace(singleLineComment, ""); | ||
} | ||
if (multiLine) { | ||
src = src.replace(multiLineComment, ""); | ||
} | ||
} | ||
return strictMode.test(src); | ||
} | ||
module.exports = detectStrictMode; | ||
module.exports = detectStrictMode; |
{ | ||
"name": "rewire", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "Easy dependency injection for node.js unit testing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26499
337