@@ -20,29 +20,17 @@ export interface ScalarAnnotation {
20
20
readonly text ?: string ;
21
21
}
22
22
23
- export interface FunctionAnnotation {
24
- readonly type : 'function' ;
25
- readonly text ?: string ;
26
- }
27
-
28
- export interface CircularRefAnnotation {
29
- readonly type : 'circular-ref' ;
30
- readonly text ?: string ;
31
- }
32
-
33
- export interface UnknownAnnotation {
34
- readonly type : 'unknown' ;
35
- readonly value : unknown ;
23
+ export interface OpaqueAnnotation {
24
+ readonly type : 'opaque' ;
25
+ readonly value : string ; // e.g. '???' | '<function>' | '<circular ref>'
36
26
readonly text ?: string ;
37
27
}
38
28
39
29
export type Annotation =
40
30
| ObjectAnnotation
41
31
| ArrayAnnotation
42
32
| ScalarAnnotation
43
- | FunctionAnnotation
44
- | CircularRefAnnotation
45
- | UnknownAnnotation ;
33
+ | OpaqueAnnotation ;
46
34
47
35
/** @internal */
48
36
function brand < A extends Annotation > ( ann : A ) : A {
@@ -67,25 +55,15 @@ export function makeArrayAnn(
67
55
}
68
56
69
57
/** @internal */
70
- export function makeFunctionAnn ( text ?: string ) : FunctionAnnotation {
71
- return brand ( { type : 'function' , text } ) ;
72
- }
73
-
74
- /** @internal */
75
- export function makeUnknownAnn ( value : unknown , text ?: string ) : UnknownAnnotation {
76
- return brand ( { type : 'unknown' , value, text } ) ;
58
+ export function makeOpaqueAnn ( value : string , text ?: string ) : OpaqueAnnotation {
59
+ return brand ( { type : 'opaque' , value, text } ) ;
77
60
}
78
61
79
62
/** @internal */
80
63
export function makeScalarAnn ( value : unknown , text ?: string ) : ScalarAnnotation {
81
64
return brand ( { type : 'scalar' , value, text } ) ;
82
65
}
83
66
84
- /** @internal */
85
- export function makeCircularRefAnn ( text ?: string ) : CircularRefAnnotation {
86
- return brand ( { type : 'circular-ref' , text } ) ;
87
- }
88
-
89
67
/**
90
68
* @internal
91
69
* Given an existing Annotation, set the annotation's text to a new value.
@@ -122,7 +100,7 @@ function annotateArray(
122
100
arr : readonly unknown [ ] ,
123
101
text : string | undefined ,
124
102
seen : RefSet ,
125
- ) : ArrayAnnotation | CircularRefAnnotation {
103
+ ) : ArrayAnnotation | OpaqueAnnotation {
126
104
seen . add ( arr ) ;
127
105
128
106
// Cannot use .map() here because it won't work correctly if `arr` is
@@ -171,7 +149,7 @@ function annotate(value: unknown, text: string | undefined, seen: RefSet): Annot
171
149
if ( Array . isArray ( value ) ) {
172
150
// "Circular references" can only exist in objects or arrays
173
151
if ( seen . has ( value ) ) {
174
- return makeCircularRefAnn ( text ) ;
152
+ return makeOpaqueAnn ( '<circular ref>' , text ) ;
175
153
} else {
176
154
return annotateArray ( value , text , seen ) ;
177
155
}
@@ -180,17 +158,17 @@ function annotate(value: unknown, text: string | undefined, seen: RefSet): Annot
180
158
if ( isPojo ( value ) ) {
181
159
// "Circular references" can only exist in objects or arrays
182
160
if ( seen . has ( value ) ) {
183
- return makeCircularRefAnn ( text ) ;
161
+ return makeOpaqueAnn ( '<circular ref>' , text ) ;
184
162
} else {
185
163
return annotateObject ( value , text , seen ) ;
186
164
}
187
165
}
188
166
189
167
if ( typeof value === 'function' ) {
190
- return makeFunctionAnn ( text ) ;
168
+ return makeOpaqueAnn ( '<function>' , text ) ;
191
169
}
192
170
193
- return makeUnknownAnn ( value , text ) ;
171
+ return makeOpaqueAnn ( '???' , text ) ;
194
172
}
195
173
196
174
function public_annotate ( value : unknown , text ?: string ) : Annotation {
0 commit comments