source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/attribute-selectors.mjs

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

initial commit

  • Property mode set to 100644
File size: 9.6 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.AttributeSelectorsMigration = void 0;
11const ts = require("typescript");
12const migration_1 = require("../../update-tool/migration");
13const literal_1 = require("../typescript/literal");
14const upgrade_data_1 = require("../upgrade-data");
15/**
16 * Migration that walks through every string literal, template and stylesheet
17 * in order to switch deprecated attribute selectors to the updated selector.
18 */
19class AttributeSelectorsMigration extends migration_1.Migration {
20 constructor() {
21 super(...arguments);
22 /** Required upgrade changes for specified target version. */
23 this.data = upgrade_data_1.getVersionUpgradeData(this, 'attributeSelectors');
24 // Only enable the migration rule if there is upgrade data.
25 this.enabled = this.data.length !== 0;
26 }
27 visitNode(node) {
28 if (ts.isStringLiteralLike(node)) {
29 this._visitStringLiteralLike(node);
30 }
31 }
32 visitTemplate(template) {
33 this.data.forEach(selector => {
34 literal_1.findAllSubstringIndices(template.content, selector.replace)
35 .map(offset => template.start + offset)
36 .forEach(start => this._replaceSelector(template.filePath, start, selector));
37 });
38 }
39 visitStylesheet(stylesheet) {
40 this.data.forEach(selector => {
41 const currentSelector = `[${selector.replace}]`;
42 const updatedSelector = `[${selector.replaceWith}]`;
43 literal_1.findAllSubstringIndices(stylesheet.content, currentSelector)
44 .map(offset => stylesheet.start + offset)
45 .forEach(start => this._replaceSelector(stylesheet.filePath, start, { replace: currentSelector, replaceWith: updatedSelector }));
46 });
47 }
48 _visitStringLiteralLike(literal) {
49 if (literal.parent && literal.parent.kind !== ts.SyntaxKind.CallExpression) {
50 return;
51 }
52 const literalText = literal.getText();
53 const filePath = this.fileSystem.resolve(literal.getSourceFile().fileName);
54 this.data.forEach(selector => {
55 literal_1.findAllSubstringIndices(literalText, selector.replace)
56 .map(offset => literal.getStart() + offset)
57 .forEach(start => this._replaceSelector(filePath, start, selector));
58 });
59 }
60 _replaceSelector(filePath, start, data) {
61 this.fileSystem.edit(filePath)
62 .remove(start, data.replace.length)
63 .insertRight(start, data.replaceWith);
64 }
65}
66exports.AttributeSelectorsMigration = AttributeSelectorsMigration;
67//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNlbGVjdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvc2NoZW1hdGljcy9uZy11cGRhdGUvbWlncmF0aW9ucy9hdHRyaWJ1dGUtc2VsZWN0b3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7OztBQUVILGlDQUFpQztBQUdqQywyREFBc0Q7QUFFdEQsbURBQThEO0FBQzlELGtEQUFtRTtBQUVuRTs7O0dBR0c7QUFDSCxNQUFhLDJCQUE0QixTQUFRLHFCQUFzQjtJQUF2RTs7UUFDRSw2REFBNkQ7UUFDN0QsU0FBSSxHQUFHLG9DQUFxQixDQUFDLElBQUksRUFBRSxvQkFBb0IsQ0FBQyxDQUFDO1FBRXpELDJEQUEyRDtRQUMzRCxZQUFPLEdBQVksSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLEtBQUssQ0FBQyxDQUFDO0lBbUQ1QyxDQUFDO0lBakRVLFNBQVMsQ0FBQyxJQUFhO1FBQzlCLElBQUksRUFBRSxDQUFDLG1CQUFtQixDQUFDLElBQUksQ0FBQyxFQUFFO1lBQ2hDLElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxJQUFJLENBQUMsQ0FBQztTQUNwQztJQUNILENBQUM7SUFFUSxhQUFhLENBQUMsUUFBMEI7UUFDL0MsSUFBSSxDQU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