本文整理匯總了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);
}