source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/css-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.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.CssSelectorsMigration = 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 in
17 * order to migrate outdated CSS selectors to the new selector.
18 */
19class CssSelectorsMigration extends migration_1.Migration {
20 constructor() {
21 super(...arguments);
22 /** Change data that upgrades to the specified target version. */
23 this.data = upgrade_data_1.getVersionUpgradeData(this, 'cssSelectors');
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(data => {
34 if (data.replaceIn && !data.replaceIn.html) {
35 return;
36 }
37 literal_1.findAllSubstringIndices(template.content, data.replace)
38 .map(offset => template.start + offset)
39 .forEach(start => this._replaceSelector(template.filePath, start, data));
40 });
41 }
42 visitStylesheet(stylesheet) {
43 this.data.forEach(data => {
44 if (data.replaceIn && !data.replaceIn.stylesheet) {
45 return;
46 }
47 literal_1.findAllSubstringIndices(stylesheet.content, data.replace)
48 .map(offset => stylesheet.start + offset)
49 .forEach(start => this._replaceSelector(stylesheet.filePath, start, data));
50 });
51 }
52 _visitStringLiteralLike(node) {
53 if (node.parent && node.parent.kind !== ts.SyntaxKind.CallExpression) {
54 return;
55 }
56 const textContent = node.getText();
57 const filePath = this.fileSystem.resolve(node.getSourceFile().fileName);
58 this.data.forEach(data => {
59 if (data.replaceIn && !data.replaceIn.tsStringLiterals) {
60 return;
61 }
62 literal_1.findAllSubstringIndices(textContent, data.replace)
63 .map(offset => node.getStart() + offset)
64 .forEach(start => this._replaceSelector(filePath, start, data));
65 });
66 }
67 _replaceSelector(filePath, start, data) {
68 this.fileSystem.edit(filePath)
69 .remove(start, data.replace.length)
70 .insertRight(start, data.replaceWith);
71 }
72}
73exports.CssSelectorsMigration = CssSelectorsMigration;
74//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3NzLXNlbGVjdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvc2NoZW1hdGljcy9uZy11cGRhdGUvbWlncmF0aW9ucy9jc3Mtc2VsZWN0b3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7OztBQUVILGlDQUFpQztBQUdqQywyREFBc0Q7QUFFdEQsbURBQThEO0FBQzlELGtEQUFtRTtBQUVuRTs7O0dBR0c7QUFDSCxNQUFhLHFCQUFzQixTQUFRLHFCQUFzQjtJQUFqRTs7UUFDRSxpRUFBaUU7UUFDakUsU0FBSSxHQUE2QixvQ0FBcUIsQ0FBQyxJQUFJLEVBQUUsY0FBYyxDQUFDLENBQUM7UUFFN0UsMkRBQTJEO1FBQzNELFlBQU8sR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sS0FBSyxDQUFDLENBQUM7SUF3RG5DLENBQUM7SUF0RFUsU0FBUyxDQUFDLElBQWE7UUFDOUIsSUFBSSxFQUFFLENBQUMsbUJBQW1CLENBQUMsSUFBSSxDQUFDLEVBQUU7WUFDaEMsSUFBSSxDQUFDLHVCQUF1QixDQUFDLElBQUksQ0FBQyxDQUFDO1NBQ3BDO0lBQ0gsQ0FBQztJQUVRLGFBQWEsQ0FBQyxRQUEwQjtRQUMvQyxJQU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leHQoKTtcbiAgICBjb25zdCBmaWxlUGF0aCA9IHRoaXMuZmlsZVN5c3RlbS5yZXNvbHZlKG5vZGUuZ2V0U291cmNlRmlsZSgpLmZpbGVOYW1lKTtcblxuICAgIHRoaXMuZGF0YS5mb3JFYWNoKGRhdGEgPT4ge1xuICAgICAgaWYgKGRhdGEucmVwbGFjZUluICYmICFkYXRhLnJlcGxhY2VJbi50c1N0cmluZ0xpdGVyYWxzKSB7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cblxuICAgICAgZmluZEFsbFN1YnN0cmluZ0luZGljZXModGV4dENvbnRlbnQsIGRhdGEucmVwbGFjZSlcbiAgICAgICAgICAubWFwKG9mZnNldCA9PiBub2RlLmdldFN0YXJ0KCkgKyBvZmZzZXQpXG4gICAgICAgICAgLmZvckVhY2goc3RhcnQgPT4gdGhpcy5fcmVwbGFjZVNlbGVjdG9yKGZpbGVQYXRoLCBzdGFydCwgZGF0YSkpO1xuICAgIH0pO1xuICB9XG5cbiAgcHJpdmF0ZSBfcmVwbGFjZVNlbGVjdG9yKGZpbGVQYXRoOiBXb3Jrc3BhY2VQYXRoLCBzdGFydDogbnVtYmVyLCBkYXRhOiBDc3NTZWxlY3RvclVwZ3JhZGVEYXRhKSB7XG4gICAgdGhpcy5maWxlU3lzdGVtLmVkaXQoZmlsZVBhdGgpXG4gICAgICAucmVtb3ZlKHN0YXJ0LCBkYXRhLnJlcGxhY2UubGVuZ3RoKVxuICAgICAgLmluc2VydFJpZ2h0KHN0YXJ0LCBkYXRhLnJlcGxhY2VXaXRoKTtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.