本文整理汇总了TypeScript中ast-types.IPath类的典型用法代码示例。如果您正苦于以下问题:TypeScript IPath类的具体用法?TypeScript IPath怎么用?TypeScript IPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPath类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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;
}