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.io/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 = 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(...angular_1.findOutputsOnElementWithAttr(template.content, name.replace, limitedTo.attributes));
|
---|
32 | }
|
---|
33 | if (limitedTo.elements) {
|
---|
34 | relativeOffsets.push(...angular_1.findOutputsOnElementWithTag(template.content, name.replace, limitedTo.elements));
|
---|
35 | }
|
---|
36 | relativeOffsets.map(offset => template.start + offset)
|
---|
37 | .forEach(start => this._replaceOutputName(template.filePath, start, name.replace.length, name.replaceWith));
|
---|
38 | });
|
---|
39 | }
|
---|
40 | _replaceOutputName(filePath, start, width, newName) {
|
---|
41 | this.fileSystem.edit(filePath)
|
---|
42 | .remove(start, width)
|
---|
43 | .insertRight(start, newName);
|
---|
44 | }
|
---|
45 | }
|
---|
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