MCPcopy Index your code
hub / github.com/BloombergGraphics/whatiscode / advanceSlash

Function advanceSlash

scripts/libs/esprima.js:1309–1370  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1307 }
1308
1309 function advanceSlash() {
1310 var prevToken,
1311 checkToken;
1312 // Using the following algorithm:
1313 // https://github.com/mozilla/sweet.js/wiki/design
1314 prevToken = extra.tokens[extra.tokens.length - 1];
1315 if (!prevToken) {
1316 // Nothing before that: it cannot be a division.
1317 return collectRegex();
1318 }
1319 if (prevToken.type === 'Punctuator') {
1320 if (prevToken.value === ']') {
1321 return scanPunctuator();
1322 }
1323 if (prevToken.value === ')') {
1324 checkToken = extra.tokens[extra.openParenToken - 1];
1325 if (checkToken &&
1326 checkToken.type === 'Keyword' &&
1327 (checkToken.value === 'if' ||
1328 checkToken.value === 'while' ||
1329 checkToken.value === 'for' ||
1330 checkToken.value === 'with')) {
1331 return collectRegex();
1332 }
1333 return scanPunctuator();
1334 }
1335 if (prevToken.value === '}') {
1336 // Dividing a function by anything makes little sense,
1337 // but we have to check for that.
1338 if (extra.tokens[extra.openCurlyToken - 3] &&
1339 extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {
1340 // Anonymous function.
1341 checkToken = extra.tokens[extra.openCurlyToken - 4];
1342 if (!checkToken) {
1343 return scanPunctuator();
1344 }
1345 } else if (extra.tokens[extra.openCurlyToken - 4] &&
1346 extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {
1347 // Named function.
1348 checkToken = extra.tokens[extra.openCurlyToken - 5];
1349 if (!checkToken) {
1350 return collectRegex();
1351 }
1352 } else {
1353 return scanPunctuator();
1354 }
1355 // checkToken determines whether the function is
1356 // a declaration or an expression.
1357 if (FnExprTokens.indexOf(checkToken.value) >= 0) {
1358 // It is an expression.
1359 return scanPunctuator();
1360 }
1361 // It is a declaration.
1362 return collectRegex();
1363 }
1364 return collectRegex();
1365 }
1366 if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {

Callers 1

advanceFunction · 0.85

Calls 2

collectRegexFunction · 0.85
scanPunctuatorFunction · 0.85

Tested by

no test coverage detected