source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/property-names.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.0 KB
Line 
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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.PropertyNamesMigration = void 0;
11const ts = require("typescript");
12const migration_1 = require("../../update-tool/migration");
13const 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 */
18class PropertyNamesMigration extends migration_1.Migration {
19 constructor() {
20 super(...arguments);
21 /** Change data that upgrades to the specified target version. */
22 this.data = 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.edit(this.fileSystem.resolve(node.getSourceFile().fileName))
52 .remove(node.name.getStart(), node.name.getWidth())
53 .insertRight(node.name.getStart(), data.replaceWith);
54 }
55 });
56 }
57}
58exports.PropertyNamesMigration = PropertyNamesMigration;
59//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJm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Z2V0TmFtZSgpKTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICB0aGlzLmRhdGEuZm9yRWFjaChkYXRhID0+IHtcbiAgICAgIGlmIChub2RlLm5hbWUudGV4dCAhPT0gZGF0YS5yZXBsYWNlKSB7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cblxuICAgICAgaWYgKCFkYXRhLmxpbWl0ZWRUbyB8fCB0eXBlTmFtZXMuc29tZSh0eXBlID0+IGRhdGEubGltaXRlZFRvLmNsYXNzZXMuaW5jbHVkZXModHlwZSkpKSB7XG4gICAgICAgIHRoaXMuZmlsZVN5c3RlbS5lZGl0KHRoaXMuZmlsZVN5c3RlbS5yZXNvbHZlKG5vZGUuZ2V0U291cmNlRmlsZSgpLmZpbGVOYW1lKSlcbiAgICAgICAgICAucmVtb3ZlKG5vZGUubmFtZS5nZXRTdGFydCgpLCBub2RlLm5hbWUuZ2V0V2lkdGgoKSlcbiAgICAgICAgICAuaW5zZXJ0UmlnaHQobm9kZS5uYW1lLmdldFN0YXJ0KCksIGRhdGEucmVwbGFjZVdpdGgpO1xuICAgICAgfVxuICAgIH0pO1xuICB9XG59XG4iXX0=
Note: See TracBrowser for help on using the repository browser.