()
| 1222 | } |
| 1223 | |
| 1224 | function advanceSlash() { |
| 1225 | var prevToken, |
| 1226 | checkToken; |
| 1227 | // Using the following algorithm: |
| 1228 | // https://github.com/mozilla/sweet.js/wiki/design |
| 1229 | prevToken = extra.tokens[extra.tokens.length - 1]; |
| 1230 | if (!prevToken) { |
| 1231 | // Nothing before that: it cannot be a division. |
| 1232 | return collectRegex(); |
| 1233 | } |
| 1234 | if (prevToken.type === 'Punctuator') { |
| 1235 | if (prevToken.value === ']') { |
| 1236 | return scanPunctuator(); |
| 1237 | } |
| 1238 | if (prevToken.value === ')') { |
| 1239 | checkToken = extra.tokens[extra.openParenToken - 1]; |
| 1240 | if (checkToken && |
| 1241 | checkToken.type === 'Keyword' && |
| 1242 | (checkToken.value === 'if' || |
| 1243 | checkToken.value === 'while' || |
| 1244 | checkToken.value === 'for' || |
| 1245 | checkToken.value === 'with')) { |
| 1246 | return collectRegex(); |
| 1247 | } |
| 1248 | return scanPunctuator(); |
| 1249 | } |
| 1250 | if (prevToken.value === '}') { |
| 1251 | // Dividing a function by anything makes little sense, |
| 1252 | // but we have to check for that. |
| 1253 | if (extra.tokens[extra.openCurlyToken - 3] && |
| 1254 | extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') { |
| 1255 | // Anonymous function. |
| 1256 | checkToken = extra.tokens[extra.openCurlyToken - 4]; |
| 1257 | if (!checkToken) { |
| 1258 | return scanPunctuator(); |
| 1259 | } |
| 1260 | } else if (extra.tokens[extra.openCurlyToken - 4] && |
| 1261 | extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') { |
| 1262 | // Named function. |
| 1263 | checkToken = extra.tokens[extra.openCurlyToken - 5]; |
| 1264 | if (!checkToken) { |
| 1265 | return collectRegex(); |
| 1266 | } |
| 1267 | } else { |
| 1268 | return scanPunctuator(); |
| 1269 | } |
| 1270 | // checkToken determines whether the function is |
| 1271 | // a declaration or an expression. |
| 1272 | if (FnExprTokens.indexOf(checkToken.value) >= 0) { |
| 1273 | // It is an expression. |
| 1274 | return scanPunctuator(); |
| 1275 | } |
| 1276 | // It is a declaration. |
| 1277 | return collectRegex(); |
| 1278 | } |
| 1279 | return collectRegex(); |
| 1280 | } |
| 1281 | if (prevToken.type === 'Keyword' && prevToken.value !== 'this') { |
no test coverage detected