output-names.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.OutputNamesMigration = void 0;
  11. const migration_1 = require("../../update-tool/migration");
  12. const angular_1 = require("../html-parsing/angular");
  13. const upgrade_data_1 = require("../upgrade-data");
  14. /**
  15. * Migration that walks through every inline or external HTML template and switches
  16. * changed output binding names to the proper new output name.
  17. */
  18. class OutputNamesMigration extends migration_1.Migration {
  19. constructor() {
  20. super(...arguments);
  21. /** Change data that upgrades to the specified target version. */
  22. this.data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'outputNames');
  23. // Only enable the migration rule if there is upgrade data.
  24. this.enabled = this.data.length !== 0;
  25. }
  26. visitTemplate(template) {
  27. this.data.forEach(name => {
  28. const limitedTo = name.limitedTo;
  29. const relativeOffsets = [];
  30. if (limitedTo.attributes) {
  31. relativeOffsets.push(...(0, angular_1.findOutputsOnElementWithAttr)(template.content, name.replace, limitedTo.attributes));
  32. }
  33. if (limitedTo.elements) {
  34. relativeOffsets.push(...(0, angular_1.findOutputsOnElementWithTag)(template.content, name.replace, limitedTo.elements));
  35. }
  36. relativeOffsets
  37. .map(offset => template.start + offset)
  38. .forEach(start => this._replaceOutputName(template.filePath, start, name.replace.length, name.replaceWith));
  39. });
  40. }
  41. _replaceOutputName(filePath, start, width, newName) {
  42. this.fileSystem.edit(filePath).remove(start, width).insertRight(start, newName);
  43. }
  44. }
  45. exports.OutputNamesMigration = OutputNamesMigration;
  46. //# sourceMappingURL=output-names.js.map