本文整理汇总了TypeScript中ast-types.builders.identifier方法的典型用法代码示例。如果您正苦于以下问题:TypeScript builders.identifier方法的具体用法?TypeScript builders.identifier怎么用?TypeScript builders.identifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ast-types.builders
的用法示例。
在下文中一共展示了builders.identifier方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
});
}
示例3: 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
)
)
)
])
)
]
)
);
}
示例4: moduleExportsExpression
function moduleExportsExpression(id: string): any {
return b.memberExpression(
b.memberExpression(
b.identifier('module'),
b.identifier('exports'),
false
),
b.literal(id),
true
);
}
示例5: 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
)
)
};
}
示例6: 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
)
)
]);
}
示例7: function
visitExportDefaultDeclaration: function(path: IPath<ESTree.ExportDefaultDeclaration>): boolean {
const declaration = path.node.declaration;
if (n.Identifier.check(declaration)) {
// e.g. export default a;
path.replace(
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression('default'),
b.identifier(declaration.name)
)
)
);
} else if (n.FunctionDeclaration.check(declaration) || n.ClassDeclaration.check(declaration)) {
// e.g. export default class {}
path.replace(declaration);
path.insertAfter(
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression('default'),
b.identifier(declaration.id.name)
)
)
);
} else if (n.FunctionExpression.check(declaration)) {
// e.g. export default function() {}
path.replace(
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression('default'),
declaration
)
)
);
}
return false;
}
示例8: 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))
]
)
)
];
}
}
示例9: 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)
]
)
)
]
);
}