"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.AttributeSelectorsMigration = 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 switch deprecated attribute selectors to the updated selector. */ class AttributeSelectorsMigration extends migration_1.Migration { /** Required upgrade changes for specified target version. */ data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'attributeSelectors'); // 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(selector => { (0, literal_1.findAllSubstringIndices)(template.content, selector.replace) .map(offset => template.start + offset) .forEach(start => this._replaceSelector(template.filePath, start, selector)); }); } visitStylesheet(stylesheet) { this.data.forEach(selector => { const currentSelector = `[${selector.replace}]`; const updatedSelector = `[${selector.replaceWith}]`; (0, literal_1.findAllSubstringIndices)(stylesheet.content, currentSelector) .map(offset => stylesheet.start + offset) .forEach(start => this._replaceSelector(stylesheet.filePath, start, { replace: currentSelector, replaceWith: updatedSelector, })); }); } _visitStringLiteralLike(literal) { if (literal.parent && literal.parent.kind !== ts.SyntaxKind.CallExpression) { return; } const literalText = literal.getText(); const filePath = this.fileSystem.resolve(literal.getSourceFile().fileName); this.data.forEach(selector => { (0, literal_1.findAllSubstringIndices)(literalText, selector.replace) .map(offset => literal.getStart() + offset) .forEach(start => this._replaceSelector(filePath, start, selector)); }); } _replaceSelector(filePath, start, data) { this.fileSystem .edit(filePath) .remove(start, data.replace.length) .insertRight(start, data.replaceWith); } } exports.AttributeSelectorsMigration = AttributeSelectorsMigration; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0cmlidXRlLXNlbGVjdG9ycy5qcyIsIn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