UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

60 lines 2.31 kB
"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.dev/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 { constructor() { super(...arguments); /** Change data that upgrades to the specified target version. */ this.data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'propertyNames'); // Only enable the migration rule if there is upgrade data. this.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=property-names.js.map