Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2015-04-28 01:46:50 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2015-04-28 01:46:50 +0300
commitbbbd05cab7260f7db9ffcb4adb2e19bdf661bca9 (patch)
treef1d61fe120ad564e911f72f6c8b0b395083731f4 /lib
parent7cd73d4d70f103814035bc8cb5648d71d4960562 (diff)
Fix issue where the strict mode was not detected when a comment was before "strict mode";
Fixes #54
Diffstat (limited to 'lib')
-rw-r--r--lib/detectStrictMode.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/detectStrictMode.js b/lib/detectStrictMode.js
index 35f27fb..57dc14d 100644
--- a/lib/detectStrictMode.js
+++ b/lib/detectStrictMode.js
@@ -1,3 +1,7 @@
+var multiLineComment = /^\s*\/\*.*?\*\//;
+var singleLineComment = /^\s*\/\/.*?[\r\n]/;
+var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/;
+
/**
* Returns true if the source code is intended to run in strict mode. Does not detect
* "use strict" if it occurs in a nested function.
@@ -6,7 +10,19 @@
* @return {Boolean}
*/
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; \ No newline at end of file
+module.exports = detectStrictMode;