当前位置: 首页>>代码示例>>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;未经允许,请勿转载。