function visitor()

in src/jsdoc_transformer.ts [1317:1388]


      function visitor(node: ts.Node): ts.Node|ts.Node[] {
        if (transformerUtil.isAmbient(node)) {
          if (!transformerUtil.hasModifierFlag(node as ts.Declaration, ts.ModifierFlags.Export)) {
            return node;
          }
          return visitExportedAmbient(node);
        }
        switch (node.kind) {
          case ts.SyntaxKind.ImportDeclaration:
            return visitImportDeclaration(node as ts.ImportDeclaration);
          case ts.SyntaxKind.ExportDeclaration:
            return visitExportDeclaration(node as ts.ExportDeclaration);
          case ts.SyntaxKind.ClassDeclaration:
            return visitClassDeclaration(node as ts.ClassDeclaration);
          case ts.SyntaxKind.InterfaceDeclaration:
            return visitInterfaceDeclaration(node as ts.InterfaceDeclaration);
          case ts.SyntaxKind.HeritageClause:
            return visitHeritageClause(node as ts.HeritageClause);
          case ts.SyntaxKind.ArrowFunction:
          case ts.SyntaxKind.FunctionExpression:
            // Inserting a comment before an expression can trigger automatic semicolon insertion,
            // e.g. if the function below is the expression in a `return` statement. Parenthesizing
            // prevents ASI, as long as the opening paren remains on the same line (which it does).
            return ts.factory.createParenthesizedExpression(
                visitFunctionLikeDeclaration(
                    node as ts.ArrowFunction | ts.FunctionExpression));
          case ts.SyntaxKind.Constructor:
          case ts.SyntaxKind.FunctionDeclaration:
          case ts.SyntaxKind.MethodDeclaration:
          case ts.SyntaxKind.GetAccessor:
          case ts.SyntaxKind.SetAccessor:
            return visitFunctionLikeDeclaration(node as ts.FunctionLikeDeclaration);
          case ts.SyntaxKind.ThisKeyword:
            return visitThisExpression(node as ts.ThisExpression);
          case ts.SyntaxKind.VariableStatement:
            return visitVariableStatement(node as ts.VariableStatement);
          case ts.SyntaxKind.ExpressionStatement:
          case ts.SyntaxKind.PropertyAssignment:
          case ts.SyntaxKind.PropertyDeclaration:
          case ts.SyntaxKind.ModuleDeclaration:
          case ts.SyntaxKind.EnumMember:
            escapeIllegalJSDoc(node);
            break;
          case ts.SyntaxKind.Parameter:
            // Parameter properties (e.g. `constructor(/** docs */ private foo: string)`) might have
            // JSDoc comments, including JSDoc tags recognized by Closure Compiler. Prevent emitting
            // any comments on them, so that Closure doesn't error on them.
            // See test_files/parameter_properties.ts.
            const paramDecl = node as ts.ParameterDeclaration;
            if (transformerUtil.hasModifierFlag(
                    paramDecl, ts.ModifierFlags.ParameterPropertyModifier)) {
              ts.setSyntheticLeadingComments(paramDecl, []);
              jsdoc.suppressLeadingCommentsRecursively(paramDecl);
            }
            break;
          case ts.SyntaxKind.TypeAliasDeclaration:
            return visitTypeAliasDeclaration(node as ts.TypeAliasDeclaration);
          case ts.SyntaxKind.AsExpression:
          case ts.SyntaxKind.TypeAssertionExpression:
            return visitAssertionExpression(node as ts.TypeAssertion);
          case ts.SyntaxKind.NonNullExpression:
            return visitNonNullExpression(node as ts.NonNullExpression);
          case ts.SyntaxKind.EnumDeclaration:
            visitEnumDeclaration(node as ts.EnumDeclaration);
            break;
          case ts.SyntaxKind.ForOfStatement:
            return visitForOfStatement(node as ts.ForOfStatement);
          default:
            break;
        }
        return ts.visitEachChild(node, visitor, context);
      }