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

TypeScript babel-types.isObjectProperty函数代码示例

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

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



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

示例1: codeFrameError

 .forEach(prop => {
   if (t.isObjectProperty(prop)) {
     let propKey: string | null = null
     if (t.isStringLiteral(prop.key)) {
       propKey = prop.key.value
     }
     if (t.isIdentifier(prop.key)) {
       propKey = prop.key.name
       // propsKeys.push(prop.key.name)
     }
     if (t.isObjectExpression(prop.value) && propKey) {
       for (const p of prop.value.properties) {
         if (t.isObjectProperty(p)) {
           let key: string | null = null
           if (t.isStringLiteral(p.key)) {
             key = p.key.value
           }
           if (t.isIdentifier(p.key)) {
             key = p.key.name
           }
           if (key === 'value') {
             defaultProps.push({
               name: propKey,
               value: p.value
             })
           } else if (key === 'observer') {
             observeProps.push({
               name: propKey,
               observer: p.value
             })
           }
           if (!isValidVarName(propKey)) {
             throw codeFrameError(prop, `${propKey} 不是一个合法的 JavaScript 变量名`)
           }
         }
         if (t.isObjectMethod(p) && t.isIdentifier(p.key, { name: 'observer' })) {
           observeProps.push({
             name: propKey,
             observer: t.arrowFunctionExpression(p.params, p.body, p.async)
           })
         }
       }
     }
     if (propKey) {
       propsKeys.push(propKey)
     }
   }
 })
开发者ID:YangShaoQun,项目名称:taro,代码行数:48,代码来源:script.ts


示例2:

 .forEach(prop => {
   if (t.isObjectProperty(prop)) {
     if (t.isStringLiteral(prop.key)) {
       stateKeys.push(prop.key.value)
     }
     if (t.isIdentifier(prop.key)) {
       stateKeys.push(prop.key.name)
     }
   }
 })
开发者ID:topud,项目名称:taro,代码行数:10,代码来源:script.ts


示例3: if

 .forEach(prop => {
   if (t.isObjectProperty(prop)) {
     let propKey: string | null = null
     if (t.isStringLiteral(prop.key)) {
       propKey = prop.key.value
     }
     if (t.isIdentifier(prop.key)) {
       propKey = prop.key.name
       // propsKeys.push(prop.key.name)
     }
     if (t.isObjectExpression(prop.value) && propKey) {
       for (const p of prop.value.properties) {
         if (t.isObjectProperty(p)) {
           let key: string | null = null
           if (t.isStringLiteral(p.key)) {
             key = p.key.value
           }
           if (t.isIdentifier(p.key)) {
             key = p.key.name
           }
           if (key === 'value') {
             defaultProps.push({
               name: propKey,
               value: p.value
             })
           } else if (key === 'observer') {
             observeProps.push({
               name: propKey,
               observer: p.value
             })
           }
         }
       }
     }
     if (propKey) {
       propsKeys.push(propKey)
     }
   }
 })
开发者ID:topud,项目名称:taro,代码行数:39,代码来源:script.ts


示例4: handleThirdPartyComponent

function handleThirdPartyComponent (expr: t.ClassMethod | t.ClassProperty) {
  if (t.isClassProperty(expr) && expr.key.name === 'config' && t.isObjectExpression(expr.value)) {
    const properties = expr.value.properties
    for (const prop of properties) {
      if (
        t.isObjectProperty(prop) &&
        (t.isIdentifier(prop.key, { name: 'usingComponents' }) || t.isStringLiteral(prop.key, { value: 'usingComponents' })) &&
        t.isObjectExpression(prop.value)
      ) {
        for (const value of prop.value.properties) {
          if (t.isObjectProperty(value)) {
            if (t.isStringLiteral(value.key)) {
              THIRD_PARTY_COMPONENTS.add(value.key.value)
            }
            if (t.isIdentifier(value.key)) {
              THIRD_PARTY_COMPONENTS.add(value.key.name)
            }
          }
        }
      }
    }
  }
}
开发者ID:topud,项目名称:taro,代码行数:23,代码来源:index.ts


示例5: toScannedPolymerProperty

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

  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
    }));
  }

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

  let type = closureType(value, sourceRange, document);
  const typeTag = jsdoc.getTag(parsedJsdoc, 'type');
  if (typeTag) {
    type = doctrine.type.stringify(typeTag.type!) || type;
  }
  if (type instanceof Warning) {
    warnings.push(type);
    type = 'Object';
  }
  const name = maybeName || '';
  const result: ScannedPolymerProperty = {
    name,
    type,
    description,
    sourceRange,
    warnings,
    astNode: node,
    isConfiguration: configurationProperties.has(name),
    jsdoc: parsedJsdoc,
    privacy: getOrInferPrivacy(name, parsedJsdoc)
  };

  return result;
};
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:47,代码来源:js-utils.ts


示例6: toConstant


//.........这里部分代码省略.........
     if (constant && expression.operator === '||') {
       return left || right;
     }
   }
   if (b.isMemberExpression(expression)) {
     const object = toConstant(expression.object);
     if (!object || !constant) {
       constant = false;
       return;
     }
     const member = expression.computed
       ? toConstant(expression.property)
       : b.isIdentifier(expression.property)
         ? expression.property.name
         : undefined;
     if (member === undefined && !expression.computed) {
       constant = false;
     }
     if (!constant) return;
     if ({}.hasOwnProperty.call(object, '' + member) && member[0] !== '_') {
       return object[member];
     }
   }
   if (b.isNullLiteral(expression)) {
     return null;
   }
   if (b.isNumericLiteral(expression)) {
     return expression.value;
   }
   if (b.isObjectExpression(expression)) {
     const result: any = {};
     for (let i = 0; constant && i < expression.properties.length; i++) {
       const property = expression.properties[i];
       if (b.isObjectProperty(property)) {
         if (property.shorthand) {
           constant = false;
           return;
         }
         const key = property.computed
           ? toConstant(property.key)
           : b.isIdentifier(property.key)
             ? property.key.name
             : b.isStringLiteral(property.key)
               ? property.key.value
               : undefined;
         if (!key || key[0] === '_') {
           constant = false;
         }
         if (!constant) return;
         const value = toConstant(property.value);
         if (!constant) return;
         result[key] = value;
       } else if (b.isObjectMethod(property)) {
         constant = false;
       } else if (b.isSpreadProperty(property)) {
         const argument = toConstant(property.argument);
         if (!argument) constant = false;
         if (!constant) return;
         Object.assign(result, argument);
       }
     }
     return result;
   }
   if (b.isParenthesizedExpression(expression)) {
     return toConstant(expression.expression);
   }
开发者ID:Ashwinie,项目名称:inceptionEngine,代码行数:67,代码来源:index.ts


示例7: toScannedMethod

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

  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;

  let type = closureType(value, sourceRange, document);
  const typeTag = jsdoc.getTag(parsedJsdoc, 'type');
  if (typeTag) {
    type = doctrine.type.stringify(typeTag.type!) || type;
  }
  if (type instanceof Warning) {
    warnings.push(type);
    type = 'Function';
  }
  const name = maybeName || '';
  const scannedMethod: ScannedMethod = {
    name,
    type,
    description,
    sourceRange,
    warnings,
    astNode: node,
    jsdoc: parsedJsdoc,
    privacy: getOrInferPrivacy(name, parsedJsdoc)
  };

  if (value && babel.isFunction(value)) {
    const paramTags = new Map<string, doctrine.Tag>();
    if (scannedMethod.jsdoc) {
      for (const tag of (scannedMethod.jsdoc.tags || [])) {
        if (tag.title === 'param' && tag.name) {
          paramTags.set(tag.name, tag);

        } else if (tag.title === 'return' || tag.title === 'returns') {
          scannedMethod.return = {};
          if (tag.type) {
            scannedMethod.return.type = doctrine.type.stringify(tag.type!);
          }
          if (tag.description) {
            scannedMethod.return.desc = tag.description;
          }
        }
      }
    }

    scannedMethod.params = (value.params || []).map((nodeParam) => {
      let name;
      let defaultValue;
      let rest;

      if (babel.isIdentifier(nodeParam)) {
        // Basic parameter: method(param)
        name = nodeParam.name;

      } else if (
          babel.isRestElement(nodeParam) &&
          babel.isIdentifier(nodeParam.argument)) {
        // Rest parameter: method(...param)
        name = nodeParam.argument.name;
        rest = true;

      } else if (
          babel.isAssignmentPattern(nodeParam) &&
          babel.isIdentifier(nodeParam.left) &&
          babel.isLiteral(nodeParam.right)) {
        // Parameter with a default: method(param = "default")
        name = nodeParam.left.name;
        defaultValue = generate(nodeParam.right).code;

      } else {
        // Some AST pattern we don't recognize. Hope the code generator does
        // something reasonable.
        name = generate(nodeParam).code;
      }

      let type;
      let description;
      const tag = paramTags.get(name);
      if (tag) {
        if (tag.type) {
          type = doctrine.type.stringify(tag.type);
        }
        if (tag.description) {
//.........这里部分代码省略.........
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:101,代码来源:esutil.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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