source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/input-names.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: 8.7 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.InputNamesMigration = void 0;
11const angular_1 = require("../html-parsing/angular");
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 template or stylesheet and replaces outdated input
17 * names to the new input name. Selectors in stylesheets could also target input
18 * bindings declared as static attribute. See for example:
19 *
20 * e.g. `<my-component color="primary">` becomes `my-component[color]`
21 */
22class InputNamesMigration extends migration_1.Migration {
23 constructor() {
24 super(...arguments);
25 /** Change data that upgrades to the specified target version. */
26 this.data = upgrade_data_1.getVersionUpgradeData(this, 'inputNames');
27 // Only enable the migration rule if there is upgrade data.
28 this.enabled = this.data.length !== 0;
29 }
30 visitStylesheet(stylesheet) {
31 this.data.forEach(name => {
32 const currentSelector = `[${name.replace}]`;
33 const updatedSelector = `[${name.replaceWith}]`;
34 literal_1.findAllSubstringIndices(stylesheet.content, currentSelector)
35 .map(offset => stylesheet.start + offset)
36 .forEach(start => this._replaceInputName(stylesheet.filePath, start, currentSelector.length, updatedSelector));
37 });
38 }
39 visitTemplate(template) {
40 this.data.forEach(name => {
41 const limitedTo = name.limitedTo;
42 const relativeOffsets = [];
43 if (limitedTo.attributes) {
44 relativeOffsets.push(...angular_1.findInputsOnElementWithAttr(template.content, name.replace, limitedTo.attributes));
45 }
46 if (limitedTo.elements) {
47 relativeOffsets.push(...angular_1.findInputsOnElementWithTag(template.content, name.replace, limitedTo.elements));
48 }
49 relativeOffsets.map(offset => template.start + offset)
50 .forEach(start => this._replaceInputName(template.filePath, start, name.replace.length, name.replaceWith));
51 });
52 }
53 _replaceInputName(filePath, start, width, newName) {
54 this.fileSystem.edit(filePath)
55 .remove(start, width)
56 .insertRight(start, newName);
57 }
58}
59exports.InputNamesMigration = InputNamesMigration;
60//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQtbmFtZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3NjaGVtYXRpY3MvbmctdXBkYXRlL21pZ3JhdGlvbnMvaW5wdXQtbmFtZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7O0FBR0gscURBQWdHO0FBRWhHLDJEQUFzRDtBQUd0RCxtREFBOEQ7QUFDOUQsa0RBQW1FO0FBRW5FOzs7Ozs7R0FNRztBQUNILE1BQWEsbUJBQW9CLFNBQVEscUJBQXNCO0lBQS9EOztRQUNFLGlFQUFpRTtRQUNqRSxTQUFJLEdBQTJCLG9DQUFxQixDQUFDLElBQUksRUFBRSxZQUFZLENBQUMsQ0FBQztRQUV6RSwyREFBMkQ7UUFDM0QsWUFBTyxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLENBQUMsQ0FBQztJQTJDbkMsQ0FBQztJQXpDVSxlQUFlLENBQUMsVUFBNEI7UUFDbkQsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEVBQUU7WUFDdkIsTUFBTSxlQUFlLEdBQUcsSUFBSSxJQUFJLENBQUMsT0FBTyxHQUFHLENBQUM7WUFDNUMsTUFBTSxlQUFlLEdBQUcsSUFBSSxJQUFJLENBQUMsV0FBVyxHQUFHLENBQUM7WUFFaEQsaUNBQXVCLENBQUMsVUFBVSxDQUFDLE9BQU8sRUFBRSxlQUFlLENBQUM7aUJBQ3ZELEdBQUcsQ0FBQyxNQUFNLEN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uICAgICAgICByZWxhdGl2ZU9mZnNldHMucHVzaChcbiAgICAgICAgICAgIC4uLmZpbmRJbnB1dHNPbkVsZW1lbnRXaXRoQXR0cih0ZW1wbGF0ZS5jb250ZW50LCBuYW1lLnJlcGxhY2UsIGxpbWl0ZWRUby5hdHRyaWJ1dGVzKSk7XG4gICAgICB9XG5cbiAgICAgIGlmIChsaW1pdGVkVG8uZWxlbWVudHMpIHtcbiAgICAgICAgcmVsYXRpdmVPZmZzZXRzLnB1c2goXG4gICAgICAgICAgICAuLi5maW5kSW5wdXRzT25FbGVtZW50V2l0aFRhZyh0ZW1wbGF0ZS5jb250ZW50LCBuYW1lLnJlcGxhY2UsIGxpbWl0ZWRUby5lbGVtZW50cykpO1xuICAgICAgfVxuXG4gICAgICByZWxhdGl2ZU9mZnNldHMubWFwKG9mZnNldCA9PiB0ZW1wbGF0ZS5zdGFydCArIG9mZnNldClcbiAgICAgICAgICAuZm9yRWFjaChcbiAgICAgICAgICAgICAgc3RhcnQgPT4gdGhpcy5fcmVwbGFjZUlucHV0TmFtZShcbiAgICAgICAgICAgICAgICAgIHRlbXBsYXRlLmZpbGVQYXRoLCBzdGFydCwgbmFtZS5yZXBsYWNlLmxlbmd0aCwgbmFtZS5yZXBsYWNlV2l0aCkpO1xuICAgIH0pO1xuICB9XG5cbiAgcHJpdmF0ZSBfcmVwbGFjZUlucHV0TmFtZShmaWxlUGF0aDogV29ya3NwYWNlUGF0aCwgc3RhcnQ6IG51bWJlciwgd2lkdGg6IG51bWJlcixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXdOYW1lOiBzdHJpbmcpIHtcbiAgICB0aGlzLmZpbGVTeXN0ZW0uZWRpdChmaWxlUGF0aClcbiAgICAgIC5yZW1vdmUoc3RhcnQsIHdpZHRoKVxuICAgICAgLmluc2VydFJpZ2h0KHN0YXJ0LCBuZXdOYW1lKTtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.