當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。