1
1
import type { Dictionary } from '@stoplight/types' ;
2
2
3
- import { isRegularNode } from '../../guards' ;
3
+ import { isReferenceNode , isRegularNode } from '../../guards' ;
4
4
import type { SchemaFragment } from '../../types' ;
5
5
import { isNonNullable } from '../../utils' ;
6
6
import { BaseNode } from '../BaseNode' ;
7
+ import { BooleanishNode } from '../BooleanishNode' ;
7
8
import type { ReferenceNode } from '../ReferenceNode' ;
8
9
import type { RegularNode } from '../RegularNode' ;
9
10
import type { SchemaAnnotations , SchemaCombinerName , SchemaNodeKind } from '../types' ;
10
11
import { MirroredReferenceNode } from './MirroredReferenceNode' ;
11
12
12
13
export class MirroredRegularNode extends BaseNode implements RegularNode {
14
+ public readonly fragment : SchemaFragment ;
13
15
public readonly $id ! : string | null ;
14
16
public readonly types ! : SchemaNodeKind [ ] | null ;
15
17
public readonly primaryType ! : SchemaNodeKind | null ;
@@ -28,10 +30,14 @@ export class MirroredRegularNode extends BaseNode implements RegularNode {
28
30
public readonly simple ! : boolean ;
29
31
public readonly unknown ! : boolean ;
30
32
31
- private readonly cache : WeakMap < RegularNode | ReferenceNode , MirroredRegularNode | MirroredReferenceNode > ;
33
+ private readonly cache : WeakMap <
34
+ RegularNode | BooleanishNode | ReferenceNode ,
35
+ MirroredRegularNode | BooleanishNode | MirroredReferenceNode
36
+ > ;
32
37
33
38
constructor ( public readonly mirroredNode : RegularNode , context ?: { originalFragment ?: SchemaFragment } ) {
34
- super ( mirroredNode . fragment ) ;
39
+ super ( ) ;
40
+ this . fragment = mirroredNode . fragment ;
35
41
this . originalFragment = context ?. originalFragment ?? mirroredNode . originalFragment ;
36
42
37
43
this . cache = new WeakMap ( ) ;
@@ -59,9 +65,9 @@ export class MirroredRegularNode extends BaseNode implements RegularNode {
59
65
60
66
private readonly _this : MirroredRegularNode ;
61
67
62
- private _children ?: ( MirroredRegularNode | MirroredReferenceNode ) [ ] ;
68
+ private _children ?: ( MirroredRegularNode | BooleanishNode | MirroredReferenceNode ) [ ] ;
63
69
64
- public get children ( ) : ( MirroredRegularNode | MirroredReferenceNode ) [ ] | null | undefined {
70
+ public get children ( ) : ( MirroredRegularNode | BooleanishNode | MirroredReferenceNode ) [ ] | null | undefined {
65
71
const referencedChildren = this . mirroredNode . children ;
66
72
67
73
if ( ! isNonNullable ( referencedChildren ) ) {
@@ -74,7 +80,7 @@ export class MirroredRegularNode extends BaseNode implements RegularNode {
74
80
this . _children . length = 0 ;
75
81
}
76
82
77
- const children : ( MirroredRegularNode | MirroredReferenceNode ) [ ] = this . _children ;
83
+ const children : ( MirroredRegularNode | BooleanishNode | MirroredReferenceNode ) [ ] = this . _children ;
78
84
for ( const child of referencedChildren ) {
79
85
// this is to avoid pointing at nested mirroring
80
86
const cached = this . cache . get ( child ) ;
@@ -84,7 +90,11 @@ export class MirroredRegularNode extends BaseNode implements RegularNode {
84
90
continue ;
85
91
}
86
92
87
- const mirroredChild = isRegularNode ( child ) ? new MirroredRegularNode ( child ) : new MirroredReferenceNode ( child ) ;
93
+ const mirroredChild = isRegularNode ( child )
94
+ ? new MirroredRegularNode ( child )
95
+ : isReferenceNode ( child )
96
+ ? new MirroredReferenceNode ( child )
97
+ : new BooleanishNode ( child . fragment ) ;
88
98
89
99
mirroredChild . parent = this . _this ;
90
100
mirroredChild . subpath = child . subpath ;
0 commit comments