"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyNamesMigration = void 0; const ts = require("typescript"); const migration_1 = require("../../update-tool/migration"); const upgrade_data_1 = require("../upgrade-data"); /** * Migration that walks through every property access expression and updates * accessed properties that have been updated to a new name. */ class PropertyNamesMigration extends migration_1.Migration { /** Change data that upgrades to the specified target version. */ data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'propertyNames'); // Only enable the migration rule if there is upgrade data. enabled = this.data.length !== 0; visitNode(node) { if (ts.isPropertyAccessExpression(node)) { this._visitPropertyAccessExpression(node); } } _visitPropertyAccessExpression(node) { const hostType = this.typeChecker.getTypeAtLocation(node.expression); const typeNames = []; if (hostType) { if (hostType.isIntersection()) { hostType.types.forEach(type => { if (type.symbol) { typeNames.push(type.symbol.getName()); } }); } else if (hostType.symbol) { typeNames.push(hostType.symbol.getName()); } } this.data.forEach(data => { if (node.name.text !== data.replace) { return; } if (!data.limitedTo || typeNames.some(type => data.limitedTo.classes.includes(type))) { this.fileSystem .edit(this.fileSystem.resolve(node.getSourceFile().fileName)) .remove(node.name.getStart(), node.name.getWidth()) .insertRight(node.name.getStart(), data.replaceWith); } }); } } exports.PropertyNamesMigration = PropertyNamesMigration; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvcGVydHktbmFtZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3NjaGVtYXRpY3MvbmctdXBkYXRlL21pZ3JhdGlvbnMvcHJvcGVydHktbmFtZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7O0FBRUgsaUNBQWlDO0FBQ2pDLDJEQUFzRDtBQUd0RCxrREFBbUU7QUFFbkU7OztHQUdHO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