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


TypeScript builders.literal方法代码示例

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


在下文中一共展示了builders.literal方法的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: 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: 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

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

 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
       )
     );
   }
 });
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:41,代码来源:es6-import.ts

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

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

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


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