Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

docs.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import util from "util";
  2. import stringifyValidator from "../utils/stringifyValidator.js";
  3. import toFunctionName from "../utils/toFunctionName.js";
  4. import t from "../../lib/index.js";
  5. const readme = [
  6. `---
  7. id: babel-types
  8. title: @babel/types
  9. ---
  10. <!-- Do not modify! This file is automatically generated by
  11. github.com/babel/babel/babel-types/scripts/generators/docs.js !-->
  12. > This module contains methods for building ASTs manually and for checking the types of AST nodes.
  13. ## Install
  14. \`\`\`sh
  15. npm install --save-dev @babel/types
  16. \`\`\`
  17. ## API`,
  18. ];
  19. const customTypes = {
  20. ClassMethod: {
  21. key: "if computed then `Expression` else `Identifier | Literal`",
  22. },
  23. Identifier: {
  24. name: "`string`",
  25. },
  26. MemberExpression: {
  27. property: "if computed then `Expression` else `Identifier`",
  28. },
  29. ObjectMethod: {
  30. key: "if computed then `Expression` else `Identifier | Literal`",
  31. },
  32. ObjectProperty: {
  33. key: "if computed then `Expression` else `Identifier | Literal`",
  34. },
  35. ClassPrivateMethod: {
  36. computed: "'false'",
  37. },
  38. ClassPrivateProperty: {
  39. computed: "'false'",
  40. },
  41. };
  42. const APIHistory = {
  43. ClassProperty: [["v7.6.0", "Supports `static`"]],
  44. };
  45. function formatHistory(historyItems) {
  46. const lines = historyItems.map(
  47. item => "| `" + item[0] + "` | " + item[1] + " |"
  48. );
  49. return [
  50. "<details>",
  51. " <summary>History</summary>",
  52. "| Version | Changes |",
  53. "| --- | --- |",
  54. ...lines,
  55. "</details>",
  56. ];
  57. }
  58. function printAPIHistory(key, readme) {
  59. if (APIHistory[key]) {
  60. readme.push("");
  61. readme.push(...formatHistory(APIHistory[key]));
  62. }
  63. }
  64. function printNodeFields(key, readme) {
  65. if (Object.keys(t.NODE_FIELDS[key]).length > 0) {
  66. readme.push("");
  67. readme.push("AST Node `" + key + "` shape:");
  68. Object.keys(t.NODE_FIELDS[key])
  69. .sort(function (fieldA, fieldB) {
  70. const indexA = t.BUILDER_KEYS[key].indexOf(fieldA);
  71. const indexB = t.BUILDER_KEYS[key].indexOf(fieldB);
  72. if (indexA === indexB) return fieldA < fieldB ? -1 : 1;
  73. if (indexA === -1) return 1;
  74. if (indexB === -1) return -1;
  75. return indexA - indexB;
  76. })
  77. .forEach(function (field) {
  78. const defaultValue = t.NODE_FIELDS[key][field].default;
  79. const fieldDescription = ["`" + field + "`"];
  80. const validator = t.NODE_FIELDS[key][field].validate;
  81. if (customTypes[key] && customTypes[key][field]) {
  82. fieldDescription.push(`: ${customTypes[key][field]}`);
  83. } else if (validator) {
  84. try {
  85. fieldDescription.push(
  86. ": `" + stringifyValidator(validator, "") + "`"
  87. );
  88. } catch (ex) {
  89. if (ex.code === "UNEXPECTED_VALIDATOR_TYPE") {
  90. console.log(
  91. "Unrecognised validator type for " + key + "." + field
  92. );
  93. console.dir(ex.validator, { depth: 10, colors: true });
  94. }
  95. }
  96. }
  97. if (defaultValue !== null || t.NODE_FIELDS[key][field].optional) {
  98. fieldDescription.push(
  99. " (default: `" + util.inspect(defaultValue) + "`"
  100. );
  101. if (t.BUILDER_KEYS[key].indexOf(field) < 0) {
  102. fieldDescription.push(", excluded from builder function");
  103. }
  104. fieldDescription.push(")");
  105. } else {
  106. fieldDescription.push(" (required)");
  107. }
  108. readme.push("- " + fieldDescription.join(""));
  109. });
  110. }
  111. }
  112. function printAliasKeys(key, readme) {
  113. if (t.ALIAS_KEYS[key] && t.ALIAS_KEYS[key].length) {
  114. readme.push("");
  115. readme.push(
  116. "Aliases: " +
  117. t.ALIAS_KEYS[key]
  118. .map(function (key) {
  119. return "[`" + key + "`](#" + key.toLowerCase() + ")";
  120. })
  121. .join(", ")
  122. );
  123. }
  124. }
  125. readme.push("### Node Builders");
  126. readme.push("");
  127. Object.keys(t.BUILDER_KEYS)
  128. .sort()
  129. .forEach(function (key) {
  130. readme.push("#### " + toFunctionName(key));
  131. readme.push("");
  132. readme.push("```javascript");
  133. readme.push(
  134. "t." + toFunctionName(key) + "(" + t.BUILDER_KEYS[key].join(", ") + ");"
  135. );
  136. readme.push("```");
  137. printAPIHistory(key, readme);
  138. readme.push("");
  139. readme.push(
  140. "See also `t.is" +
  141. key +
  142. "(node, opts)` and `t.assert" +
  143. key +
  144. "(node, opts)`."
  145. );
  146. printNodeFields(key, readme);
  147. printAliasKeys(key, readme);
  148. readme.push("");
  149. readme.push("---");
  150. readme.push("");
  151. });
  152. function generateMapAliasToNodeTypes() {
  153. const result = new Map();
  154. for (const nodeType of Object.keys(t.ALIAS_KEYS)) {
  155. const aliases = t.ALIAS_KEYS[nodeType];
  156. if (!aliases) continue;
  157. for (const alias of aliases) {
  158. if (!result.has(alias)) {
  159. result.set(alias, []);
  160. }
  161. const nodeTypes = result.get(alias);
  162. nodeTypes.push(nodeType);
  163. }
  164. }
  165. return result;
  166. }
  167. const aliasDescriptions = {
  168. Binary:
  169. "A cover of BinaryExpression and LogicalExpression, which share the same AST shape.",
  170. Block: "Deprecated. Will be removed in Babel 8.",
  171. BlockParent:
  172. "A cover of AST nodes that start an execution context with new [LexicalEnvironment](https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts). In other words, they define the scope of `let` and `const` declarations.",
  173. Class:
  174. "A cover of ClassExpression and ClassDeclaration, which share the same AST shape.",
  175. CompletionStatement:
  176. "A statement that indicates the [completion records](https://tc39.es/ecma262/#sec-completion-record-specification-type). In other words, they define the control flow of the program, such as when should a loop break or an action throws critical errors.",
  177. Conditional:
  178. "A cover of ConditionalExpression and IfStatement, which share the same AST shape.",
  179. Declaration:
  180. "A cover of any [Declaration](https://tc39.es/ecma262/#prod-Declaration)s.",
  181. EnumBody: "A cover of Flow enum bodies.",
  182. EnumMember: "A cover of Flow enum membors.",
  183. ExportDeclaration:
  184. "A cover of any [ExportDeclaration](https://tc39.es/ecma262/#prod-ExportDeclaration)s.",
  185. Expression:
  186. "A cover of any [Expression](https://tc39.es/ecma262/#sec-ecmascript-language-expressions)s.",
  187. ExpressionWrapper:
  188. "A wrapper of expression that does not have runtime semantics.",
  189. Flow: "A cover of AST nodes defined for Flow.",
  190. FlowBaseAnnotation: "A cover of primary Flow type annotations.",
  191. FlowDeclaration: "A cover of Flow declarations.",
  192. FlowPredicate: "A cover of Flow predicates.",
  193. FlowType: "A cover of Flow type annotations.",
  194. For: "A cover of [ForStatement](https://tc39.es/ecma262/#sec-for-statement)s and [ForXStatement](#forxstatement)s.",
  195. ForXStatement:
  196. "A cover of [ForInStatements and ForOfStatements](https://tc39.es/ecma262/#sec-for-in-and-for-of-statements).",
  197. Function:
  198. "A cover of functions and [method](#method)s, the must have `body` and `params`. Note: `Function` is different to `FunctionParent`.",
  199. FunctionParent:
  200. "A cover of AST nodes that start an execution context with new [VariableEnvironment](https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts). In other words, they define the scope of `var` declarations. FunctionParent did not include `Program` since Babel 7.",
  201. Immutable:
  202. "A cover of immutable objects and JSX elements. An object is [immutable](https://tc39.es/ecma262/#immutable-prototype-exotic-object) if no other properties can be defined once created.",
  203. JSX: "A cover of AST nodes defined for [JSX](https://facebook.github.io/jsx/).",
  204. LVal: "A cover of left hand side expressions used in the `left` of assignment expressions and [ForXStatement](#forxstatement)s. ",
  205. Literal:
  206. "A cover of [Literal](https://tc39.es/ecma262/#sec-primary-expression-literals)s, [Regular Expression Literal](https://tc39.es/ecma262/#sec-primary-expression-regular-expression-literals)s and [Template Literal](https://tc39.es/ecma262/#sec-template-literals)s.",
  207. Loop: "A cover of loop statements.",
  208. Method: "A cover of object methods and class methods.",
  209. ModuleDeclaration:
  210. "A cover of ImportDeclaration and [ExportDeclaration](#exportdeclaration)",
  211. ModuleSpecifier:
  212. "A cover of import and export specifiers. Note: It is _not_ the [ModuleSpecifier](https://tc39.es/ecma262/#prod-ModuleSpecifier) defined in the spec.",
  213. ObjectMember:
  214. "A cover of [members](https://tc39.es/ecma262/#prod-PropertyDefinitionList) in an object literal.",
  215. Pattern:
  216. "A cover of [BindingPattern](https://tc39.es/ecma262/#prod-BindingPattern) except Identifiers.",
  217. PatternLike:
  218. "A cover of [BindingPattern](https://tc39.es/ecma262/#prod-BindingPattern)s. ",
  219. Private: "A cover of private class elements and private identifiers.",
  220. Property: "A cover of object properties and class properties.",
  221. Pureish:
  222. "A cover of AST nodes which do not have side-effects. In other words, there is no observable behaviour changes if they are evaluated more than once.",
  223. Scopable:
  224. "A cover of [FunctionParent](#functionparent) and [BlockParent](#blockparent).",
  225. Statement:
  226. "A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.",
  227. TSBaseType: "A cover of primary TypeScript type annotations.",
  228. TSEntityName: "A cover of ts entities.",
  229. TSType: "A cover of TypeScript type annotations.",
  230. TSTypeElement: "A cover of TypeScript type declarations.",
  231. Terminatorless:
  232. "A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.",
  233. UnaryLike: "A cover of UnaryExpression and SpreadElement.",
  234. UserWhitespacable: "Deprecated. Will be removed in Babel 8.",
  235. While:
  236. "A cover of DoWhileStatement and WhileStatement, which share the same AST shape.",
  237. };
  238. const mapAliasToNodeTypes = generateMapAliasToNodeTypes();
  239. readme.push("### Aliases");
  240. readme.push("");
  241. for (const alias of [...mapAliasToNodeTypes.keys()].sort()) {
  242. const nodeTypes = mapAliasToNodeTypes.get(alias);
  243. nodeTypes.sort();
  244. if (!(alias in aliasDescriptions)) {
  245. throw new Error(
  246. 'Missing alias descriptions of "' +
  247. alias +
  248. ", which covers " +
  249. nodeTypes.join(",")
  250. );
  251. }
  252. readme.push("#### " + alias);
  253. readme.push("");
  254. readme.push(aliasDescriptions[alias]);
  255. readme.push("```javascript");
  256. readme.push("t.is" + alias + "(node);");
  257. readme.push("```");
  258. readme.push("");
  259. readme.push("Covered nodes: ");
  260. for (const nodeType of nodeTypes) {
  261. readme.push("- [`" + nodeType + "`](#" + nodeType.toLowerCase() + ")");
  262. }
  263. readme.push("");
  264. }
  265. process.stdout.write(readme.join("\n"));