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.JsonWorkspaceMetadata = exports.JsonWorkspaceSymbol = void 0;
|
---|
11 | exports.JsonWorkspaceSymbol = Symbol.for('@angular/core:workspace-json');
|
---|
12 | class JsonWorkspaceMetadata {
|
---|
13 | constructor(filePath, ast, raw) {
|
---|
14 | this.filePath = filePath;
|
---|
15 | this.ast = ast;
|
---|
16 | this.raw = raw;
|
---|
17 | this.changes = [];
|
---|
18 | }
|
---|
19 | get hasChanges() {
|
---|
20 | return this.changes.length > 0;
|
---|
21 | }
|
---|
22 | get changeCount() {
|
---|
23 | return this.changes.length;
|
---|
24 | }
|
---|
25 | findChangesForPath(path) {
|
---|
26 | return this.changes.filter((c) => c.path === path);
|
---|
27 | }
|
---|
28 | addChange(op, path, node, value, type) {
|
---|
29 | // Remove redundant operations
|
---|
30 | if (op === 'remove' || op === 'replace') {
|
---|
31 | for (let i = this.changes.length - 1; i >= 0; --i) {
|
---|
32 | const currentPath = this.changes[i].path;
|
---|
33 | if (currentPath === path || currentPath.startsWith(path + '/')) {
|
---|
34 | if (op === 'replace' && currentPath === path && this.changes[i].op === 'add') {
|
---|
35 | op = 'add';
|
---|
36 | }
|
---|
37 | this.changes.splice(i, 1);
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | this.changes.push({ op, path, node, value, type: op === 'remove' || !type ? 'json' : type });
|
---|
42 | }
|
---|
43 | reset() {
|
---|
44 | this.changes.length = 0;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | exports.JsonWorkspaceMetadata = JsonWorkspaceMetadata;
|
---|