/
parameter.ts
58 lines (50 loc) · 1.55 KB
/
parameter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { SomeType } from "..";
import { ReflectionType } from "../types";
import { Reflection, TraverseCallback, TraverseProperty } from "./abstract";
import type { SignatureReflection } from "./signature";
import type { Serializer, JSONOutput, Deserializer } from "../../serialization";
/**
* @category Reflections
*/
export class ParameterReflection extends Reflection {
readonly variant = "param";
override parent?: SignatureReflection;
defaultValue?: string;
type?: SomeType;
override traverse(callback: TraverseCallback) {
if (this.type instanceof ReflectionType) {
if (
callback(
this.type.declaration,
TraverseProperty.TypeLiteral,
) === false
) {
return;
}
}
}
/**
* Return a string representation of this reflection.
*/
override toString() {
return (
super.toString() + (this.type ? ": " + this.type.toString() : "")
);
}
override toObject(serializer: Serializer): JSONOutput.ParameterReflection {
return {
...super.toObject(serializer),
variant: this.variant,
type: serializer.toObject(this.type),
defaultValue: this.defaultValue,
};
}
override fromObject(
de: Deserializer,
obj: JSONOutput.ParameterReflection,
): void {
super.fromObject(de, obj);
this.type = de.reviveType(obj.type);
this.defaultValue = obj.defaultValue;
}
}