How to use the typescript.isClassDeclaration 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 tensorflow / tfjs / tfjs-core / scripts / test_snippets / util.ts View on Github external
async function visit(
    // tslint:disable-next-line:no-any
    tf: any, checker: ts.TypeChecker, node: ts.Node,
    sourceFile: ts.SourceFile) {
  const children = node.getChildren();
  for (let i = 0; i < children.length; i++) {
    await visit(tf, checker, children[i], sourceFile);
  }

  if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) ||
      ts.isMethodDeclaration(node) || ts.isInterfaceDeclaration(node)) {
    const symbol = checker.getSymbolAtLocation(node.name);
    const jsdoc = getJSDocTag(symbol);
    if (jsdoc == null) {
      return;
    }
    // Ignore snippets of methods that have been marked with ignoreCI.
    if (jsdoc['ignoreCI']) {
      return;
    }

    const documentation = symbol.getDocumentationComment(checker);
    if (documentation == null) {
      return;
    }
    for (let i = 0; i < documentation.length; i++) {
github angular / angular / packages / compiler-cli / ngcc / src / analysis / module_with_providers_analyzer.ts View on Github external
ConcreteDeclaration {
    const ngModule = fn.ngModule;

    // For external module references, use the declaration as is.
    if (ngModule.viaModule !== null) {
      return ngModule;
    }

    // For internal (non-library) module references, redirect the module's value declaration
    // to its type declaration.
    const dtsNgModule = this.host.getDtsDeclaration(ngModule.node);
    if (!dtsNgModule) {
      throw new Error(
          `No typings declaration can be found for the referenced NgModule class in ${fn.declaration.getText()}.`);
    }
    if (!ts.isClassDeclaration(dtsNgModule) || !hasNameIdentifier(dtsNgModule)) {
      throw new Error(
          `The referenced NgModule in ${fn.declaration.getText()} is not a named class declaration in the typings program; instead we get ${dtsNgModule.getText()}`);
    }

    return {node: dtsNgModule, viaModule: null};
  }
}
github puppeteer / puppeteer / utils / doclint / check_public_api / JSBuilder.js View on Github external
function visit(node) {
    if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) {
      const symbol = node.name ? checker.getSymbolAtLocation(node.name) : node.symbol;
      let className = symbol.getName();

      if (className === '__class') {
        let parent = node;
        while (parent.parent)
          parent = parent.parent;
        className = path.basename(parent.fileName,  '.js');
      }
      if (className && !excludeClasses.has(className)) {
        classes.push(serializeClass(className, symbol, node));
        const parentClassName = parentClass(node);
        if (parentClassName)
          inheritance.set(className, parentClassName);
        excludeClasses.add(className);
      }
github bloomberg / pasta-sourcemaps / src / parser.ts View on Github external
function getParentClassProperty(func: ts.FunctionLikeDeclaration) {
    const propertyNode = getPropertyNodeForFunction(func);
    if (propertyNode) {
        const parent = propertyNode.parent;
        if (ts.isClassDeclaration(parent) || ts.isClassExpression(parent)) {
            return parent;
        }
    }
    return null;
}
github angular / angular / packages / compiler-cli / src / ngtsc / reflection / src / typescript.ts View on Github external
hasBaseClass(clazz: ClassDeclaration): boolean {
    return (ts.isClassDeclaration(clazz) || ts.isClassExpression(clazz)) &&
        clazz.heritageClauses !== undefined &&
        clazz.heritageClauses.some(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
  }
github plantain-00 / types-as-schema / src / parser.ts View on Github external
private handleSourceFile(node: ts.Node, sourceFile: ts.SourceFile) {
    const jsDocs = this.getJsDocs(node, sourceFile)
    const entry = jsDocs.find(jsDoc => jsDoc.name === 'entry')
    if (ts.isTypeAliasDeclaration(node)) {
      this.handleTypeAliasDeclaration(node, jsDocs, entry, sourceFile)
    } else if (ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) {
      this.handleInterfaceOrClassDeclaration(node, jsDocs, entry, sourceFile)
    } else if (ts.isFunctionDeclaration(node)) {
      this.handleFunctionDeclaration(node, jsDocs, sourceFile)
    }
  }
github vendure-ecommerce / vendure / scripts / generate-config-docs.ts View on Github external
if (ts.isInterfaceDeclaration(statement)) {
        return {
            ...info,
            kind: 'interface',
            extends: getHeritageClauseText(statement, ts.SyntaxKind.ExtendsKeyword),
            members: parseMembers(statement.members),
        };
    } else if (ts.isTypeAliasDeclaration(statement)) {
        return {
            ...info,
            type: statement.type,
            kind: 'typeAlias',
            members: ts.isTypeLiteralNode(statement.type) ? parseMembers(statement.type.members) : undefined,
        };
    } else if (ts.isClassDeclaration(statement)) {
        return {
            ...info,
            kind: 'class',
            members: parseMembers(statement.members),
            extends: getHeritageClauseText(statement, ts.SyntaxKind.ExtendsKeyword),
            implements: getHeritageClauseText(statement, ts.SyntaxKind.ImplementsKeyword),
        };
    }
}
github ts-llvm / ts-llvm / src / types.ts View on Github external
export function getStructType(type: ts.ObjectType, isOpaque: boolean, generator: LLVMGenerator) {
  const { context, module, checker } = generator;

  const elements = getStoredProperties(type, checker).map(property =>
    getLLVMType(checker.getTypeAtLocation(property.valueDeclaration), generator)
  );
  const declaration = type.symbol.declarations[0];
  let struct: llvm.StructType | null;

  if (ts.isClassDeclaration(declaration)) {
    const name = mangleType(type, checker);
    struct = module.getTypeByName(name);
    if (!struct) {
      struct = llvm.StructType.create(context, name);
      if (!isOpaque) {
        struct.setBody(elements);
      }
    }
  } else {
    struct = llvm.StructType.get(context, elements);
  }

  return struct;
}
github angular / angular / packages / compiler-cli / src / ngtsc / annotations / src / selector_scope.ts View on Github external
function maybeUnwrapNameOfDeclaration(decl: ts.Declaration): ts.Declaration|ts.Identifier {
  if ((ts.isClassDeclaration(decl) || ts.isVariableDeclaration(decl)) && decl.name !== undefined &&
      ts.isIdentifier(decl.name)) {
    return decl.name;
  }
  return decl;
}
github angular / angular / packages / core / schematics / migrations / module-with-providers / transform.ts View on Github external
private _getTypeOfResolvedValue(value: ResolvedValue): string|undefined {
    if (value instanceof Map && this.isModuleWithProvidersType(value)) {
      const mapValue = value.get('ngModule') !;
      if (mapValue instanceof Reference && ts.isClassDeclaration(mapValue.node) &&
          mapValue.node.name) {
        return mapValue.node.name.text;
      } else if (mapValue instanceof DynamicValue) {
        addTodoToNode(mapValue.node, TODO_COMMENT);
        this._updateNode(mapValue.node, mapValue.node);
      }
    }

    return undefined;
  }