当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript types.isClass函数代码示例

本文整理汇总了TypeScript中@babel/types.isClass函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isClass函数的具体用法?TypeScript isClass怎么用?TypeScript isClass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isClass函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getConstructorMethod

export function getConstructorMethod(
    astNode: babel.Node, document: JavaScriptDocument): ScannedMethod|
    undefined {
  if (!babel.isClass(astNode)) {
    return;
  }

  const statement = getConstructorClassMethod(astNode);

  if (statement) {
    const method = toScannedMethod(
        statement, document.sourceRangeForNode(statement)!, document);
    const typeTag = getReturnFromAnnotation(
        jsdoc.parseJsdoc(getAttachedComment(statement) || ''));

    if (typeTag) {
      method.return = {...method.return, ...typeTag};
    } else {
      method.return = undefined;
    }

    return method;
  }
}
开发者ID:Polymer,项目名称:tools,代码行数:24,代码来源:esutil.ts

示例2: extractPropertiesFromClassOrObjectBody

export function extractPropertiesFromClassOrObjectBody(
    node: babel.Class|babel.ObjectExpression,
    document: JavaScriptDocument): Map<string, ScannedProperty> {
  const properties = new Map<string, ScannedProperty>();
  const accessors = new Map<string, {
    getter?: babel.ClassMethod | babel.ObjectMethod,
    setter?: babel.ClassMethod | babel.ObjectMethod
  }>();

  let body;

  if (babel.isClass(node)) {
    body = node.body.body;
  } else {
    body = node.properties;
  }

  for (const member of body) {
    if (!babel.isMethod(member) && !babel.isObjectProperty(member)) {
      continue;
    }

    const name = getPropertyName(member);
    if (name === undefined) {
      continue;
    }

    if (babel.isMethod(member) || babel.isFunction(member.value)) {
      if (babel.isMethod(member) &&
          (member.kind === 'get' || member.kind === 'set')) {
        let accessor = accessors.get(name);

        if (!accessor) {
          accessor = {};
          accessors.set(name, accessor);
        }

        if (member.kind === 'get') {
          accessor.getter = member;
        } else {
          accessor.setter = member;
        }
      }

      continue;
    }

    const astNode = member.key;
    const sourceRange = document.sourceRangeForNode(member)!;
    const jsdocAnn = jsdoc.parseJsdoc(getAttachedComment(member) || '');
    const detectedType =
        getClosureType(member.value, jsdocAnn, sourceRange, document);
    let type: string|undefined = undefined;

    if (detectedType.successful) {
      type = detectedType.value;
    }

    properties.set(name, {
      name,
      astNode: {language: 'js', node: astNode, containingDocument: document},
      type,
      jsdoc: jsdocAnn,
      sourceRange,
      description: jsdocAnn ? jsdoc.getDescription(jsdocAnn) : undefined,
      privacy: getOrInferPrivacy(name, jsdocAnn),
      warnings: [],
      readOnly: jsdoc.hasTag(jsdocAnn, 'readonly'),
    });
  }

  for (const val of accessors.values()) {
    let getter: ScannedProperty|null = null;
    let setter: ScannedProperty|null = null;

    if (val.getter) {
      const parsedJsdoc =
          jsdoc.parseJsdoc(getAttachedComment(val.getter) || '');
      getter =
          extractPropertyFromGetterOrSetter(val.getter, parsedJsdoc, document);
    }

    if (val.setter) {
      const parsedJsdoc =
          jsdoc.parseJsdoc(getAttachedComment(val.setter) || '');
      setter =
          extractPropertyFromGetterOrSetter(val.setter, parsedJsdoc, document);
    }

    const prop = getter || setter;
    if (!prop) {
      continue;
    }

    if (!prop.readOnly) {
      prop.readOnly = (val.setter === undefined);
    }

    properties.set(prop.name, prop);
  }
//.........这里部分代码省略.........
开发者ID:Polymer,项目名称:tools,代码行数:101,代码来源:esutil.ts


注:本文中的@babel/types.isClass函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。