( input: SimpleExpressionNode, )
| 494 | const stripParensRE = /^\(|\)$/g |
| 495 | |
| 496 | function parseForExpression( |
| 497 | input: SimpleExpressionNode, |
| 498 | ): ForParseResult | undefined { |
| 499 | const loc = input.loc |
| 500 | const exp = input.content |
| 501 | const inMatch = exp.match(forAliasRE) |
| 502 | if (!inMatch) return |
| 503 | |
| 504 | const [, LHS, RHS] = inMatch |
| 505 | |
| 506 | const createAliasExpression = ( |
| 507 | content: string, |
| 508 | offset: number, |
| 509 | asParam = false, |
| 510 | ) => { |
| 511 | const start = loc.start.offset + offset |
| 512 | const end = start + content.length |
| 513 | return createExp( |
| 514 | content, |
| 515 | false, |
| 516 | getLoc(start, end), |
| 517 | ConstantTypes.NOT_CONSTANT, |
| 518 | asParam ? ExpParseMode.Params : ExpParseMode.Normal, |
| 519 | ) |
| 520 | } |
| 521 | |
| 522 | const result: ForParseResult = { |
| 523 | source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)), |
| 524 | value: undefined, |
| 525 | key: undefined, |
| 526 | index: undefined, |
| 527 | finalized: false, |
| 528 | } |
| 529 | |
| 530 | let valueContent = LHS.trim().replace(stripParensRE, '').trim() |
| 531 | const trimmedOffset = LHS.indexOf(valueContent) |
| 532 | |
| 533 | const iteratorMatch = valueContent.match(forIteratorRE) |
| 534 | if (iteratorMatch) { |
| 535 | valueContent = valueContent.replace(forIteratorRE, '').trim() |
| 536 | |
| 537 | const keyContent = iteratorMatch[1].trim() |
| 538 | let keyOffset: number | undefined |
| 539 | if (keyContent) { |
| 540 | keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length) |
| 541 | result.key = createAliasExpression(keyContent, keyOffset, true) |
| 542 | } |
| 543 | |
| 544 | if (iteratorMatch[2]) { |
| 545 | const indexContent = iteratorMatch[2].trim() |
| 546 | |
| 547 | if (indexContent) { |
| 548 | result.index = createAliasExpression( |
| 549 | indexContent, |
| 550 | exp.indexOf( |
| 551 | indexContent, |
| 552 | result.key |
| 553 | ? keyOffset! + keyContent.length |
no test coverage detected