@atlaspack/graph 3.4.1-canary.33 → 3.4.1-canary.331

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.
@@ -1,18 +1,16 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import {BitSet} from '../src/BitSet';
5
3
 
6
4
  function assertValues(set: BitSet, values: Array<number>) {
7
- let setValues = [];
8
- set.forEach((bit) => {
5
+ let setValues: Array<any> = [];
6
+ set.forEach((bit: any) => {
9
7
  setValues.push(bit);
10
8
  });
11
9
 
12
10
  for (let value of values) {
13
11
  assert(set.has(value), 'Set.has returned false');
14
12
  assert(
15
- setValues.some((v) => v === value),
13
+ setValues.some((v: any) => v === value),
16
14
  'Set values is missing value',
17
15
  );
18
16
  }
@@ -107,4 +105,46 @@ describe('BitSet', () => {
107
105
  assertValues(set2, [3, 5]);
108
106
  assertValues(set3, [1, 3, 5]);
109
107
  });
108
+
109
+ it('BitSet.intersect should create a new BitSet with the intersect', () => {
110
+ let set1 = new BitSet(5);
111
+ set1.add(1);
112
+ set1.add(3);
113
+
114
+ let set2 = new BitSet(5);
115
+ set2.add(3);
116
+ set2.add(5);
117
+
118
+ let set3 = BitSet.intersect(set1, set2);
119
+ assertValues(set1, [1, 3]);
120
+ assertValues(set2, [3, 5]);
121
+ assertValues(set3, [3]);
122
+ });
123
+
124
+ it('should identify equality with another BitSet', () => {
125
+ let set1 = new BitSet(5);
126
+ set1.add(1);
127
+ set1.add(3);
128
+
129
+ let set2 = new BitSet(5);
130
+ set2.add(3);
131
+ set2.add(5);
132
+
133
+ let set3 = set1.clone();
134
+
135
+ assert(set1.equals(set3));
136
+ assert(!set1.equals(set2));
137
+ });
138
+
139
+ it('should calculate size of BitSet', () => {
140
+ let set1 = new BitSet(5);
141
+ set1.add(1);
142
+ set1.add(3);
143
+
144
+ assert.equal(set1.size(), 2);
145
+
146
+ set1.add(3);
147
+ set1.add(4);
148
+ assert.equal(set1.size(), 3);
149
+ });
110
150
  });
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import ContentGraph from '../src/ContentGraph';
5
3
 
@@ -7,7 +5,7 @@ describe('ContentGraph', () => {
7
5
  it('should addNodeByContentKey if no node exists with the content key', () => {
8
6
  let graph = new ContentGraph();
9
7
 
10
- const node = {};
8
+ const node: Record<string, any> = {};
11
9
 
12
10
  const nodeId1 = graph.addNodeByContentKey('contentKey', node);
13
11
 
@@ -29,7 +27,7 @@ describe('ContentGraph', () => {
29
27
  it('should remove the content key from graph when node is removed', () => {
30
28
  let graph = new ContentGraph();
31
29
 
32
- const node1 = {};
30
+ const node1: Record<string, any> = {};
33
31
  const nodeId1 = graph.addNodeByContentKey('contentKey', node1);
34
32
 
35
33
  assert.equal(graph.getNode(nodeId1), node1);
@@ -1,11 +1,9 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import type {TraversalActions} from '@atlaspack/types-internal';
6
4
 
7
5
  import Graph from '../src/Graph';
8
- import {toNodeId, type NodeId} from '../src/types';
6
+ import {toNodeId, NodeId} from '../src/types';
9
7
 
10
8
  describe('Graph', () => {
11
9
  it('constructor should initialize an empty graph', () => {
@@ -16,7 +14,7 @@ describe('Graph', () => {
16
14
 
17
15
  it('addNode should add a node to the graph', () => {
18
16
  let graph = new Graph();
19
- let node = {};
17
+ let node: Record<string, any> = {};
20
18
  let id = graph.addNode(node);
21
19
  assert.equal(graph.getNode(id), node);
22
20
  });
@@ -340,9 +338,9 @@ describe('Graph', () => {
340
338
 
341
339
  graph.setRootNodeId(nodeA);
342
340
 
343
- let visited = [];
341
+ let visited: Array<any> = [];
344
342
  graph.traverse(
345
- (nodeId) => {
343
+ (nodeId: any) => {
346
344
  visited.push(nodeId);
347
345
  },
348
346
  null, // use root as startNode
@@ -413,7 +411,7 @@ describe('Graph', () => {
413
411
  graph.addEdge(1, 3);
414
412
  graph.addEdge(2, 3);
415
413
 
416
- const order = [];
414
+ const order: Array<any> = [];
417
415
  const visit = (node: NodeId) => {
418
416
  order.push(node);
419
417
  };
@@ -440,10 +438,10 @@ describe('Graph', () => {
440
438
  graph.addEdge(1, 2);
441
439
  graph.addEdge(0, 3);
442
440
 
443
- const order = [];
441
+ const order: Array<any> = [];
444
442
  const visit = (
445
443
  node: NodeId,
446
- context: mixed | null,
444
+ context: unknown | null,
447
445
  actions: TraversalActions,
448
446
  ) => {
449
447
  if (node === 1) actions.skipChildren();
@@ -474,10 +472,10 @@ describe('Graph', () => {
474
472
  graph.addEdge(0, 2);
475
473
  graph.addEdge(2, 3);
476
474
 
477
- const order = [];
475
+ const order: Array<any> = [];
478
476
  const visit = (
479
477
  node: NodeId,
480
- context: mixed | null,
478
+ context: unknown | null,
481
479
  actions: TraversalActions,
482
480
  ) => {
483
481
  order.push(node);
@@ -515,8 +513,8 @@ describe('Graph', () => {
515
513
  graph.addEdge(0, 2);
516
514
  graph.addEdge(2, 3);
517
515
 
518
- const contexts = [];
519
- const visit = (node: NodeId, context: mixed | null) => {
516
+ const contexts: Array<any> = [];
517
+ const visit = (node: NodeId, context: unknown | null) => {
520
518
  contexts.push([node, context]);
521
519
  return `node-${node}-created-context`;
522
520
  };
@@ -528,12 +526,17 @@ describe('Graph', () => {
528
526
  getChildren,
529
527
  });
530
528
 
531
- assert.deepEqual(contexts, [
532
- [0, undefined],
533
- [1, 'node-0-created-context'],
534
- [2, 'node-1-created-context'],
535
- [3, 'node-2-created-context'],
536
- ]);
529
+ assert.deepEqual(
530
+ contexts.map((values: any) =>
531
+ values.map((v: any) => (v != null ? v : undefined)),
532
+ ),
533
+ [
534
+ [0, undefined],
535
+ [1, 'node-0-created-context'],
536
+ [2, 'node-1-created-context'],
537
+ [3, 'node-2-created-context'],
538
+ ],
539
+ );
537
540
  assert.equal(result, undefined);
538
541
  });
539
542
  });
@@ -552,12 +555,12 @@ describe('Graph', () => {
552
555
  graph.addEdge(1, 3);
553
556
  graph.addEdge(0, 2);
554
557
 
555
- const contexts = [];
556
- const visit = (node: NodeId, context: mixed | null) => {
558
+ const contexts: Array<any> = [];
559
+ const visit = (node: NodeId, context: unknown | null) => {
557
560
  contexts.push([node, context]);
558
561
  return `node-${node}-created-context`;
559
562
  };
560
- const visitExit = (node: NodeId, context: mixed | null) => {
563
+ const visitExit = (node: NodeId, context: unknown | null) => {
561
564
  contexts.push(['exit', node, context]);
562
565
  return `node-exit-${node}-created-context`;
563
566
  };
@@ -572,16 +575,21 @@ describe('Graph', () => {
572
575
  getChildren,
573
576
  });
574
577
 
575
- assert.deepEqual(contexts, [
576
- [0, undefined],
577
- [1, 'node-0-created-context'],
578
- [2, 'node-1-created-context'],
579
- ['exit', 2, 'node-2-created-context'],
580
- [3, 'node-1-created-context'],
581
- ['exit', 3, 'node-3-created-context'],
582
- ['exit', 1, 'node-1-created-context'],
583
- ['exit', 0, 'node-0-created-context'],
584
- ]);
578
+ assert.deepEqual(
579
+ contexts.map((values: any) =>
580
+ values.map((v: any) => (v != null ? v : undefined)),
581
+ ),
582
+ [
583
+ [0, undefined],
584
+ [1, 'node-0-created-context'],
585
+ [2, 'node-1-created-context'],
586
+ ['exit', 2, 'node-2-created-context'],
587
+ [3, 'node-1-created-context'],
588
+ ['exit', 3, 'node-3-created-context'],
589
+ ['exit', 1, 'node-1-created-context'],
590
+ ['exit', 0, 'node-0-created-context'],
591
+ ],
592
+ );
585
593
  assert.equal(result, undefined);
586
594
  });
587
595
  });
@@ -602,8 +610,8 @@ describe('Graph', () => {
602
610
  graph.addEdge(a, c);
603
611
  graph.addEdge(c, d);
604
612
 
605
- const order = [];
606
- graph.forEachNodeIdConnectedTo(d, (node) => {
613
+ const order: Array<any> = [];
614
+ graph.forEachNodeIdConnectedTo(d, (node: any) => {
607
615
  order.push(node);
608
616
  });
609
617
 
@@ -626,8 +634,8 @@ describe('Graph', () => {
626
634
  graph.addEdge(a, c);
627
635
  graph.addEdge(c, d);
628
636
 
629
- const order = [];
630
- graph.forEachNodeIdConnectedFrom(a, (node) => {
637
+ const order: Array<any> = [];
638
+ graph.forEachNodeIdConnectedFrom(a, (node: any) => {
631
639
  order.push(node);
632
640
  });
633
641
 
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../dev/babel-register/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../feature-flags/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../types-internal/tsconfig.json"
16
+ }
17
+ ]
18
+ }