本文整理匯總了TypeScript中ast-types.builders.expressionStatement方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript builders.expressionStatement方法的具體用法?TypeScript builders.expressionStatement怎麽用?TypeScript builders.expressionStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ast-types.builders
的用法示例。
在下文中一共展示了builders.expressionStatement方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
)
)
)
])
)
]
)
);
}
示例2: moduleExportsExpression
.map(specifier =>
b.expressionStatement(
b.assignmentExpression(
'=',
moduleExportsExpression(specifier.exported.name),
b.literal(specifier.local.name)
)
)
示例3: 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;
}
示例4: 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
)
)
]);
}
示例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))
]
)
)
];
}
}