當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript generator.default函數代碼示例

本文整理匯總了TypeScript中@babel/generator.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

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

示例2: rewriteBareModuleSpecifiers

export function rewriteBareModuleSpecifiers(
    code: string, packageVersions: PackageVersionMap, rootPackage: string):
    string {
  const jsAST = babelParser.parse(
      code, {sourceType: 'module', plugins: ['dynamicImport']});
  for (const node of jsAST.program.body) {
    if ((node.type === 'ImportDeclaration' ||
         node.type === 'ExportNamedDeclaration' ||
         node.type === 'ExportAllDeclaration') &&
        node.source) {
      if (isBareModuleSpecifier(node.source.value)) {
        const parsedPackage = parsePackageName(node.source.value);
        const version = packageVersions[parsedPackage.package];
        const versionString = version ? '@' + version : '';
        const queryString = rootPackage ? '?' + rootPackage : '';
        node.source.value = `/${parsedPackage.package}${versionString}${
            parsedPackage.path}${queryString}`;
      } else {
        // Append rootPackage to relative URLs.
        const parsedUrl = url.parse(node.source.value);
        if (!parsedUrl.protocol) {
          parsedUrl.search = rootPackage || '';
          node.source.value = url.format(parsedUrl);
        }
      }
    }
  }

  const outputJs = babelGenerate(jsAST, {retainLines: true}, code);
  return outputJs.code;
}
開發者ID:customelements,項目名稱:v2,代碼行數:31,代碼來源:html-rewriter.ts

示例3: invariant

 const evalFn = (n: t.Node) => {
   // variable
   if (t.isIdentifier(n)) {
     invariant(
       staticNamespace.hasOwnProperty(n.name),
       'identifier not in staticNamespace'
     );
     return staticNamespace[n.name];
   }
   return vm.runInContext(`(${generate(n).code})`, evalContext);
 };
開發者ID:petehunt,項目名稱:jsxstyle,代碼行數:11,代碼來源:extractStyles.ts

示例4: it

 it('returns the original prop value if no spread attributes appear before the requested prop', () => {
   // TODO: update to use `resolves` when Jest 20 is released
   const ast = parse(`<Block {...spread} thing={Wow} />`);
   const statement = ast.program.body[0] as t.ExpressionStatement;
   const jsxElement = statement.expression as t.JSXElement;
   const node = jsxElement.openingElement;
   const componentPropValue = getPropValueFromAttributes(
     'thing',
     node.attributes
   );
   expect(generate(componentPropValue).code).toEqual('Wow');
 });
開發者ID:petehunt,項目名稱:jsxstyle,代碼行數:12,代碼來源:getPropValueFromAttributes.spec.ts

示例5: Error

 node.attributes.forEach(attr => {
   if (
     !t.isJSXAttribute(attr) ||
     typeof attr.name.name !== 'string' ||
     !t.isJSXExpressionContainer(attr.value)
   ) {
     throw new Error(
       'Received invalid JSXAttribute: ' + generate(attr).code
     );
   }
   testItems[nodeName.name].attrs[attr.name.name] = attr.value.expression;
 });
開發者ID:petehunt,項目名稱:jsxstyle,代碼行數:12,代碼來源:getStaticBindingsForScope.spec.ts

示例6: invariant

 // 1. idx is greater than propValue prop index
 // 2. attr is a spread operator
 (attr, idx): attr is t.JSXSpreadAttribute => {
   if (t.isJSXSpreadAttribute(attr)) {
     invariant(
       // only allow member expressions and identifiers to be spread for now
       t.isIdentifier(attr.argument) ||
         t.isMemberExpression(attr.argument),
       'Unhandled spread operator value of type `%s` (`%s`)',
       attr.argument.type,
       generate(attr).code
     );
     return idx > propIndex;
   }
   return false;
 }
開發者ID:petehunt,項目名稱:jsxstyle,代碼行數:16,代碼來源:getPropValueFromAttributes.ts

示例7: generate

const evalFn = n => vm.runInContext('(' + generate(n).code + ')', ctx);
開發者ID:petehunt,項目名稱:jsxstyle,代碼行數:1,代碼來源:evaluateAstNode.spec.ts


注:本文中的@babel/generator.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。