本文整理汇总了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;
}
示例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;
}
}
示例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);
}
});
}
示例4: moduleExportsExpression
.map(specifier =>
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression(specifier.exported.name),
b.literal(specifier.local.name)
)
)
示例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)
]
)
)
]
);
}
示例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
)
)
};
}
示例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;
},
示例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
)
)
]);
}