"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.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CssSelectorsMigration = void 0; const ts = require("typescript"); const migration_1 = require("../../update-tool/migration"); const literal_1 = require("../typescript/literal"); const upgrade_data_1 = require("../upgrade-data"); /** * Migration that walks through every string literal, template and stylesheet in * order to migrate outdated CSS selectors to the new selector. */ class CssSelectorsMigration extends migration_1.Migration { /** Change data that upgrades to the specified target version. */ data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'cssSelectors'); // Only enable the migration rule if there is upgrade data. enabled = this.data.length !== 0; visitNode(node) { if (ts.isStringLiteralLike(node)) { this._visitStringLiteralLike(node); } } visitTemplate(template) { this.data.forEach(data => { if (data.replaceIn && !data.replaceIn.html) { return; } (0, literal_1.findAllSubstringIndices)(template.content, data.replace) .map(offset => template.start + offset) .forEach(start => this._replaceSelector(template.filePath, start, data)); }); } visitStylesheet(stylesheet) { this.data.forEach(data => { if (data.replaceIn && !data.replaceIn.stylesheet) { return; } (0, literal_1.findAllSubstringIndices)(stylesheet.content, data.replace) .map(offset => stylesheet.start + offset) .forEach(start => this._replaceSelector(stylesheet.filePath, start, data)); }); } _visitStringLiteralLike(node) { if (node.parent && node.parent.kind !== ts.SyntaxKind.CallExpression) { return; } const textContent = node.getText(); const filePath = this.fileSystem.resolve(node.getSourceFile().fileName); this.data.forEach(data => { if (data.replaceIn && !data.replaceIn.tsStringLiterals) { return; } (0, literal_1.findAllSubstringIndices)(textContent, data.replace) .map(offset => node.getStart() + offset) .forEach(start => this._replaceSelector(filePath, start, data)); }); } _replaceSelector(filePath, start, data) { this.fileSystem .edit(filePath) .remove(start, data.replace.length) .insertRight(start, data.replaceWith); } } exports.CssSelectorsMigration = CssSelectorsMigration; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3NzLXNlbGVjdG9ycy5qcyIsInNvdXJjZV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