output-names.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /**
  3. * Use of this source code is governed by an MIT-style license that can be
  4. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.OutputNamesMigration = void 0;
  8. const schematics_1 = require("@angular/cdk/schematics");
  9. const upgrade_data_1 = require("../upgrade-data");
  10. /**
  11. * Migration that walks through every inline or external HTML template and switches
  12. * changed output binding names to the proper new output name.
  13. */
  14. class OutputNamesMigration extends schematics_1.Migration {
  15. constructor() {
  16. super(...arguments);
  17. /** Change data that upgrades to the specified target version. */
  18. this.data = (0, upgrade_data_1.getVersionUpgradeData)(this, 'outputNames');
  19. // Only enable the migration rule if there is upgrade data.
  20. this.enabled = this.data.length !== 0;
  21. }
  22. visitTemplate(template) {
  23. this.data.forEach(name => {
  24. const limitedTo = name.limitedTo;
  25. const relativeOffsets = [];
  26. if (limitedTo.attributes) {
  27. relativeOffsets.push(...(0, schematics_1.findOutputsOnElementWithAttr)(template.content, name.replace, limitedTo.attributes));
  28. }
  29. if (limitedTo.elements) {
  30. relativeOffsets.push(...(0, schematics_1.findOutputsOnElementWithTag)(template.content, name.replace, limitedTo.elements));
  31. }
  32. relativeOffsets
  33. .map(offset => template.start + offset)
  34. .forEach(start => this._replaceOutputName(template.filePath, start, name.replace.length, name.replaceWith));
  35. });
  36. }
  37. _replaceOutputName(filePath, start, width, newName) {
  38. this.fileSystem.edit(filePath).remove(start, width).insertRight(start, newName);
  39. }
  40. }
  41. exports.OutputNamesMigration = OutputNamesMigration;
  42. //# sourceMappingURL=output-names.js.map