222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
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
module.exports = function stringifyValidator(validator, nodePrefix) {
  if (validator === undefined) {
    return "any";
  }
 
  if (validator.each) {
    return `Array<${stringifyValidator(validator.each, nodePrefix)}>`;
  }
 
  if (validator.chainOf) {
    return stringifyValidator(validator.chainOf[1], nodePrefix);
  }
 
  if (validator.oneOf) {
    return validator.oneOf.map(JSON.stringify).join(" | ");
  }
 
  if (validator.oneOfNodeTypes) {
    return validator.oneOfNodeTypes.map(_ => nodePrefix + _).join(" | ");
  }
 
  if (validator.oneOfNodeOrValueTypes) {
    return validator.oneOfNodeOrValueTypes
      .map(_ => {
        return isValueType(_) ? _ : nodePrefix + _;
      })
      .join(" | ");
  }
 
  if (validator.type) {
    return validator.type;
  }
 
  return ["any"];
};
 
/**
 * Heuristic to decide whether or not the given type is a value type (eg. "null")
 * or a Node type (eg. "Expression").
 */
function isValueType(type) {
  return type.charAt(0).toLowerCase() === type.charAt(0);
}