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.

formatters.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.program = exports.expression = exports.statement = exports.statements = exports.smart = void 0;
  6. var t = require("@babel/types");
  7. function makeStatementFormatter(fn) {
  8. return {
  9. code: str => `/* @babel/template */;\n${str}`,
  10. validate: () => {},
  11. unwrap: ast => {
  12. return fn(ast.program.body.slice(1));
  13. }
  14. };
  15. }
  16. const smart = makeStatementFormatter(body => {
  17. if (body.length > 1) {
  18. return body;
  19. } else {
  20. return body[0];
  21. }
  22. });
  23. exports.smart = smart;
  24. const statements = makeStatementFormatter(body => body);
  25. exports.statements = statements;
  26. const statement = makeStatementFormatter(body => {
  27. if (body.length === 0) {
  28. throw new Error("Found nothing to return.");
  29. }
  30. if (body.length > 1) {
  31. throw new Error("Found multiple statements but wanted one");
  32. }
  33. return body[0];
  34. });
  35. exports.statement = statement;
  36. const expression = {
  37. code: str => `(\n${str}\n)`,
  38. validate: ast => {
  39. if (ast.program.body.length > 1) {
  40. throw new Error("Found multiple statements but wanted one");
  41. }
  42. if (expression.unwrap(ast).start === 0) {
  43. throw new Error("Parse result included parens.");
  44. }
  45. },
  46. unwrap: ({
  47. program
  48. }) => {
  49. const [stmt] = program.body;
  50. t.assertExpressionStatement(stmt);
  51. return stmt.expression;
  52. }
  53. };
  54. exports.expression = expression;
  55. const program = {
  56. code: str => str,
  57. validate: () => {},
  58. unwrap: ast => ast.program
  59. };
  60. exports.program = program;