當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ast-utils.addImportToModule函數代碼示例

本文整理匯總了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);
}
開發者ID:formly-js,項目名稱:ng2-formly,代碼行數:19,代碼來源:ast.ts

示例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);
  }
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:19,代碼來源:add-to-modules.ts

示例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);
}
開發者ID:codef0rmer,項目名稱:material2,代碼行數:22,代碼來源:ast.ts


注:本文中的@schematics/angular/utility/ast-utils.addImportToModule函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。