* After a `for` keyword ending at `forEnd`, recognize `var Name in` or * `var Name: Type in` and push the `var` range and the `: Type` range onto * `ranges`. The type runs to the `in` at nesting depth 0, so generic types * (`TPair >`) and dotted names are whole. Any other *
(s: string, forEnd: number, ranges: number[])
| 361 | * nothing. Returns the index to resume scanning from. |
| 362 | */ |
| 363 | function scanForInVariable(s: string, forEnd: number, ranges: number[]): number { |
| 364 | const varStart = skipTrivia(s, forEnd); |
| 365 | if (lowerWordAt(s, varStart) !== 'var') return forEnd; |
| 366 | const varEnd = varStart + 3; |
| 367 | const nameStart = skipTrivia(s, varEnd); |
| 368 | if (!isIdentStart(s.charCodeAt(nameStart))) return forEnd; |
| 369 | let i = skipTrivia(s, wordEnd(s, nameStart + 1)); |
| 370 | let typeStart = -1; |
| 371 | if (s.charCodeAt(i) === CH_COLON && s.charCodeAt(i + 1) !== CH_EQ) { |
| 372 | typeStart = i; |
| 373 | const limit = Math.min(s.length, i + MAX_LOOP_TYPE_LENGTH); |
| 374 | let depth = 0; |
| 375 | i++; |
| 376 | for (;;) { |
| 377 | if (i >= limit) return forEnd; |
| 378 | const k = commentOrStringEnd(s, i); |
| 379 | if (k >= 0) { |
| 380 | i = k; |
| 381 | continue; |
| 382 | } |
| 383 | const c = s.charCodeAt(i); |
| 384 | if (c === CH_LT || c === CH_LPAREN || c === CH_LBRACKET) { |
| 385 | depth++; |
| 386 | } else if (c === CH_GT || c === CH_RPAREN || c === CH_RBRACKET) { |
| 387 | if (--depth < 0) return forEnd; |
| 388 | } else if (c === CH_SEMI || c === CH_EQ) { |
| 389 | return forEnd; // `for var i: Integer := 0 to …`, or no loop at all |
| 390 | } else if (isIdentStart(c)) { |
| 391 | const word = lowerWordAt(s, i); |
| 392 | if (depth === 0 && word === 'in') break; |
| 393 | if (NOT_A_FOR_IN.has(word)) return forEnd; |
| 394 | i = wordEnd(s, i + 1); |
| 395 | continue; |
| 396 | } |
| 397 | i++; |
| 398 | } |
| 399 | } |
| 400 | if (lowerWordAt(s, i) !== 'in') return forEnd; |
| 401 | ranges.push(varStart, varEnd); |
| 402 | if (typeStart >= 0) ranges.push(typeStart, i); |
| 403 | return i; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * After a `property` keyword running from `start` to `propertyEnd`, |
no test coverage detected