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

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

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

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



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

示例1: convertAstExpressionToVariable

export function convertAstExpressionToVariable (node) {
  if (t.isObjectExpression(node)) {
    const obj = {}
    const properties = node.properties
    properties.forEach(property => {
      if (property.type === 'ObjectProperty' || property.type === 'ObjectMethod') {
        const key = convertAstExpressionToVariable(property.key)
        const value = convertAstExpressionToVariable(property.value)
        obj[key] = value
      }
    })
    return obj
  } else if (t.isArrayExpression(node)) {
    return node.elements.map(convertAstExpressionToVariable)
  } else if (t.isLiteral(node)) {
    return node['value']
  } else if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
    const name = node.name
    return name === 'undefined'
      ? undefined
      : name
  } else if (t.isJSXExpressionContainer(node)) {
    return convertAstExpressionToVariable(node.expression)
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:25,代码来源:astConvert.ts


示例2: resetTSClassProperty

export function resetTSClassProperty (body) {
  for (const method of body) {
    if (t.isClassMethod(method) && method.kind === 'constructor') {
      for (const statement of cloneDeep(method.body.body)) {
        if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {
          const expr = statement.expression
          const { left, right } = expr
          if (
            t.isMemberExpression(left) &&
              t.isThisExpression(left.object) &&
              t.isIdentifier(left.property)
          ) {
            if (
              (t.isArrowFunctionExpression(right) || t.isFunctionExpression(right)) ||
                (left.property.name === 'config' && t.isObjectExpression(right))
            ) {
              body.push(
                t.classProperty(left.property, right)
              )
              remove(method.body.body, statement)
            }
          }
        }
      }
    }
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:27,代码来源:helper.ts


示例3: 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


示例4: 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


示例5: 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


示例6: toConstant


//.........这里部分代码省略.........
     const right = toConstant(expression.right);
     if (constant && expression.operator === '&&') {
       return left && right;
     }
     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;
开发者ID:Ashwinie,项目名称:inceptionEngine,代码行数:67,代码来源:index.ts


示例7: analyzeProperties

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

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

  for (const property of node.properties) {
    if (babel.isSpreadProperty(property)) {
      continue;
    }
    const prop = toScannedPolymerProperty(
        property, document.sourceRangeForNode(property)!, document);

    // 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 value.properties) {
        if (babel.isSpreadProperty(propertyArg)) {
          continue;
        }
        const propertyKey = esutil.objectKeyToString(propertyArg.key);

        switch (propertyKey) {
          case 'type':
            prop.attributeType = esutil.objectKeyToString(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;
//.........这里部分代码省略.........
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:101,代码来源:analyze-properties.ts


示例8:

 if (elements.some(el => t.isObjectExpression(el as any))) {
开发者ID:topud,项目名称:taro,代码行数:1,代码来源:utils.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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