migration-rule.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const ts = require("typescript");
  11. class MigrationRule {
  12. constructor(program, typeChecker, targetVersion, upgradeData) {
  13. this.program = program;
  14. this.typeChecker = typeChecker;
  15. this.targetVersion = targetVersion;
  16. this.upgradeData = upgradeData;
  17. /** List of migration failures that need to be reported. */
  18. this.failures = [];
  19. /** Whether the migration rule is enabled or not. */
  20. this.ruleEnabled = true;
  21. }
  22. /** Method can be used to perform global analysis of the program. */
  23. init() { }
  24. /**
  25. * Method that will be called for each node in a given source file. Unlike tslint, this
  26. * function will only retrieve TypeScript nodes that need to be casted manually. This
  27. * allows us to only walk the program source files once per program and not per
  28. * migration rule (significant performance boost).
  29. */
  30. visitNode(node) { }
  31. /** Method that will be called for each Angular template in the program. */
  32. visitTemplate(template) { }
  33. /** Method that will be called for each stylesheet in the program. */
  34. visitStylesheet(stylesheet) { }
  35. /** Gets the update recorder for a given source file or resolved template. */
  36. getUpdateRecorder(filePath) {
  37. throw new Error('MigrationRule#getUpdateRecorder is not implemented.');
  38. }
  39. /** Creates a failure with a specified message at the given node location. */
  40. createFailureAtNode(node, message) {
  41. const sourceFile = node.getSourceFile();
  42. this.failures.push({
  43. filePath: sourceFile.fileName,
  44. position: ts.getLineAndCharacterOfPosition(sourceFile, node.getStart()),
  45. message: message,
  46. });
  47. }
  48. }
  49. exports.MigrationRule = MigrationRule;
  50. //# sourceMappingURL=migration-rule.js.map