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


TypeScript builders.blockStatement方法代码示例

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


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

示例1: exportAllKeys

/**
 * Object.keys(identifier).forEach(function(key) {
 *   module.exports[key] = identifier.exports[key];
 * });
 */
function exportAllKeys(identifier: ESTree.Identifier): ESTree.ExpressionStatement {
  return b.expressionStatement(
    b.callExpression(
      b.memberExpression(
        b.callExpression(
          b.memberExpression(
            b.identifier('Object'),
            b.identifier('keys'),
            false
          ),
          [
            b.memberExpression(
              identifier,
              b.identifier('exports'),
              false
            )
          ]
        ),
        b.identifier('forEach'),
        false
      ),
      [
        b.functionExpression(
          null,
          [
            b.identifier('key')
          ],
          b.blockStatement([
            b.expressionStatement(
              b.assignmentExpression(
                '=',
                b.memberExpression(
                  b.memberExpression(
                    b.identifier('module'),
                    b.identifier('exports'),
                    false
                  ),
                  b.identifier('key'),
                  true
                ),
                b.memberExpression(
                  b.memberExpression(
                    identifier,
                    b.identifier('exports'),
                    false
                  ),
                  b.identifier('key'),
                  true
                )
              )
            )
          ])
        )
      ]
    )
  );
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:62,代码来源:es6-export.ts

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

示例3: rewriteGlobalLocals

export function rewriteGlobalLocals(program: ESTree.Program, currentModule: string, context: IPaeckchenContext): void {
  let detectedFilename = false;
  let detectedDirname = false;
  visit(program, {
    visitIdentifier: function(path: IPath<ESTree.Identifier>): void {
      if (path.node.name === '__filename' && path.scope.lookup('__filename') === null) {
        detectedFilename = true;
      } else if (path.node.name === '__dirname' && path.scope.lookup('__dirname') === null) {
        detectedDirname = true;
      }
      if (detectedFilename && detectedDirname) {
        this.abort();
      }
      this.traverse(path);
    }
  });

  if (detectedFilename || detectedDirname) {
    program.body = [
      b.expressionStatement(
        b.callExpression(
          b.functionExpression(
            null,
            [
              b.identifier('__filename'),
              b.identifier('__dirname')
            ],
            b.blockStatement(
              program.body
            )
          ),
          [
            b.literal(currentModule.substring(context.host.cwd().length)),
            b.literal(context.host.dirname(currentModule).substring(context.host.cwd().length))
          ]
        )
      )
    ];
  }
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:40,代码来源:global-locals.ts


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