How to use the typescript.visitEachChild function in typescript

To help you get started, we’ve selected a few typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular / packages / compiler-cli / src / transformers / lower_expressions.ts View on Github external
const exportName = nodeRequest.name;
          declarations.push({name: exportName, node, order: DeclarationOrder.BeforeStmt});
          return ts.createIdentifier(exportName);
        }
        let result = node;
        if (shouldVisit(pos, end) && !isLexicalScope(node)) {
          result = ts.visitEachChild(node, visitNode, context);
        }
        return result;
      }

      // Get the original node before tsickle
      const {pos, end} = ts.getOriginalNode(node);
      let resultStmt: ts.Statement;
      if (shouldVisit(pos, end)) {
        resultStmt = ts.visitEachChild(node, visitNode, context);
      } else {
        resultStmt = node;
      }

      if (declarations.length) {
        inserts.push({relativeTo: resultStmt, declarations});
      }
      return resultStmt;
    }
github angular / tsickle / src / decorator_downlevel_transformer.ts View on Github external
function transformClassElement(element: ts.ClassElement):
        [string|undefined, ts.ClassElement, ts.Decorator[]] {
      element = ts.visitEachChild(element, visitor, context);
      const decoratorsToKeep: ts.Decorator[] = [];
      const toLower: ts.Decorator[] = [];
      for (const decorator of element.decorators || []) {
        if (!shouldLower(decorator, typeChecker)) {
          decoratorsToKeep.push(decorator);
          continue;
        }
        toLower.push(decorator);
      }
      if (!toLower.length) return [undefined, element, []];

      if (!element.name || element.name.kind !== ts.SyntaxKind.Identifier) {
        // Method has a weird name, e.g.
        //   [Symbol.foo]() {...}
        diagnostics.push({
          file: element.getSourceFile(),
github ng-packagr / ng-packagr / src / lib / ts / analyse-dependencies-transformer.ts View on Github external
if (ts.isImportDeclaration(node)) {
      // Found an 'import ...' declaration
      const importedModuleId: string = findModuleIdFromImport(node);
      analyser(node.getSourceFile(), importedModuleId);
    } else if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
      // Found an 'export ... from ...' declaration
      const importedModuleId: string = findModuleIdFromExport(node);
      analyser(node.getSourceFile(), importedModuleId);
    } else {
      return ts.visitEachChild(node, visitImports, context);
    }

    return node;
  };

  return ts.visitEachChild(sourceFile, visitImports, context);
};
github angular / angular-cli / packages / ngtools / webpack / src / transformers / import_factory.ts View on Github external
const newImportString = `./${forwardSlashPath(relativePath)}`.replace(/ts$/, 'ngfactory');

  // The easiest way to alter them is with a simple visitor.
  const replacementVisitor: ts.Visitor = (node: ts.Node) => {
    if (node === importStringLit) {
      // Transform the import string.
      return ts.createStringLiteral(newImportString);
    } else if (node === exportNameId) {
      // Transform the export name.
      return ts.createIdentifier(exportNameId.text + 'NgFactory');
    }

    return ts.visitEachChild(node, replacementVisitor, context);
  };

  return ts.visitEachChild(node, replacementVisitor, context);
}
github TypeScriptToLua / TypeScriptToLua / test / unit / transformers / utils.ts View on Github external
    const visit: ts.Visitor = node => visitor(node) ?? ts.visitEachChild(node, visit, context);
    return ts.visitNode(node, visit);
github ionic-team / stencil / src / compiler / transpile / transformers / add-metadata-export.ts View on Github external
function visit(node: ts.Node, cmpMeta: ComponentMeta): ts.VisitResult {
      switch (node.kind) {
        case ts.SyntaxKind.ClassDeclaration:
          return visitClass(node as ts.ClassDeclaration, cmpMeta);
        default:
          return ts.visitEachChild(node, (node) => {
            return visit(node, cmpMeta);
          }, transformContext);
      }
    }
github atfzl / ReactUI / showcase / styled-components-source / createTransformer.ts View on Github external
);

          return ts.createCall(
            ts.createPropertyAccess(n as ts.Expression, 'withConfig'),
            undefined,
            [ts.createObjectLiteral(styledConfig)],
          );
        }

        ts.forEachChild(n, m => {
          if (!m.parent) {
            m.parent = n;
          }
        });

        return ts.visitEachChild(n, visitor, context);
      };
github ts-type-makeup / superstruct-ts-transformer / transformer.ts View on Github external
    const pass = () => ts.visitEachChild(node, visitor, ctx);
github nestjs / swagger / lib / plugin / visitors / controller-class.visitor.ts View on Github external
const visitNode = (node: ts.Node): ts.Node => {
      if (ts.isMethodDeclaration(node)) {
        return this.addDecoratorToNode(node, typeChecker, sourceFile.fileName);
      }
      return ts.visitEachChild(node, visitNode, ctx);
    };
    return ts.visitNode(sourceFile, visitNode);
github Bearer / bearer-js / packages / transpiler / src / transformers / replace-function-decorator.ts View on Github external
function visitEnsureConstructor(node: ts.Node): ts.VisitResult {
      if (ts.isClassDeclaration(node)) {
        return ts.visitEachChild(
          appendConstructor(node as ts.ClassDeclaration),
          visitEnsureConstructor,
          transformContext
        )
      }
      return ts.visitEachChild(node, visitEnsureConstructor, transformContext)
    }