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


TypeScript doctrine.type类代码示例

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


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

示例1:

 ...tags.filter((tag) => tag.title === 'param').map((param) => {
   return {
     type: param.type ? doctrine.type.stringify(param.type) : 'N/A',
     desc: param.description || '',
     name: param.name || 'N/A'
   };
 }));
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:7,代码来源:docs.ts

示例2: getClosureType

export function getClosureType(
    node: babel.Node,
    parsedJsdoc: doctrine.Annotation|undefined,
    sourceRange: SourceRange,
    document: ParsedDocument): Result<string, Warning> {
  if (parsedJsdoc) {
    const typeTag = jsdoc.getTag(parsedJsdoc, 'type');
    if (typeTag) {
      return {successful: true, value: doctrine.type.stringify(typeTag.type!)};
    }
  }
  const type = VALID_EXPRESSION_TYPES.get(node.type);
  if (type) {
    return {successful: true, value: type};
  }
  if (babel.isIdentifier(node)) {
    return {
      successful: true,
      value: CLOSURE_CONSTRUCTOR_MAP.get(node.name) || node.name
    };
  }
  const warning = new Warning({
    code: 'no-closure-type',
    message: `Unable to determine closure type for expression of type ` +
        `${node.type}`,
    severity: Severity.WARNING,
    sourceRange,
    parsedDocument: document,
  });
  return {successful: false, error: warning};
}
开发者ID:Polymer,项目名称:tools,代码行数:31,代码来源:esutil.ts

示例3: toMethodParam

export function toMethodParam(
    nodeParam: babel.LVal, jsdocAnn?: jsdoc.Annotation): MethodParam {
  const paramTags = new Map<string, doctrine.Tag>();
  let name;
  let defaultValue;
  let rest;

  if (jsdocAnn) {
    for (const tag of (jsdocAnn.tags || [])) {
      if (tag.title === 'param' && tag.name) {
        paramTags.set(tag.name, tag);
      }
    }
  }

  if (babel.isIdentifier(nodeParam)) {
    // Basic parameter: method(param)
    name = nodeParam.name;

  } else if (
      babel.isRestElement(nodeParam) &&
      babel.isIdentifier(nodeParam.argument)) {
    // Rest parameter: method(...param)
    name = nodeParam.argument.name;
    rest = true;

  } else if (
      babel.isAssignmentPattern(nodeParam) &&
      babel.isIdentifier(nodeParam.left)) {
    // Parameter with a default: method(param = "default")
    name = nodeParam.left.name;
    defaultValue = generate(nodeParam.right).code;

  } else {
    // Some AST pattern we don't recognize. Hope the code generator does
    // something reasonable.
    name = generate(nodeParam).code;
  }

  let type;
  let description;
  const tag = paramTags.get(name);
  if (tag) {
    if (tag.type) {
      type = doctrine.type.stringify(tag.type);
    }
    if (tag.description) {
      description = tag.description;
    }
  }

  const param: MethodParam = {name, type, defaultValue, rest, description};
  return param;
}
开发者ID:Polymer,项目名称:tools,代码行数:54,代码来源:esutil.ts

示例4:

tags.forEach((tag) => {
  string = doctrine.type.stringify({type: 'NullableLiteral'});
  string = tag.title;
  string = tag.description || '';
  string = tag.kind || '';
  string = tag.name || '';
  strings = tag.errors || [];
  if (tag.type && tag.type.type === 'NameExpression') {
    string = tag.type.name;
  }
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:11,代码来源:doctrine-tests.ts

示例5:

 return tags.map(function(tag):Tag {
   if (tag.title in CUSTOM_TAGS) {
     return CUSTOM_TAGS[tag.title](tag);
   }
   else {
     return {
       tag:  tag.title,
       type: tag.type ? doctrine.type.stringify(tag.type) : null,
       name: tag.name,
       description: tag.description,
     };
   }
 });
开发者ID:1hemant,项目名称:Test00,代码行数:13,代码来源:jsdoc.ts

示例6: toScannedPolymerProperty

export function toScannedPolymerProperty(
    node: babel.ObjectMethod|babel.ObjectProperty|babel.ClassMethod,
    sourceRange: SourceRange,
    document: ParsedDocument): ScannedPolymerProperty {
  const parsedJsdoc = jsdoc.parseJsdoc(getAttachedComment(node) || '');
  const description = parsedJsdoc.description.trim();
  const maybeName = objectKeyToString(node.key);

  const warnings: Warning[] = [];
  if (!maybeName) {
    warnings.push(new Warning({
      code: 'unknown-prop-name',
      message:
          `Could not determine name of property from expression of type: ` +
          `${node.key.type}`,
      sourceRange: sourceRange,
      severity: Severity.WARNING,
      parsedDocument: document
    }));
  }

  const value = babel.isObjectProperty(node) ? node.value : node;

  let type = closureType(value, sourceRange, document);
  const typeTag = jsdoc.getTag(parsedJsdoc, 'type');
  if (typeTag) {
    type = doctrine.type.stringify(typeTag.type!) || type;
  }
  if (type instanceof Warning) {
    warnings.push(type);
    type = 'Object';
  }
  const name = maybeName || '';
  const result: ScannedPolymerProperty = {
    name,
    type,
    description,
    sourceRange,
    warnings,
    astNode: node,
    isConfiguration: configurationProperties.has(name),
    jsdoc: parsedJsdoc,
    privacy: getOrInferPrivacy(name, parsedJsdoc)
  };

  return result;
};
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:47,代码来源:js-utils.ts

示例7: if

    scannedMethod.params = (value.params || []).map((nodeParam) => {
      let name;
      let defaultValue;
      let rest;

      if (babel.isIdentifier(nodeParam)) {
        // Basic parameter: method(param)
        name = nodeParam.name;

      } else if (
          babel.isRestElement(nodeParam) &&
          babel.isIdentifier(nodeParam.argument)) {
        // Rest parameter: method(...param)
        name = nodeParam.argument.name;
        rest = true;

      } else if (
          babel.isAssignmentPattern(nodeParam) &&
          babel.isIdentifier(nodeParam.left) &&
          babel.isLiteral(nodeParam.right)) {
        // Parameter with a default: method(param = "default")
        name = nodeParam.left.name;
        defaultValue = generate(nodeParam.right).code;

      } else {
        // Some AST pattern we don't recognize. Hope the code generator does
        // something reasonable.
        name = generate(nodeParam).code;
      }

      let type;
      let description;
      const tag = paramTags.get(name);
      if (tag) {
        if (tag.type) {
          type = doctrine.type.stringify(tag.type);
        }
        if (tag.description) {
          description = tag.description;
        }
      }

      const param: MethodParam = {name, type, defaultValue, rest, description};
      return param;
    });
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:45,代码来源:esutil.ts

示例8: annotateProperty

/**
 * Annotates documentation found about a scanned polymer property.
 *
 * @param feature
 * @param ignoreConfiguration If true, `configuration` is not set.
 * @return The descriptior that was given.
 */
function annotateProperty(feature: ScannedPolymerProperty):
    ScannedPolymerProperty {
  annotate(feature);

  // @type JSDoc wins
  const typeTag = jsdoc.getTag(feature.jsdoc, 'type');
  if (typeTag !== undefined && typeTag.type != null) {
    feature.type = doctrine.type.stringify(typeTag.type);
  }

  // @default JSDoc wins
  const defaultTag = jsdoc.getTag(feature.jsdoc, 'default');
  if (defaultTag !== undefined) {
    const newDefault = (defaultTag.name || '') + (defaultTag.description || '');
    if (newDefault !== '') {
      feature.default = newDefault;
    }
  }

  return feature;
}
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:28,代码来源:docs.ts

示例9: getReturnFromAnnotation

export function getReturnFromAnnotation(jsdocAnn: jsdoc.Annotation):
    {type?: string, desc?: string}|undefined {
  const tag =
      jsdoc.getTag(jsdocAnn, 'return') || jsdoc.getTag(jsdocAnn, 'returns');

  if (!tag || (!tag.type && !tag.description)) {
    return undefined;
  }

  const type: {type?: string, desc?: string} = {};

  if (tag && (tag.type || tag.description)) {
    if (tag.type) {
      type.type = doctrine.type.stringify(tag.type);
    }
    if (tag.description) {
      type.desc = tag.description;
    }
  }

  return type;
}
开发者ID:Polymer,项目名称:tools,代码行数:22,代码来源:esutil.ts

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


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