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


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

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


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

示例1: getPropertyValue

export function getPropertyValue(
    node: babel.ObjectExpression, name: string): babel.Node|undefined {
  const properties = node.properties;
  for (const property of properties) {
    if (!babel.isSpreadProperty(property) &&
        objectKeyToString(property.key) === name) {
      return property.value;
    }
  }
}
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:10,代码来源:esutil.ts

示例2: toConstant


//.........这里部分代码省略.........
         : 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);
   }
   if (b.isRegExpLiteral(expression)) {
     return new RegExp(expression.pattern, expression.flags);
   }
   if (b.isSequenceExpression(expression)) {
     for (let i = 0; i < expression.expressions.length - 1 && constant; i++) {
       toConstant(expression.expressions[i]);
     }
     return toConstant(
       expression.expressions[expression.expressions.length - 1],
     );
   }
   if (b.isStringLiteral(expression)) {
     return expression.value;
   }
   // TODO: TaggedTemplateExpression
   if (b.isTemplateLiteral(expression)) {
     let result = '';
     for (let i = 0; i < expression.quasis.length; i++) {
       const quasi = expression.quasis[i];
       result += quasi.value.cooked;
       if (i < expression.expressions.length) {
         result += '' + toConstant(expression.expressions[i]);
       }
     }
     return result;
   }
   if (b.isUnaryExpression(expression)) {
     const argument = toConstant(expression.argument);
     if (!constant) {
       return;
     }
     switch (expression.operator) {
       case '-':
         return -argument;
       case '+':
         return +argument;
       case '!':
         return !argument;
       case '~':
         return ~argument;
       case 'typeof':
         return typeof argument;
       case 'void':
         return void argument;
     }
   }
   constant = false;
 }
开发者ID:Ashwinie,项目名称:inceptionEngine,代码行数:101,代码来源:index.ts

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

示例4: declarationPropertyHandlers

export function declarationPropertyHandlers(
    declaration: ScannedPolymerElement,
    document: JavaScriptDocument): 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 = getBehaviorAssignmentOrWarning(element, document);
        if (result.kind === 'warning') {
          declaration.warnings.push(result.warning);
        } else {
          declaration.behaviorAssignments.push(result.assignment);
        }
      }
    },
    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 node.properties) {
        if (babel.isSpreadProperty(p)) {
          continue;
        }
        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:asdfg9822,项目名称:polymer-analyzer,代码行数:71,代码来源:declaration-property-handlers.ts


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