migration.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.Migration = void 0;
  11. const ts = require("typescript");
  12. class Migration {
  13. constructor(
  14. /** TypeScript program for the migration. */
  15. program,
  16. /** TypeChecker instance for the analysis program. */
  17. typeChecker,
  18. /**
  19. * Version for which the migration rule should run. Null if the migration
  20. * is invoked manually.
  21. */
  22. targetVersion,
  23. /** Context data for the migration. */
  24. context,
  25. /** Upgrade data passed to the migration. */
  26. upgradeData,
  27. /** File system that can be used for modifying files. */
  28. fileSystem,
  29. /** Logger that can be used to print messages as part of the migration. */
  30. logger) {
  31. this.program = program;
  32. this.typeChecker = typeChecker;
  33. this.targetVersion = targetVersion;
  34. this.context = context;
  35. this.upgradeData = upgradeData;
  36. this.fileSystem = fileSystem;
  37. this.logger = logger;
  38. /** List of migration failures that need to be reported. */
  39. this.failures = [];
  40. }
  41. /** Method can be used to perform global analysis of the program. */
  42. init() { }
  43. /**
  44. * Method that will be called once all nodes, templates and stylesheets
  45. * have been visited.
  46. */
  47. postAnalysis() { }
  48. /**
  49. * Method that will be called for each node in a given source file. Unlike tslint, this
  50. * function will only retrieve TypeScript nodes that need to be casted manually. This
  51. * allows us to only walk the program source files once per program and not per
  52. * migration rule (significant performance boost).
  53. */
  54. visitNode(node) { }
  55. /** Method that will be called for each Angular template in the program. */
  56. visitTemplate(template) { }
  57. /** Method that will be called for each stylesheet in the program. */
  58. visitStylesheet(stylesheet) { }
  59. /** Creates a failure with a specified message at the given node location. */
  60. createFailureAtNode(node, message) {
  61. const sourceFile = node.getSourceFile();
  62. this.failures.push({
  63. filePath: this.fileSystem.resolve(sourceFile.fileName),
  64. position: ts.getLineAndCharacterOfPosition(sourceFile, node.getStart()),
  65. message: message,
  66. });
  67. }
  68. }
  69. exports.Migration = Migration;
  70. //# sourceMappingURL=migration.js.map