diff --git a/packages/babel-types/scripts/generators/docs.js b/packages/babel-types/scripts/generators/docs.js index 18e536dd2f..07a44bbd37 100644 --- a/packages/babel-types/scripts/generators/docs.js +++ b/packages/babel-types/scripts/generators/docs.js @@ -5,7 +5,12 @@ import toFunctionName from "../utils/toFunctionName.js"; import t from "../../lib/index.js"; const readme = [ - `# @babel/types + `--- +id: babel-types +title: @babel/types +--- + > This module contains methods for building ASTs manually and for checking the types of AST nodes. @@ -34,36 +39,39 @@ const customTypes = { ObjectProperty: { key: "if computed then `Expression` else `Identifier | Literal`", }, + ClassPrivateMethod: { + computed: "'false'", + }, + ClassPrivateProperty: { + computed: "'false'", + }, }; -Object.keys(t.BUILDER_KEYS) - .sort() - .forEach(function (key) { - readme.push("### " + key[0].toLowerCase() + key.substr(1)); - readme.push("```javascript"); - readme.push( - "t." + toFunctionName(key) + "(" + t.BUILDER_KEYS[key].join(", ") + ")" - ); - readme.push("```"); +const APIHistory = { + ClassProperty: [["v7.6.0", "Supports `static`"]], +}; +function formatHistory(historyItems) { + const lines = historyItems.map( + item => "| `" + item[0] + "` | " + item[1] + " |" + ); + return [ + "
", + " History", + "| Version | Changes |", + "| --- | --- |", + ...lines, + "
", + ]; +} +function printAPIHistory(key, readme) { + if (APIHistory[key]) { readme.push(""); - readme.push( - "See also `t.is" + - key + - "(node, opts)` and `t.assert" + - key + - "(node, opts)`." - ); + readme.push(...formatHistory(APIHistory[key])); + } +} +function printNodeFields(key, readme) { + if (Object.keys(t.NODE_FIELDS[key]).length > 0) { readme.push(""); - if (t.ALIAS_KEYS[key] && t.ALIAS_KEYS[key].length) { - readme.push( - "Aliases: " + - t.ALIAS_KEYS[key] - .map(function (key) { - return "`" + key + "`"; - }) - .join(", ") - ); - readme.push(""); - } + readme.push("AST Node `" + key + "` shape:"); Object.keys(t.NODE_FIELDS[key]) .sort(function (fieldA, fieldB) { const indexA = t.BUILDER_KEYS[key].indexOf(fieldA); @@ -104,8 +112,47 @@ Object.keys(t.BUILDER_KEYS) } else { fieldDescription.push(" (required)"); } - readme.push(" - " + fieldDescription.join("")); + readme.push("- " + fieldDescription.join("")); }); + } +} + +function printAliasKeys(key, readme) { + if (t.ALIAS_KEYS[key] && t.ALIAS_KEYS[key].length) { + readme.push(""); + readme.push( + "Aliases: " + + t.ALIAS_KEYS[key] + .map(function (key) { + return "`" + key + "`"; + }) + .join(", ") + ); + } +} + +Object.keys(t.BUILDER_KEYS) + .sort() + .forEach(function (key) { + readme.push("### " + toFunctionName(key)); + readme.push(""); + readme.push("```javascript"); + readme.push( + "t." + toFunctionName(key) + "(" + t.BUILDER_KEYS[key].join(", ") + ");" + ); + readme.push("```"); + printAPIHistory(key, readme); + readme.push(""); + readme.push( + "See also `t.is" + + key + + "(node, opts)` and `t.assert" + + key + + "(node, opts)`." + ); + + printNodeFields(key, readme); + printAliasKeys(key, readme); readme.push(""); readme.push("---");