( importState: ImportState, nodes: (tsmorph.Node<tsmorph.ts.Node>)[], )
| 630 | } |
| 631 | |
| 632 | function rewriteCtxMethods( |
| 633 | importState: ImportState, |
| 634 | nodes: (tsmorph.Node<tsmorph.ts.Node>)[], |
| 635 | ) { |
| 636 | for (let i = 0; i < nodes.length; i++) { |
| 637 | const node = nodes[i]; |
| 638 | |
| 639 | if (node.wasForgotten()) continue; |
| 640 | |
| 641 | if ( |
| 642 | node.isKind(SyntaxKind.ExpressionStatement) && |
| 643 | node.getText() === "ctx.renderNotFound();" |
| 644 | ) { |
| 645 | importState.httpError++; |
| 646 | node.replaceWithText("throw new HttpError(404);"); |
| 647 | continue; |
| 648 | } |
| 649 | |
| 650 | if (node.isKind(SyntaxKind.PropertyAccessExpression)) { |
| 651 | rewriteCtxMemberName(node); |
| 652 | } else if (node.isKind(SyntaxKind.ReturnStatement)) { |
| 653 | if (node.getText() === "return ctx.renderNotFound();") { |
| 654 | importState.httpError++; |
| 655 | node.replaceWithText(`throw new HttpError(404)`); |
| 656 | continue; |
| 657 | } else { |
| 658 | const expr = node.getExpression(); |
| 659 | if (expr !== undefined) { |
| 660 | rewriteCtxMethods(importState, [expr]); |
| 661 | } |
| 662 | } |
| 663 | } else if (node.isKind(SyntaxKind.VariableStatement)) { |
| 664 | const decls = node.getDeclarations(); |
| 665 | for (let i = 0; i < decls.length; i++) { |
| 666 | const decl = decls[i]; |
| 667 | const init = decl.getInitializer(); |
| 668 | if (init !== undefined) { |
| 669 | rewriteCtxMethods(importState, [init]); |
| 670 | } |
| 671 | } |
| 672 | } else if ( |
| 673 | node.isKind(SyntaxKind.ExpressionStatement) || |
| 674 | node.isKind(SyntaxKind.AwaitExpression) || |
| 675 | node.isKind(SyntaxKind.CallExpression) |
| 676 | ) { |
| 677 | const expr = node.getExpression(); |
| 678 | rewriteCtxMethods(importState, [expr]); |
| 679 | } else if (node.isKind(SyntaxKind.BinaryExpression)) { |
| 680 | rewriteCtxMethods(importState, [node.getLeft()]); |
| 681 | rewriteCtxMethods(importState, [node.getRight()]); |
| 682 | } else if ( |
| 683 | !node.isKind(SyntaxKind.ExpressionStatement) && |
| 684 | node.getKindName().endsWith("Statement") |
| 685 | ) { |
| 686 | const inner = node.getDescendantStatements(); |
| 687 | rewriteCtxMethods(importState, inner); |
| 688 | } |
| 689 | } |
no test coverage detected