當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。