Run prettier
This commit is contained in:
@@ -6,7 +6,13 @@ const fs = require("fs");
|
||||
|
||||
const types = require("../packages/babel-types");
|
||||
|
||||
const readmePath = path.join(__dirname, "..", "packages", "babel-types", "README.md");
|
||||
const readmePath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"packages",
|
||||
"babel-types",
|
||||
"README.md"
|
||||
);
|
||||
const readmeSrc = fs.readFileSync(readmePath, "utf8");
|
||||
const readme = [
|
||||
readmeSrc.split("<!-- begin generated section -->")[0].trim(),
|
||||
@@ -40,7 +46,7 @@ function getType(validator) {
|
||||
} else if (validator.oneOfNodeOrValueTypes) {
|
||||
return validator.oneOfNodeOrValueTypes.join(" | ");
|
||||
} else if (validator.oneOf) {
|
||||
return validator.oneOf.map((val) => util.inspect(val)).join(" | ");
|
||||
return validator.oneOf.map(val => util.inspect(val)).join(" | ");
|
||||
} else if (validator.chainOf) {
|
||||
if (
|
||||
validator.chainOf.length === 2 &&
|
||||
@@ -54,9 +60,11 @@ function getType(validator) {
|
||||
validator.chainOf[0].type === "string" &&
|
||||
validator.chainOf[1].oneOf
|
||||
) {
|
||||
return validator.chainOf[1].oneOf.map(function (val) {
|
||||
return JSON.stringify(val);
|
||||
}).join(" | ");
|
||||
return validator.chainOf[1].oneOf
|
||||
.map(function(val) {
|
||||
return JSON.stringify(val);
|
||||
})
|
||||
.join(" | ");
|
||||
}
|
||||
}
|
||||
const err = new Error("Unrecognised validator type");
|
||||
@@ -64,54 +72,72 @@ function getType(validator) {
|
||||
err.validator = validator;
|
||||
throw err;
|
||||
}
|
||||
Object.keys(types.BUILDER_KEYS).sort().forEach(function (key) {
|
||||
Object.keys(types.BUILDER_KEYS).sort().forEach(function(key) {
|
||||
readme.push("### " + key[0].toLowerCase() + key.substr(1));
|
||||
readme.push("```javascript");
|
||||
readme.push("t." + key[0].toLowerCase() + key.substr(1) + "(" + types.BUILDER_KEYS[key].join(", ") + ")");
|
||||
readme.push(
|
||||
"t." +
|
||||
key[0].toLowerCase() +
|
||||
key.substr(1) +
|
||||
"(" +
|
||||
types.BUILDER_KEYS[key].join(", ") +
|
||||
")"
|
||||
);
|
||||
readme.push("```");
|
||||
readme.push("");
|
||||
readme.push("See also `t.is" + key + "(node, opts)` and `t.assert" + key + "(node, opts)`.");
|
||||
readme.push(
|
||||
"See also `t.is" +
|
||||
key +
|
||||
"(node, opts)` and `t.assert" +
|
||||
key +
|
||||
"(node, opts)`."
|
||||
);
|
||||
readme.push("");
|
||||
if (types.ALIAS_KEYS[key] && types.ALIAS_KEYS[key].length) {
|
||||
readme.push("Aliases: " + types.ALIAS_KEYS[key].map(function (key) {
|
||||
return "`" + key + "`";
|
||||
}).join(", "));
|
||||
readme.push(
|
||||
"Aliases: " +
|
||||
types.ALIAS_KEYS[key]
|
||||
.map(function(key) {
|
||||
return "`" + key + "`";
|
||||
})
|
||||
.join(", ")
|
||||
);
|
||||
readme.push("");
|
||||
}
|
||||
Object.keys(types.NODE_FIELDS[key]).sort(function (fieldA, fieldB) {
|
||||
const indexA = types.BUILDER_KEYS[key].indexOf(fieldA);
|
||||
const 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) {
|
||||
const defaultValue = types.NODE_FIELDS[key][field].default;
|
||||
const fieldDescription = ["`" + field + "`"];
|
||||
const validator = types.NODE_FIELDS[key][field].validate;
|
||||
if (customTypes[key] && customTypes[key][field]) {
|
||||
fieldDescription.push(customTypes[key][field]);
|
||||
} else if (validator) {
|
||||
try {
|
||||
fieldDescription.push(": `" + getType(validator) + "`");
|
||||
} catch (ex) {
|
||||
if (ex.code === "UNEXPECTED_VALIDATOR_TYPE") {
|
||||
console.log("Unrecognised validator type for " + key + "." + field);
|
||||
console.dir(ex.validator, { depth: 10, colors: true });
|
||||
Object.keys(types.NODE_FIELDS[key])
|
||||
.sort(function(fieldA, fieldB) {
|
||||
const indexA = types.BUILDER_KEYS[key].indexOf(fieldA);
|
||||
const 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) {
|
||||
const defaultValue = types.NODE_FIELDS[key][field].default;
|
||||
const fieldDescription = ["`" + field + "`"];
|
||||
const validator = types.NODE_FIELDS[key][field].validate;
|
||||
if (customTypes[key] && customTypes[key][field]) {
|
||||
fieldDescription.push(customTypes[key][field]);
|
||||
} else if (validator) {
|
||||
try {
|
||||
fieldDescription.push(": `" + getType(validator) + "`");
|
||||
} catch (ex) {
|
||||
if (ex.code === "UNEXPECTED_VALIDATOR_TYPE") {
|
||||
console.log("Unrecognised validator type for " + key + "." + field);
|
||||
console.dir(ex.validator, { depth: 10, colors: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
defaultValue !== null ||
|
||||
types.NODE_FIELDS[key][field].optional
|
||||
) {
|
||||
fieldDescription.push(" (default: `" + util.inspect(defaultValue) + "`)");
|
||||
} else {
|
||||
fieldDescription.push(" (required)");
|
||||
}
|
||||
readme.push(" - " + fieldDescription.join(""));
|
||||
});
|
||||
if (defaultValue !== null || types.NODE_FIELDS[key][field].optional) {
|
||||
fieldDescription.push(
|
||||
" (default: `" + util.inspect(defaultValue) + "`)"
|
||||
);
|
||||
} else {
|
||||
fieldDescription.push(" (required)");
|
||||
}
|
||||
readme.push(" - " + fieldDescription.join(""));
|
||||
});
|
||||
|
||||
readme.push("");
|
||||
readme.push("---");
|
||||
|
||||
@@ -51,7 +51,7 @@ const lines = [];
|
||||
for (const type in t.NODE_FIELDS) {
|
||||
const fields = t.NODE_FIELDS[type];
|
||||
|
||||
const struct = ["type: \"" + type + "\";"];
|
||||
const struct = ['type: "' + type + '";'];
|
||||
const args = [];
|
||||
|
||||
for (const fieldName in fields) {
|
||||
@@ -65,9 +65,11 @@ for (const type in t.NODE_FIELDS) {
|
||||
const validate = field.validate;
|
||||
if (validate) {
|
||||
if (validate.oneOf) {
|
||||
typeAnnotation = validate.oneOf.map(function (val) {
|
||||
return JSON.stringify(val);
|
||||
}).join(" | ");
|
||||
typeAnnotation = validate.oneOf
|
||||
.map(function(val) {
|
||||
return JSON.stringify(val);
|
||||
})
|
||||
.join(" | ");
|
||||
}
|
||||
|
||||
if (validate.type) {
|
||||
@@ -79,7 +81,9 @@ for (const type in t.NODE_FIELDS) {
|
||||
}
|
||||
|
||||
if (validate.oneOfNodeTypes) {
|
||||
const types = validate.oneOfNodeTypes.map((type) => `${NODE_PREFIX}${type}`);
|
||||
const types = validate.oneOfNodeTypes.map(
|
||||
type => `${NODE_PREFIX}${type}`
|
||||
);
|
||||
typeAnnotation = types.join(" | ");
|
||||
if (suffix === "?") typeAnnotation = "?" + typeAnnotation;
|
||||
}
|
||||
@@ -101,18 +105,24 @@ for (const type in t.NODE_FIELDS) {
|
||||
// Flow chokes on super() :/
|
||||
if (type !== "Super") {
|
||||
lines.push(
|
||||
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(", ")}): ${NODE_PREFIX}${type};`
|
||||
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(
|
||||
", "
|
||||
)}): ${NODE_PREFIX}${type};`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < t.TYPES.length; i++) {
|
||||
lines.push(`declare function is${t.TYPES[i]}(node: Object, opts?: Object): boolean;`);
|
||||
lines.push(
|
||||
`declare function is${t.TYPES[i]}(node: Object, opts?: Object): boolean;`
|
||||
);
|
||||
}
|
||||
|
||||
for (const type in t.FLIPPED_ALIAS_KEYS) {
|
||||
const types = t.FLIPPED_ALIAS_KEYS[type];
|
||||
code += `type ${NODE_PREFIX}${type} = ${types.map((type) => `${NODE_PREFIX}${type}`).join(" | ")};\n`;
|
||||
code += `type ${NODE_PREFIX}${type} = ${types
|
||||
.map(type => `${NODE_PREFIX}${type}`)
|
||||
.join(" | ")};\n`;
|
||||
}
|
||||
|
||||
code += `\ndeclare module "babel-types" {
|
||||
|
||||
Reference in New Issue
Block a user