diff options
Diffstat (limited to 'lib/detectStrictMode.js')
-rw-r--r-- | lib/detectStrictMode.js | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/detectStrictMode.js b/lib/detectStrictMode.js index 57dc14d..30f59fd 100644 --- a/lib/detectStrictMode.js +++ b/lib/detectStrictMode.js @@ -1,28 +1,28 @@ -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.
- *
- * @param {String} src
- * @return {Boolean}
- */
-function detectStrictMode(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;
+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. + * + * @param {String} src + * @return {Boolean} + */ +function detectStrictMode(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; |