• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript types.isObjectProperty函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSimpleObjectProperties

export function* getSimpleObjectProperties(node: babel.ObjectExpression) {
  for (const property of node.properties) {
    if (babel.isObjectProperty(property) || babel.isObjectMethod(property)) {
      yield property;
    }
  }
}
开发者ID:Polymer,项目名称:tools,代码行数:7,代码来源:esutil.ts


示例2: toScannedMethod

export function toScannedMethod(
    node: babel.ObjectProperty|babel.ObjectMethod|babel.ClassMethod,
    sourceRange: SourceRange,
    document: JavaScriptDocument): ScannedMethod {
  const parsedJsdoc = jsdoc.parseJsdoc(getAttachedComment(node) || '');
  const description = parsedJsdoc.description.trim();
  const maybeName = getPropertyName(node);

  const warnings: Warning[] = [];
  if (!maybeName) {
    warnings.push(new Warning({
      code: 'unknown-method-name',
      message: `Could not determine name of method from expression of type: ` +
          `${node.key.type}`,
      sourceRange: sourceRange,
      severity: Severity.INFO,
      parsedDocument: document
    }));
  }

  const value = babel.isObjectProperty(node) ? node.value : node;

  const result = getClosureType(value, parsedJsdoc, sourceRange, document);
  const type = result.successful === true ? result.value : 'Function';

  const name = maybeName || '';
  const scannedMethod: ScannedMethod = {
    name,
    type,
    description,
    sourceRange,
    warnings,
    astNode: {language: 'js', node, containingDocument: document},
    jsdoc: parsedJsdoc,
    privacy: getOrInferPrivacy(name, parsedJsdoc)
  };

  if (value && babel.isFunction(value)) {
    if (scannedMethod.jsdoc !== undefined) {
      scannedMethod.return = getReturnFromAnnotation(scannedMethod.jsdoc);
    }
    if (scannedMethod.return === undefined) {
      scannedMethod.return = inferReturnFromBody(value);
    }

    scannedMethod.params =
        (value.params ||
         []).map((nodeParam) => toMethodParam(nodeParam, scannedMethod.jsdoc));
  }

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


示例3: toScannedPolymerProperty

export function toScannedPolymerProperty(
    node: babel.ObjectMethod|babel.ObjectProperty|babel.ClassMethod,
    sourceRange: SourceRange,
    document: JavaScriptDocument): ScannedPolymerProperty|undefined {
  const parsedJsdoc = jsdoc.parseJsdoc(getAttachedComment(node) || '');
  const description = parsedJsdoc.description.trim();
  const maybeName = getPropertyName(node);

  const warnings: Warning[] = [];
  if (!maybeName) {
    warnings.push(new Warning({
      code: 'unknown-prop-name',
      message:
          `Could not determine name of property from expression of type: ` +
          `${node.key.type}`,
      sourceRange: sourceRange,
      severity: Severity.WARNING,
      parsedDocument: document
    }));
    return;
  }

  const value = babel.isObjectProperty(node) ? node.value : node;

  const typeResult = getClosureType(value, parsedJsdoc, sourceRange, document);
  let type;
  if (typeResult.successful) {
    type = typeResult.value;
  } else {
    warnings.push(typeResult.error);
    type = 'Object';
  }

  const name = maybeName || '';
  const result: ScannedPolymerProperty = {
    name,
    type,
    description,
    sourceRange,
    warnings,
    astNode: {node, language: 'js', containingDocument: document},
    isConfiguration: configurationProperties.has(name),
    jsdoc: parsedJsdoc,
    privacy: getOrInferPrivacy(name, parsedJsdoc)
  };

  return result;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:48,代码来源:js-utils.ts


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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript types.isStatement函数代码示例发布时间:2022-05-28
下一篇:
TypeScript types.isObjectExpression函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap