Babel types docs (#3549)
* Update babel-types documentation Mostly just re-run generate-babel-types-docs but also update for some more validator types. * Rebuild docs as part of "build-dost" * Include fields not in BUILDER_KEYS in babel-types docs These fields don’t have a shorthand for you to pass them to the helper method, but they are still useful to know about. * Fields not included in BUILDER_KEYS cannot be "required" We don’t ever type-check fields not in BUILDER_KEYS so they are never required.
This commit is contained in:
committed by
Henry Zhu
parent
39f645768c
commit
3bc3c9a3ed
@@ -37,6 +37,10 @@ function getType(validator) {
|
||||
return validator.type;
|
||||
} else if (validator.oneOfNodeTypes) {
|
||||
return validator.oneOfNodeTypes.join(' | ');
|
||||
} else if (validator.oneOfNodeOrValueTypes) {
|
||||
return validator.oneOfNodeOrValueTypes.join(' | ');
|
||||
} else if (validator.oneOf) {
|
||||
return validator.oneOf.map(val => util.inspect(val)).join(' | ');
|
||||
} else if (validator.chainOf) {
|
||||
if (
|
||||
validator.chainOf.length === 2 &&
|
||||
@@ -56,6 +60,7 @@ function getType(validator) {
|
||||
}
|
||||
}
|
||||
var err = new Error('Unrecognised validator type');
|
||||
err.code = 'UNEXPECTED_VALIDATOR_TYPE';
|
||||
err.validator = validator;
|
||||
throw err;
|
||||
}
|
||||
@@ -70,7 +75,15 @@ Object.keys(types.BUILDER_KEYS).sort().forEach(function (key) {
|
||||
}).join(', '));
|
||||
readme.push('');
|
||||
}
|
||||
types.BUILDER_KEYS[key].forEach(function (field) {
|
||||
Object.keys(types.NODE_FIELDS[key]).sort(function (fieldA, fieldB) {
|
||||
var indexA = types.BUILDER_KEYS[key].indexOf(fieldA);
|
||||
var indexB = types.BUILDER_KEYS[key].indexOf(fieldB);
|
||||
if (indexA === indexB) return fieldA < fieldB ? -1 : 1;
|
||||
if (indexA === -1) return 1;
|
||||
if (indexB === -1) return -1;
|
||||
return indexA - indexB;
|
||||
})
|
||||
.forEach(function (field) {
|
||||
var defaultValue = types.NODE_FIELDS[key][field].default;
|
||||
var fieldDescription = ['`' + field + '`'];
|
||||
var validator = types.NODE_FIELDS[key][field].validate;
|
||||
@@ -80,9 +93,9 @@ Object.keys(types.BUILDER_KEYS).sort().forEach(function (key) {
|
||||
try {
|
||||
fieldDescription.push(': `' + getType(validator) + '`');
|
||||
} catch (ex) {
|
||||
console.log(key);
|
||||
console.log(field);
|
||||
console.dir(validator, {depth: 10, colors: true});
|
||||
if (ex.code !== UNEXPECTED_VALIDATOR_TYPE);
|
||||
console.log('Unrecognised validator type for ' + key + '.' + field);
|
||||
console.dir(ex.validator, {depth: 10, colors: true});
|
||||
}
|
||||
}
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user