MCPcopy
hub / github.com/eslint/eslint / popTryContext

Method popTryContext

lib/linter/code-path-analysis/code-path-state.js:1580–1647  ·  view source on GitHub ↗

* Pops the last context of TryStatement and finalizes it. * @returns {void}

()

Source from the content-addressed store, hash-verified

1578 * @returns {void}
1579 */
1580 popTryContext() {
1581 const context = this.tryContext;
1582
1583 this.tryContext = context.upper;
1584
1585 /*
1586 * If we're inside the `catch` block, that means there is no `finally`,
1587 * so we can process the `try` and `catch` blocks the simple way and
1588 * merge their two paths.
1589 */
1590 if (context.position === "catch") {
1591 this.popForkContext();
1592 return;
1593 }
1594
1595 /*
1596 * The following process is executed only when there is a `finally`
1597 * block.
1598 */
1599
1600 const originalReturnedForkContext = context.returnedForkContext;
1601 const originalThrownForkContext = context.thrownForkContext;
1602
1603 // no `return` or `throw` in `try` or `catch` so there's nothing left to do
1604 if (
1605 originalReturnedForkContext.empty &&
1606 originalThrownForkContext.empty
1607 ) {
1608 return;
1609 }
1610
1611 /*
1612 * The following process is executed only when there is a `finally`
1613 * block and there was a `return` or `throw` in the `try` or `catch`
1614 * blocks.
1615 */
1616
1617 // Separate head to normal paths and leaving paths.
1618 const headSegments = this.forkContext.head;
1619
1620 this.forkContext = this.forkContext.upper;
1621 const normalSegments = headSegments.slice(
1622 0,
1623 (headSegments.length / 2) | 0,
1624 );
1625 const leavingSegments = headSegments.slice(
1626 (headSegments.length / 2) | 0,
1627 );
1628
1629 // Forwards the leaving path to upper contexts.
1630 if (!originalReturnedForkContext.empty) {
1631 getReturnContext(this).returnedForkContext.add(leavingSegments);
1632 }
1633 if (!originalThrownForkContext.empty) {
1634 getThrowContext(this).thrownForkContext.add(leavingSegments);
1635 }
1636
1637 // Sets the normal path as the next.

Callers 1

processCodePathToExitFunction · 0.80

Calls 6

popForkContextMethod · 0.95
getReturnContextFunction · 0.85
getThrowContextFunction · 0.85
replaceHeadMethod · 0.80
makeUnreachableMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected