migration-rule.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { UpdateRecorder } from '@angular-devkit/schematics';
  9. import * as ts from 'typescript';
  10. import { ResolvedResource } from './component-resource-collector';
  11. import { TargetVersion } from './target-version';
  12. import { LineAndCharacter } from './utils/line-mappings';
  13. export interface MigrationFailure {
  14. filePath: string;
  15. message: string;
  16. position: LineAndCharacter;
  17. }
  18. export declare class MigrationRule<T> {
  19. program: ts.Program;
  20. typeChecker: ts.TypeChecker;
  21. targetVersion: TargetVersion;
  22. upgradeData: T;
  23. /** List of migration failures that need to be reported. */
  24. failures: MigrationFailure[];
  25. /** Whether the migration rule is enabled or not. */
  26. ruleEnabled: boolean;
  27. constructor(program: ts.Program, typeChecker: ts.TypeChecker, targetVersion: TargetVersion, upgradeData: T);
  28. /** Method can be used to perform global analysis of the program. */
  29. init(): void;
  30. /**
  31. * Method that will be called for each node in a given source file. Unlike tslint, this
  32. * function will only retrieve TypeScript nodes that need to be casted manually. This
  33. * allows us to only walk the program source files once per program and not per
  34. * migration rule (significant performance boost).
  35. */
  36. visitNode(node: ts.Node): void;
  37. /** Method that will be called for each Angular template in the program. */
  38. visitTemplate(template: ResolvedResource): void;
  39. /** Method that will be called for each stylesheet in the program. */
  40. visitStylesheet(stylesheet: ResolvedResource): void;
  41. /** Gets the update recorder for a given source file or resolved template. */
  42. getUpdateRecorder(filePath: string): UpdateRecorder;
  43. /** Creates a failure with a specified message at the given node location. */
  44. createFailureAtNode(node: ts.Node, message: string): void;
  45. }