@parcel/graph 2.7.1-nightly.2802 → 2.7.1-nightly.2808
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Graph.js +13 -5
- package/package.json +3 -3
- package/src/Graph.js +20 -5
- package/test/Graph.test.js +10 -0
package/lib/Graph.js
CHANGED
@@ -125,7 +125,7 @@ class Graph {
|
|
125
125
|
type,
|
126
126
|
from
|
127
127
|
} of this.adjacencyList.getInboundEdgesByType(nodeId)) {
|
128
|
-
this.
|
128
|
+
this._removeEdge(from, nodeId, type, // Do not allow orphans to be removed as this node could be one
|
129
129
|
// and is already being removed.
|
130
130
|
false);
|
131
131
|
}
|
@@ -134,7 +134,7 @@ class Graph {
|
|
134
134
|
type,
|
135
135
|
to
|
136
136
|
} of this.adjacencyList.getOutboundEdgesByType(nodeId)) {
|
137
|
-
this.
|
137
|
+
this._removeEdge(nodeId, to, type);
|
138
138
|
}
|
139
139
|
|
140
140
|
let wasRemoved = this.nodes.delete(nodeId);
|
@@ -147,12 +147,20 @@ class Graph {
|
|
147
147
|
}
|
148
148
|
|
149
149
|
for (let to of this.getNodeIdsConnectedFrom(nodeId, type)) {
|
150
|
-
this.
|
150
|
+
this._removeEdge(nodeId, to, type);
|
151
151
|
}
|
152
|
+
}
|
153
|
+
|
154
|
+
removeEdge(from, to, type = 1, removeOrphans = true) {
|
155
|
+
if (!this.adjacencyList.hasEdge(from, to, type)) {
|
156
|
+
throw new Error(`Edge from ${(0, _types.fromNodeId)(from)} to ${(0, _types.fromNodeId)(to)} not found!`);
|
157
|
+
}
|
158
|
+
|
159
|
+
this._removeEdge(from, to, type, removeOrphans);
|
152
160
|
} // Removes edge and node the edge is to if the node is orphaned
|
153
161
|
|
154
162
|
|
155
|
-
|
163
|
+
_removeEdge(from, to, type = 1, removeOrphans = true) {
|
156
164
|
if (!this.adjacencyList.hasEdge(from, to, type)) {
|
157
165
|
return;
|
158
166
|
}
|
@@ -215,7 +223,7 @@ class Graph {
|
|
215
223
|
}
|
216
224
|
|
217
225
|
for (let child of childrenToRemove) {
|
218
|
-
this.
|
226
|
+
this._removeEdge(fromNodeId, child, type);
|
219
227
|
}
|
220
228
|
}
|
221
229
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/graph",
|
3
|
-
"version": "2.7.1-nightly.
|
3
|
+
"version": "2.7.1-nightly.2808+96d8f285b",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
@@ -20,8 +20,8 @@
|
|
20
20
|
"node": ">= 12.0.0"
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
|
-
"@parcel/utils": "2.0.0-nightly.
|
23
|
+
"@parcel/utils": "2.0.0-nightly.1185+96d8f285b",
|
24
24
|
"nullthrows": "^1.1.1"
|
25
25
|
},
|
26
|
-
"gitHead": "
|
26
|
+
"gitHead": "96d8f285ba530fab67662ceaf06684d8da3e242a"
|
27
27
|
}
|
package/src/Graph.js
CHANGED
@@ -142,7 +142,7 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
142
142
|
}
|
143
143
|
|
144
144
|
for (let {type, from} of this.adjacencyList.getInboundEdgesByType(nodeId)) {
|
145
|
-
this.
|
145
|
+
this._removeEdge(
|
146
146
|
from,
|
147
147
|
nodeId,
|
148
148
|
type,
|
@@ -153,7 +153,7 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
153
153
|
}
|
154
154
|
|
155
155
|
for (let {type, to} of this.adjacencyList.getOutboundEdgesByType(nodeId)) {
|
156
|
-
this.
|
156
|
+
this._removeEdge(nodeId, to, type);
|
157
157
|
}
|
158
158
|
|
159
159
|
let wasRemoved = this.nodes.delete(nodeId);
|
@@ -166,16 +166,31 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
166
166
|
}
|
167
167
|
|
168
168
|
for (let to of this.getNodeIdsConnectedFrom(nodeId, type)) {
|
169
|
-
this.
|
169
|
+
this._removeEdge(nodeId, to, type);
|
170
170
|
}
|
171
171
|
}
|
172
172
|
|
173
|
-
// Removes edge and node the edge is to if the node is orphaned
|
174
173
|
removeEdge(
|
175
174
|
from: NodeId,
|
176
175
|
to: NodeId,
|
177
176
|
type: TEdgeType | NullEdgeType = 1,
|
178
177
|
removeOrphans: boolean = true,
|
178
|
+
) {
|
179
|
+
if (!this.adjacencyList.hasEdge(from, to, type)) {
|
180
|
+
throw new Error(
|
181
|
+
`Edge from ${fromNodeId(from)} to ${fromNodeId(to)} not found!`,
|
182
|
+
);
|
183
|
+
}
|
184
|
+
|
185
|
+
this._removeEdge(from, to, type, removeOrphans);
|
186
|
+
}
|
187
|
+
|
188
|
+
// Removes edge and node the edge is to if the node is orphaned
|
189
|
+
_removeEdge(
|
190
|
+
from: NodeId,
|
191
|
+
to: NodeId,
|
192
|
+
type: TEdgeType | NullEdgeType = 1,
|
193
|
+
removeOrphans: boolean = true,
|
179
194
|
) {
|
180
195
|
if (!this.adjacencyList.hasEdge(from, to, type)) {
|
181
196
|
return;
|
@@ -249,7 +264,7 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
249
264
|
}
|
250
265
|
|
251
266
|
for (let child of childrenToRemove) {
|
252
|
-
this.
|
267
|
+
this._removeEdge(fromNodeId, child, type);
|
253
268
|
}
|
254
269
|
}
|
255
270
|
|
package/test/Graph.test.js
CHANGED
@@ -89,6 +89,16 @@ describe('Graph', () => {
|
|
89
89
|
assert(!graph.isOrphanedNode(nodeC));
|
90
90
|
});
|
91
91
|
|
92
|
+
it("removeEdge should throw if the edge doesn't exist", () => {
|
93
|
+
let graph = new Graph();
|
94
|
+
let nodeA = graph.addNode('a');
|
95
|
+
let nodeB = graph.addNode('b');
|
96
|
+
|
97
|
+
assert.throws(() => {
|
98
|
+
graph.removeEdge(nodeA, nodeB);
|
99
|
+
}, /Edge from 0 to 1 not found!/);
|
100
|
+
});
|
101
|
+
|
92
102
|
it('removeEdge should prune the graph at that edge', () => {
|
93
103
|
// a
|
94
104
|
// / \
|