当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript types.isArrayExpression函数代码示例

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


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

示例1: extractObservers

export function extractObservers(
    observersArray: babel.Node, document: JavaScriptDocument): undefined|
    {observers: Observer[], warnings: Warning[]} {
  if (!babel.isArrayExpression(observersArray)) {
    return;
  }
  let warnings: Warning[] = [];
  const observers = [];
  for (const element of observersArray.elements) {
    let v = astValue.expressionToValue(element);
    if (v === undefined) {
      v = astValue.CANT_CONVERT;
    }
    const parseResult =
        parseExpressionInJsStringLiteral(document, element, 'callExpression');
    warnings = warnings.concat(parseResult.warnings);
    observers.push({
      javascriptNode: element,
      expression: v,
      parsedExpression: parseResult.databinding
    });
  }
  return {observers, warnings};
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:24,代码来源:declaration-property-handlers.ts

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