()
| 3909 | } |
| 3910 | |
| 3911 | function advanceSlash() { |
| 3912 | var prevToken, |
| 3913 | checkToken; |
| 3914 | // Using the following algorithm: |
| 3915 | // https://github.com/mozilla/sweet.js/wiki/design |
| 3916 | prevToken = extra.tokens[extra.tokens.length - 1]; |
| 3917 | if (!prevToken) { |
| 3918 | // Nothing before that: it cannot be a division. |
| 3919 | return scanRegExp(); |
| 3920 | } |
| 3921 | if (prevToken.type === 'Punctuator') { |
| 3922 | if (prevToken.value === ')') { |
| 3923 | checkToken = extra.tokens[extra.openParenToken - 1]; |
| 3924 | if (checkToken && |
| 3925 | checkToken.type === 'Keyword' && |
| 3926 | (checkToken.value === 'if' || |
| 3927 | checkToken.value === 'while' || |
| 3928 | checkToken.value === 'for' || |
| 3929 | checkToken.value === 'with')) { |
| 3930 | return scanRegExp(); |
| 3931 | } |
| 3932 | return scanPunctuator(); |
| 3933 | } |
| 3934 | if (prevToken.value === '}') { |
| 3935 | // Dividing a function by anything makes little sense, |
| 3936 | // but we have to check for that. |
| 3937 | if (extra.tokens[extra.openCurlyToken - 3] && |
| 3938 | extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') { |
| 3939 | // Anonymous function. |
| 3940 | checkToken = extra.tokens[extra.openCurlyToken - 4]; |
| 3941 | if (!checkToken) { |
| 3942 | return scanPunctuator(); |
| 3943 | } |
| 3944 | } else if (extra.tokens[extra.openCurlyToken - 4] && |
| 3945 | extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') { |
| 3946 | // Named function. |
| 3947 | checkToken = extra.tokens[extra.openCurlyToken - 5]; |
| 3948 | if (!checkToken) { |
| 3949 | return scanRegExp(); |
| 3950 | } |
| 3951 | } else { |
| 3952 | return scanPunctuator(); |
| 3953 | } |
| 3954 | // checkToken determines whether the function is |
| 3955 | // a declaration or an expression. |
| 3956 | if (FnExprTokens.indexOf(checkToken.value) >= 0) { |
| 3957 | // It is an expression. |
| 3958 | return scanPunctuator(); |
| 3959 | } |
| 3960 | // It is a declaration. |
| 3961 | return scanRegExp(); |
| 3962 | } |
| 3963 | return scanRegExp(); |
| 3964 | } |
| 3965 | if (prevToken.type === 'Keyword' && prevToken.value !== 'this') { |
| 3966 | return scanRegExp(); |
| 3967 | } |
| 3968 | return scanPunctuator(); |
no test coverage detected