symbol-removal.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.SymbolRemovalMigration = void 0;
  11. const ts = require("typescript");
  12. const migration_1 = require("../../update-tool/migration");
  13. const upgrade_data_1 = require("../upgrade-data");
  14. /** Migration that flags imports for symbols that have been removed. */
  15. class SymbolRemovalMigration extends migration_1.Migration {
  16. constructor() {
  17. super(...arguments);
  18. /** Change data that upgrades to the specified target version. */
  19. this.data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'symbolRemoval');
  20. // Only enable the migration rule if there is upgrade data.
  21. this.enabled = this.data.length !== 0;
  22. }
  23. visitNode(node) {
  24. if (!ts.isImportDeclaration(node) || !ts.isStringLiteral(node.moduleSpecifier)) {
  25. return;
  26. }
  27. const namedBindings = node.importClause && node.importClause.namedBindings;
  28. if (!namedBindings || !ts.isNamedImports(namedBindings)) {
  29. return;
  30. }
  31. const moduleNameMatches = this.data.filter(entry => node.moduleSpecifier.text === entry.module);
  32. if (!moduleNameMatches.length) {
  33. return;
  34. }
  35. namedBindings.elements.forEach(element => {
  36. var _a;
  37. const elementName = ((_a = element.propertyName) === null || _a === void 0 ? void 0 : _a.text) || element.name.text;
  38. moduleNameMatches.forEach(match => {
  39. if (match.name === elementName) {
  40. this.createFailureAtNode(element, match.message);
  41. }
  42. });
  43. });
  44. }
  45. }
  46. exports.SymbolRemovalMigration = SymbolRemovalMigration;
  47. //# sourceMappingURL=symbol-removal.js.map