property-names.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.PropertyNamesMigration = void 0;
  11. const ts = require("typescript");
  12. const migration_1 = require("../../update-tool/migration");
  13. const upgrade_data_1 = require("../upgrade-data");
  14. /**
  15. * Migration that walks through every property access expression and updates
  16. * accessed properties that have been updated to a new name.
  17. */
  18. class PropertyNamesMigration extends migration_1.Migration {
  19. constructor() {
  20. super(...arguments);
  21. /** Change data that upgrades to the specified target version. */
  22. this.data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'propertyNames');
  23. // Only enable the migration rule if there is upgrade data.
  24. this.enabled = this.data.length !== 0;
  25. }
  26. visitNode(node) {
  27. if (ts.isPropertyAccessExpression(node)) {
  28. this._visitPropertyAccessExpression(node);
  29. }
  30. }
  31. _visitPropertyAccessExpression(node) {
  32. const hostType = this.typeChecker.getTypeAtLocation(node.expression);
  33. const typeNames = [];
  34. if (hostType) {
  35. if (hostType.isIntersection()) {
  36. hostType.types.forEach(type => {
  37. if (type.symbol) {
  38. typeNames.push(type.symbol.getName());
  39. }
  40. });
  41. }
  42. else if (hostType.symbol) {
  43. typeNames.push(hostType.symbol.getName());
  44. }
  45. }
  46. this.data.forEach(data => {
  47. if (node.name.text !== data.replace) {
  48. return;
  49. }
  50. if (!data.limitedTo || typeNames.some(type => data.limitedTo.classes.includes(type))) {
  51. this.fileSystem
  52. .edit(this.fileSystem.resolve(node.getSourceFile().fileName))
  53. .remove(node.name.getStart(), node.name.getWidth())
  54. .insertRight(node.name.getStart(), data.replaceWith);
  55. }
  56. });
  57. }
  58. }
  59. exports.PropertyNamesMigration = PropertyNamesMigration;
  60. //# sourceMappingURL=property-names.js.map