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

TypeScript types.isObjectExpression函数代码示例

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

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



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

示例1: test

 test('produces expected names', function() {
   const objectLiteralCode = `
   ({
     'foo': 1,
     bar: 2,
     [10]: 3,
     [10 + 20]: 4,
     ['hi' + ' there']: 5,
     [identifier]: 6,
   });
   `;
   const statement = babylon.parse(objectLiteralCode).program.body[0];
   if (!babel.isExpressionStatement(statement)) {
     throw new Error('');
   }
   const expr = statement.expression;
   if (!babel.isObjectExpression(expr)) {
     throw new Error('');
   }
   assert.deepEqual(
       [...getSimpleObjectProperties(expr)].map(
           (prop) => getPropertyName(prop)),
       ['foo', 'bar', '10', '30', 'hi there', undefined]);
 });
开发者ID:MehdiRaash,项目名称:tools,代码行数:24,代码来源:esutil_test.ts


示例2: analyzeProperties

export function analyzeProperties(
    node: babel.Node, document: JavaScriptDocument): ScannedPolymerProperty[] {
  const analyzedProps: ScannedPolymerProperty[] = [];

  if (!babel.isObjectExpression(node)) {
    return analyzedProps;
  }

  for (const property of esutil.getSimpleObjectProperties(node)) {
    const prop = toScannedPolymerProperty(
        property, document.sourceRangeForNode(property)!, document);
    if (prop === undefined) {
      continue;
    }

    // toScannedPolymerProperty does the wrong thing for us with type. We want
    // type to be undefined unless there's a positive signal for the type.
    // toScannedPolymerProperty will give Object because it infers based on the
    // property declaration.
    prop.type = undefined;
    const typeTag = jsdoc.getTag(prop.jsdoc, 'type');
    if (typeTag) {
      prop.type =
          typeTag.type ? doctrine.type.stringify(typeTag.type) : undefined;
    }
    prop.published = true;

    let isComputed = false;

    const value = property.value;
    if (babel.isIdentifier(value)) {
      // Polymer supports this simple syntax, where only the attribute
      // deserializer is specified.
      prop.attributeType = value.name;

    } else if (!babel.isObjectExpression(value)) {
      continue;

    } else {
      /**
       * Parse the expression inside a property object block. e.g.
       * property: {
       *   key: {
       *     type: String,
       *     notify: true,
       *     value: -1,
       *     readOnly: true,
       *     reflectToAttribute: true
       *   }
       * }
       */
      for (const propertyArg of esutil.getSimpleObjectProperties(value)) {
        const propertyKey = esutil.getPropertyName(propertyArg);

        switch (propertyKey) {
          case 'type':
            prop.attributeType = astValue.getIdentifierName(propertyArg.value);
            if (prop.attributeType === undefined && prop.type === undefined) {
              prop.warnings.push(new Warning({
                code: 'invalid-property-type',
                message: 'Invalid type in property object.',
                severity: Severity.WARNING,
                sourceRange: document.sourceRangeForNode(propertyArg)!,
                parsedDocument: document
              }));
            }
            break;
          case 'notify':
            prop.notify = !!astValue.expressionToValue(propertyArg.value);
            break;
          case 'observer':
            const val = astValue.expressionToValue(propertyArg.value);
            prop.observerNode = propertyArg.value;
            const parseResult = parseExpressionInJsStringLiteral(
                document, propertyArg.value, 'identifierOnly');
            prop.warnings.push(...parseResult.warnings);
            prop.observerExpression = parseResult.databinding;
            if (val === undefined) {
              prop.observer = astValue.CANT_CONVERT;
            } else {
              prop.observer = JSON.stringify(val);
            }
            break;
          case 'readOnly':
            prop.readOnly = !!astValue.expressionToValue(propertyArg.value);
            break;
          case 'reflectToAttribute':
            prop.reflectToAttribute =
                !!astValue.expressionToValue(propertyArg.value);
            break;
          case 'computed':
            isComputed = true;
            const computedParseResult = parseExpressionInJsStringLiteral(
                document, propertyArg.value, 'callExpression');
            prop.warnings.push(...computedParseResult.warnings);
            prop.computedExpression = computedParseResult.databinding;
            break;
          case 'value':
            prop.default =
                JSON.stringify(astValue.expressionToValue(propertyArg.value));
//.........这里部分代码省略.........
开发者ID:MehdiRaash,项目名称:tools,代码行数:101,代码来源:analyze-properties.ts


示例3: declarationPropertyHandlers

export function declarationPropertyHandlers(
    declaration: ScannedPolymerElement,
    document: JavaScriptDocument,
    path: NodePath): PropertyHandlers {
  return {
    is(node: babel.Node) {
      if (babel.isLiteral(node)) {
        declaration.tagName = '' + astValue.expressionToValue(node);
      }
    },
    properties(node: babel.Node) {
      for (const prop of analyzeProperties(node, document)) {
        declaration.addProperty(prop);
      }
    },
    behaviors(node: babel.Node) {
      if (!babel.isArrayExpression(node)) {
        return;
      }
      for (const element of node.elements) {
        const result = getBehaviorReference(element, document, path);
        if (result.successful === false) {
          declaration.warnings.push(result.error);
        } else {
          declaration.behaviorAssignments.push(result.value);
        }
      }
    },
    observers(node: babel.Node) {
      const observers = extractObservers(node, document);
      if (!observers) {
        return;
      }
      declaration.warnings = declaration.warnings.concat(observers.warnings);
      declaration.observers = declaration.observers.concat(observers.observers);
    },
    listeners(node: babel.Node) {
      if (!babel.isObjectExpression(node)) {
        declaration.warnings.push(new Warning({
          code: 'invalid-listeners-declaration',
          message: '`listeners` property should be an object expression',
          severity: Severity.WARNING,
          sourceRange: document.sourceRangeForNode(node)!,
          parsedDocument: document
        }));
        return;
      }

      for (const p of getSimpleObjectProperties(node)) {
        const evtName =
            babel.isLiteral(p.key) && astValue.expressionToValue(p.key) ||
            babel.isIdentifier(p.key) && p.key.name;
        const handler =
            !babel.isLiteral(p.value) || astValue.expressionToValue(p.value);

        if (typeof evtName !== 'string' || typeof handler !== 'string') {
          // TODO (maklesoft): Notifiy the user somehow that a listener entry
          // was not extracted
          // because the event or handler namecould not be statically analyzed.
          // E.g. add a low-severity
          // warning once opting out of rules is supported.
          continue;
        }

        declaration.listeners.push({event: evtName, handler: handler});
      }
    }
  };
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:69,代码来源:declaration-property-handlers.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript types.isObjectProperty函数代码示例发布时间:2022-05-28
下一篇:
TypeScript types.isMemberExpression函数代码示例发布时间: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