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


TypeScript builders.callExpression方法代碼示例

本文整理匯總了TypeScript中ast-types.builders.callExpression方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript builders.callExpression方法的具體用法?TypeScript builders.callExpression怎麽用?TypeScript builders.callExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast-types.builders的用法示例。


在下文中一共展示了builders.callExpression方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

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

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

示例6: function

    visitImportDeclaration: function(path: IPath<ESTree.ImportDeclaration>): boolean {
      const source = path.node.source;

      if (n.Literal.check(source)) {
        const importModule = getModulePath(currentModule, source.value as string, context);
        const importModuleIndex = getModuleIndex(importModule);

        const loc = (pos: ESTree.Position) => `${pos.line}_${pos.column}`;
        const tempIdentifier = b.identifier(`__import${importModuleIndex}_${loc(path.node.loc.start)}`);
        const imports = path.node.specifiers.map((specifier) => {
          if (n.ImportSpecifier.check(specifier)) {
            // e.g. import { a as b, c } from './dep';
            return b.variableDeclarator(
              b.identifier(specifier.local.name),
              b.memberExpression(
                b.memberExpression(
                  tempIdentifier,
                  b.identifier('exports'),
                  false
                ),
                b.literal(specifier.imported.name),
                true
              )
            );
          } else if (n.ImportDefaultSpecifier.check(specifier)) {
            // e.g. import dep from './dep';
            return b.variableDeclarator(
              b.identifier(specifier.local.name),
              b.memberExpression(
                b.memberExpression(
                  tempIdentifier,
                  b.identifier('exports'),
                  false
                ),
                b.literal('default'),
                true
              )
            );
          } else if (n.ImportNamespaceSpecifier.check(specifier)) {
            // e.g. import * as dep from './dep';
            return b.variableDeclarator(
              b.identifier(specifier.local.name),
              b.memberExpression(
                tempIdentifier,
                b.identifier('exports'),
                false
              )
            );
          }
        });
        path.replace(
          b.variableDeclaration(
            'var',
            [
              b.variableDeclarator(
                tempIdentifier,
                b.callExpression(
                  b.identifier('__paeckchen_require__'),
                  [
                    b.literal(importModuleIndex)
                  ]
                )
              ),
              ...imports
            ]
          )
        );

        enqueueModule(importModule);
      }
      return false;
    }
開發者ID:ZauberNerd,項目名稱:paeckchen,代碼行數:72,代碼來源:es6-import.ts

示例7: function

    visitExportNamedDeclaration: function (path: IPath<ESTree.ExportNamedDeclaration>): boolean {
      if (path.node.declaration) {
        const declaration = path.node.declaration;
        if (n.VariableDeclaration.check(declaration)) {
          // e.g. export var a = 0;
          const id = declaration.declarations[0].id;
          path.replace(declaration);
          path.insertAfter(
            b.expressionStatement(
              b.assignmentExpression(
                '=',
                moduleExportsExpression((id as ESTree.Identifier).name),
                b.identifier((id as ESTree.Identifier).name)
              )
            )
          );
        } else if (n.FunctionDeclaration.check(declaration) || n.ClassDeclaration.check(declaration)) {
          // e.g. export function f() {}
          path.replace(declaration);
          path.insertAfter(
            b.expressionStatement(
              b.assignmentExpression(
                '=',
                moduleExportsExpression(declaration.id.name),
                b.identifier(declaration.id.name)
              )
            )
          );
        }
      } else {
        if (path.node.source) {
          // e.g. export {a as b} from './c';
          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)}`);
          const exports = path.node.specifiers
            .map(specifier =>
              b.expressionStatement(
                b.assignmentExpression(
                  '=',
                  moduleExportsExpression(specifier.exported.name),
                  b.memberExpression(
                    b.memberExpression(
                      tempIdentifier,
                      b.identifier('exports'),
                      false
                    ),
                    b.literal(specifier.local.name),
                    true
                  )
                )
              )
            );

          path.replace(
            b.variableDeclaration(
              'var',
              [
                b.variableDeclarator(
                  tempIdentifier,
                  b.callExpression(
                    b.identifier('__paeckchen_require__'),
                    [
                      b.literal(reexportModuleIndex)
                    ]
                  )
                )
              ]
            ),
            ...exports
          );

          enqueueModule(reexportModuleName);
        } else {
          // e.g. export {a as b};
          const exports = path.node.specifiers
            .map(specifier =>
              b.expressionStatement(
                b.assignmentExpression(
                  '=',
                  moduleExportsExpression(specifier.exported.name),
                  b.literal(specifier.local.name)
                )
              )
            );
          path.replace(...exports);
        }
      }
      return false;
    },
開發者ID:ZauberNerd,項目名稱:paeckchen,代碼行數:92,代碼來源:es6-export.ts


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