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


TypeScript ast-types.builders类代码示例

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


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

示例1: function

    visitProgram: function(path: IPath<ESTree.Program>): boolean {
      if (path.scope.lookup('Buffer') === null) {
        const bufferPath = getModulePath('.', 'buffer', context);
        const bufferIndex = getModuleIndex(bufferPath);

        const body = path.get<ESTree.Statement[]>('body');
        body.get(body.value.length - 1).insertBefore(
          b.variableDeclaration(
            'var',
            [
              b.variableDeclarator(
                b.identifier('Buffer'),
                b.memberExpression(
                  b.memberExpression(
                    b.callExpression(
                      b.identifier('__paeckchen_require__'),
                      [
                        b.literal(bufferIndex)
                      ]
                    ),
                    b.identifier('exports'),
                    false
                  ),
                  b.identifier('Buffer'),
                  false
                )
              )
            ]
          )
        );
        enqueueModule(bufferPath);
      }
      return false;
    }
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:34,代码来源:globals.ts

示例2: wrapModule

function wrapModule(modulePath: string, modules: (ESTree.Expression | ESTree.SpreadElement)[],
    context: IPaeckchenContext, detectedGlobals: IDetectedGlobals, plugins: any): void {
  // Prefill module indices
  getModuleIndex(modulePath);
  if (wrappedModules[modulePath].ast !== undefined) {
    // Module is already up to date
    return;
  }

  try {
    let moduleAst: ESTree.Program;
    if (Object.keys(context.config.externals).indexOf(modulePath) !== -1) {
      moduleAst = wrapExternalModule(modulePath, context);
    } else if (!context.host.fileExists(modulePath)) {
      moduleAst = b.program([
        b.throwStatement(
          b.literal(`Module ${modulePath} not found`)
        )
      ]);
    } else {
      moduleAst = processModule(modulePath, context, detectedGlobals, plugins);
    }

    const wrappedModule = createModuleWrapper(modulePath, moduleAst);
    wrappedModules[wrappedModule.name] = wrappedModule;
    modules[wrappedModule.index] = wrappedModule.ast;
  } catch (e) {
    console.error(`Failed to process module '${modulePath}'`);
    throw e;
  }
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:31,代码来源:modules.ts

示例3: rewriteRequireStatements

export function rewriteRequireStatements(program: ESTree.Program, currentModule: string,
    context: IPaeckchenContext): void {
  visit(program, {
    visitCallExpression(path: IPath<ESTree.CallExpression>): boolean {
      const callee = path.node.callee;
      // TODO: check binding here, not name
      if (n.Identifier.check(callee) && callee.name === 'require') {
        const importPath = path.node.arguments[0];
        if (n.Literal.check(importPath)) {
          const modulePath = getModulePath(currentModule, (importPath as ESTree.Literal).value.toString(), context);
          const moduleIndex = getModuleIndex(modulePath);

          path.replace(
            b.memberExpression(
              b.callExpression(
                b.identifier('__paeckchen_require__'),
                [
                  b.literal(moduleIndex)
                ]
              ),
              b.identifier('exports'),
              false
            )
          );

          enqueueModule(modulePath);
        }
        return false;
      }
      this.traverse(path);
    }
  });
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:33,代码来源:commonjs.ts

示例4: moduleExportsExpression

 .map(specifier =>
   b.expressionStatement(
     b.assignmentExpression(
       '=',
       moduleExportsExpression(specifier.exported.name),
       b.literal(specifier.local.name)
     )
   )
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:8,代码来源:es6-export.ts

示例5: importModule

/**
 * var identifier = modules[moduleIndex]();
 */
function importModule(identifier: ESTree.Identifier, moduleIndex: number): ESTree.VariableDeclaration {
  return b.variableDeclaration(
    'var',
    [
      b.variableDeclarator(
        identifier,
        b.callExpression(
          b.identifier('__paeckchen_require__'),
          [
            b.literal(moduleIndex)
          ]
        )
      )
    ]
  );
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:19,代码来源:es6-export.ts

示例6: createModuleWrapper

function createModuleWrapper(name: string, moduleAst: ESTree.Program): IWrappedModule {
  const index = getModuleIndex(name);
  return {
    index,
    name,
    ast: b.functionExpression(
      b.identifier(`_${index}`),
      [
        b.identifier('module'),
        b.identifier('exports')
      ],
      b.blockStatement(
        moduleAst.body
      )
    )
  };
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:17,代码来源:modules.ts

示例7: function

    visitExportAllDeclaration: function(path: IPath<ESTree.ExportAllDeclaration>): boolean {
      // e.g. export * from './a';
      const reexportModuleName = getModulePath(currentModule, path.node.source.value as string, context);
      const reexportModuleIndex = getModuleIndex(reexportModuleName);

      const loc = (pos: ESTree.Position) => `${pos.line}_${pos.column}`;
      const tempIdentifier = b.identifier(`__export${reexportModuleIndex}_${loc(path.node.loc.start)}`);

      path.replace(
        importModule(tempIdentifier, reexportModuleIndex),
        exportAllKeys(tempIdentifier)
      );

      enqueueModule(reexportModuleName);
      return false;
    },
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:16,代码来源:es6-export.ts

示例8: wrapExternalModule

function wrapExternalModule(modulePath: string, context: IPaeckchenContext): ESTree.Program {
  const external = context.config.externals[modulePath] === false
    ? b.objectExpression([])
    : b.identifier(context.config.externals[modulePath] as string);
  return b.program([
    b.expressionStatement(
      b.assignmentExpression(
        '=',
        b.memberExpression(
          b.identifier('module'),
          b.identifier('exports'),
          false
        ),
        external
      )
    )
  ]);
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:18,代码来源:modules.ts


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