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.

asserts.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import definitions from "../../lib/definitions/index.js";
  2. function addAssertHelper(type) {
  3. const result =
  4. definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]
  5. ? `node is t.${type}`
  6. : "boolean";
  7. return `export function assert${type}(node: object | null | undefined, opts?: object | null): asserts ${
  8. result === "boolean" ? "node" : result
  9. } {
  10. assert("${type}", node, opts) }
  11. `;
  12. }
  13. export default function generateAsserts() {
  14. let output = `/*
  15. * This file is auto-generated! Do not modify it directly.
  16. * To re-generate run 'make build'
  17. */
  18. import is from "../../validators/is";
  19. import type * as t from "../..";
  20. function assert(type: string, node: any, opts?: any): void {
  21. if (!is(type, node, opts)) {
  22. throw new Error(
  23. \`Expected type "\${type}" with option \${JSON.stringify(opts)}, \` +
  24. \`but instead got "\${node.type}".\`,
  25. );
  26. }
  27. }\n\n`;
  28. Object.keys(definitions.VISITOR_KEYS).forEach(type => {
  29. output += addAssertHelper(type);
  30. });
  31. Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
  32. output += addAssertHelper(type);
  33. });
  34. Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
  35. const newType = definitions.DEPRECATED_KEYS[type];
  36. output += `export function assert${type}(node: any, opts: any): void {
  37. console.trace("The node type ${type} has been renamed to ${newType}");
  38. assert("${type}", node, opts);
  39. }\n`;
  40. });
  41. return output;
  42. }