1 | var multiLineComment = /^\s*\/\*.*?\*\//;
|
2 | var singleLineComment = /^\s*\/\/.*?[\r\n]/;
|
3 | var strictMode = /^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
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;
|