property-names-rule.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. const migration_rule_1 = require("../../update-tool/migration-rule");
  12. const upgrade_data_1 = require("../upgrade-data");
  13. /**
  14. * Rule that walks through every property access expression and updates
  15. * accessed properties that have been updated to a new name.
  16. */
  17. class PropertyNamesRule extends migration_rule_1.MigrationRule {
  18. constructor() {
  19. super(...arguments);
  20. /** Change data that upgrades to the specified target version. */
  21. this.data = upgrade_data_1.getVersionUpgradeData(this, 'propertyNames');
  22. // Only enable the migration rule if there is upgrade data.
  23. this.ruleEnabled = this.data.length !== 0;
  24. }
  25. visitNode(node) {
  26. if (ts.isPropertyAccessExpression(node)) {
  27. this._visitPropertyAccessExpression(node);
  28. }
  29. }
  30. _visitPropertyAccessExpression(node) {
  31. const hostType = this.typeChecker.getTypeAtLocation(node.expression);
  32. const typeName = hostType && hostType.symbol && hostType.symbol.getName();
  33. this.data.forEach(data => {
  34. if (node.name.text !== data.replace) {
  35. return;
  36. }
  37. if (!data.whitelist || data.whitelist.classes.includes(typeName)) {
  38. const recorder = this.getUpdateRecorder(node.getSourceFile().fileName);
  39. recorder.remove(node.name.getStart(), node.name.getWidth());
  40. recorder.insertRight(node.name.getStart(), data.replaceWith);
  41. }
  42. });
  43. }
  44. }
  45. exports.PropertyNamesRule = PropertyNamesRule;
  46. //# sourceMappingURL=property-names-rule.js.map