class-inheritance.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.ClassInheritanceMigration = void 0;
  11. const ts = require("typescript");
  12. const migration_1 = require("../../update-tool/migration");
  13. const base_types_1 = require("../typescript/base-types");
  14. const upgrade_data_1 = require("../upgrade-data");
  15. /**
  16. * Migration that identifies class declarations that extend CDK or Material classes
  17. * which had a public property change.
  18. */
  19. class ClassInheritanceMigration extends migration_1.Migration {
  20. constructor() {
  21. super(...arguments);
  22. /**
  23. * Map of classes that have been updated. Each class name maps to the according property
  24. * change data.
  25. */
  26. this.propertyNames = new Map();
  27. // Only enable the migration rule if there is upgrade data.
  28. this.enabled = this.propertyNames.size !== 0;
  29. }
  30. init() {
  31. (0, upgrade_data_1.getVersionUpgradeData)(this, 'propertyNames')
  32. .filter(data => data.limitedTo && data.limitedTo.classes)
  33. .forEach(data => data.limitedTo.classes.forEach(name => this.propertyNames.set(name, data)));
  34. }
  35. visitNode(node) {
  36. if (ts.isClassDeclaration(node)) {
  37. this._visitClassDeclaration(node);
  38. }
  39. }
  40. _visitClassDeclaration(node) {
  41. const baseTypes = (0, base_types_1.determineBaseTypes)(node);
  42. const className = node.name ? node.name.text : '{unknown-name}';
  43. if (!baseTypes) {
  44. return;
  45. }
  46. baseTypes.forEach(typeName => {
  47. const data = this.propertyNames.get(typeName);
  48. if (data) {
  49. this.createFailureAtNode(node, `Found class "${className}" which extends class ` +
  50. `"${typeName}". Please note that the base class property ` +
  51. `"${data.replace}" has changed to "${data.replaceWith}". ` +
  52. `You may need to update your class as well.`);
  53. }
  54. });
  55. }
  56. }
  57. exports.ClassInheritanceMigration = ClassInheritanceMigration;
  58. //# sourceMappingURL=class-inheritance.js.map