"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.InputNamesMigration = void 0; const angular_1 = require("../html-parsing/angular"); 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 template or stylesheet and replaces outdated input * names to the new input name. Selectors in stylesheets could also target input * bindings declared as static attribute. See for example: * * e.g. `` becomes `my-component[color]` */ class InputNamesMigration extends migration_1.Migration { /** Change data that upgrades to the specified target version. */ data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'inputNames'); // Only enable the migration rule if there is upgrade data. enabled = this.data.length !== 0; visitStylesheet(stylesheet) { this.data.forEach(name => { const currentSelector = `[${name.replace}]`; const updatedSelector = `[${name.replaceWith}]`; (0, literal_1.findAllSubstringIndices)(stylesheet.content, currentSelector) .map(offset => stylesheet.start + offset) .forEach(start => this._replaceInputName(stylesheet.filePath, start, currentSelector.length, updatedSelector)); }); } visitTemplate(template) { this.data.forEach(name => { const limitedTo = name.limitedTo; const relativeOffsets = []; if (limitedTo.attributes) { relativeOffsets.push(...(0, angular_1.findInputsOnElementWithAttr)(template.content, name.replace, limitedTo.attributes)); } if (limitedTo.elements) { relativeOffsets.push(...(0, angular_1.findInputsOnElementWithTag)(template.content, name.replace, limitedTo.elements)); } relativeOffsets .map(offset => template.start + offset) .forEach(start => this._replaceInputName(template.filePath, start, name.replace.length, name.replaceWith)); }); } _replaceInputName(filePath, start, width, newName) { this.fileSystem.edit(filePath).remove(start, width).insertRight(start, newName); } } exports.InputNamesMigration = InputNamesMigration; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQtbmFtZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3NjaGVtYXRpY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