本文整理汇总了TypeScript中@schematics/angular/utility/ast-utils.addImportToModule函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addImportToModule函数的具体用法?TypeScript addImportToModule怎么用?TypeScript addImportToModule使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addImportToModule函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addModuleImportToModule
export function addModuleImportToModule(
host: Tree, modulePath: string, moduleName: string, src: string) {
const moduleSource = getSourceFile(host, modulePath);
if (!moduleSource) {
throw new SchematicsException(`Module not found: ${modulePath}`);
}
const changes = addImportToModule(moduleSource, modulePath, moduleName, src);
const recorder = host.beginUpdate(modulePath);
changes.forEach((change) => {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
});
host.commitUpdate(recorder);
}
示例2: processRoutingModule
function processRoutingModule(tree: Tree, modulePath: Path) {
const moduleDeclarations = getClassWithDecorator(tree, modulePath, 'NgModule');
if (!moduleDeclarations.length) {
return;
}
const featureModulePath = findFeatureModule(tree, dirname(modulePath));
if (!featureModulePath) {
throw new SchematicsException(`Can't find module for routing module ${featureModulePath }.`);
}
const featureModuleSource = getSourceFile(tree, featureModulePath);
const importString = importPath(featureModulePath, modulePath);
for (const moduleDeclaration of moduleDeclarations) {
const className = (moduleDeclaration.name as ts.Identifier).getText();
const changes = addImportToModule(featureModuleSource, featureModulePath, className, importString);
applyInsertChange(tree, featureModulePath, ...changes);
}
}
示例3: addModuleImportToModule
export function addModuleImportToModule(host: Tree, modulePath: string, moduleName: string,
src: string) {
const moduleSource = getSourceFile(host, modulePath);
if (!moduleSource) {
throw new SchematicsException(`Module not found: ${modulePath}`);
}
// TODO: TypeScript version mismatch due to @schematics/angular using a different version
// than Material. Cast to any to avoid the type assignment failure.
const changes = addImportToModule(moduleSource as any, modulePath, moduleName, src);
const recorder = host.beginUpdate(modulePath);
changes.forEach((change) => {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
});
host.commitUpdate(recorder);
}