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


TypeScript babel-types.exportSpecifier函數代碼示例

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


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

示例1: prepareBundleModule

/**
 * Generate code containing import statements to all bundled modules and
 * export statements to re-export their namespaces and exports.
 *
 * Example: a bundle containing files `module-a.js` and `module-b.js` would
 * result in a prepareBundleModule result like:
 *
 *     import * as $moduleA from './module-a.js';
 *     import * as $moduleB from './module-b.js';
 *     import $moduleBDefault from './module-b.js';
 *     export {thing1, thing2} from './module-a.js';
 *     export {thing3} from './module-b.js';
 *     export {$moduleA, $moduleB, $moduleBDefault};
 */
async function prepareBundleModule(
    bundler: Bundler, manifest: BundleManifest, assignedBundle: AssignedBundle):
    Promise<string> {
      let bundleSource = babel.program([]);
      const sourceAnalysis =
          await bundler.analyzer.analyze([...assignedBundle.bundle.files]);
      for (const sourceUrl of [...assignedBundle.bundle.files].sort()) {
        const rebasedSourceUrl =
            ensureLeadingDot(bundler.analyzer.urlResolver.relative(
                stripUrlFileSearchAndHash(assignedBundle.url), sourceUrl));
        const moduleDocument = getAnalysisDocument(sourceAnalysis, sourceUrl);
        const moduleExports = getModuleExportNames(moduleDocument);
        const starExportName =
            getOrSetBundleModuleExportName(assignedBundle, sourceUrl, '*');
        bundleSource.body.push(babel.importDeclaration(
            [babel.importNamespaceSpecifier(babel.identifier(starExportName))],
            babel.stringLiteral(rebasedSourceUrl)));
        if (moduleExports.size > 0) {
          bundleSource.body.push(babel.exportNamedDeclaration(
              undefined, [babel.exportSpecifier(
                             babel.identifier(starExportName),
                             babel.identifier(starExportName))]));
          bundleSource.body.push(babel.exportNamedDeclaration(
              undefined,
              [...moduleExports].map(
                  (e) => babel.exportSpecifier(
                      babel.identifier(e),
                      babel.identifier(getOrSetBundleModuleExportName(
                          assignedBundle, sourceUrl, e)))),
              babel.stringLiteral(rebasedSourceUrl)));
        }
      }
      const {code} = generate(bundleSource);
      return code;
    }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:49,代碼來源:es6-module-bundler.ts

示例2: rewriteExportAllToNamedExports

 rewriteExportAllToNamedExports(node: babel.Node, analysis: Analysis) {
   traverse(node, {
     noScope: true,
     ExportAllDeclaration: {
       enter(path: NodePath<babel.ExportAllDeclaration>) {
         const exportAllDeclaration = path.node;
         const sourceUrl =
             babel.isStringLiteral(exportAllDeclaration.source) &&
             exportAllDeclaration.source.value;
         if (!sourceUrl) {
           return;
         }
         const sourceDocument = getAnalysisDocument(analysis, sourceUrl);
         const documentExports = sourceDocument.getFeatures({kind: 'export'});
         const specifiers: babel.ExportSpecifier[] = [];
         for (const documentExport of documentExports) {
           for (const exportIdentifier of documentExport.identifiers) {
             const identifierValue = exportIdentifier.valueOf();
             // It does not appear that `export * from` should re-export
             // the default module export of a module.
             if (identifierValue !== 'default') {
               specifiers.push(babel.exportSpecifier(
                   babel.identifier(identifierValue),
                   babel.identifier(identifierValue)));
             }
           }
         }
         const namedExportDeclaration = babel.exportNamedDeclaration(
             undefined, specifiers, babel.stringLiteral(sourceUrl));
         rewriteObject(exportAllDeclaration, namedExportDeclaration);
       }
     }
   });
 }
開發者ID:Polymer,項目名稱:tools,代碼行數:34,代碼來源:es6-rewriter.ts

示例3:

 (e) => babel.exportSpecifier(
     babel.identifier(e),
     babel.identifier(getOrSetBundleModuleExportName(
         assignedBundle, sourceUrl, e)))),
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:4,代碼來源:es6-module-bundler.ts


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