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.

index.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = hoistVariables;
  6. var t = require("@babel/types");
  7. const visitor = {
  8. Scope(path, state) {
  9. if (state.kind === "let") path.skip();
  10. },
  11. FunctionParent(path) {
  12. path.skip();
  13. },
  14. VariableDeclaration(path, state) {
  15. if (state.kind && path.node.kind !== state.kind) return;
  16. const nodes = [];
  17. const declarations = path.get("declarations");
  18. let firstId;
  19. for (const declar of declarations) {
  20. firstId = declar.node.id;
  21. if (declar.node.init) {
  22. nodes.push(t.expressionStatement(t.assignmentExpression("=", declar.node.id, declar.node.init)));
  23. }
  24. for (const name of Object.keys(declar.getBindingIdentifiers())) {
  25. state.emit(t.identifier(name), name, declar.node.init !== null);
  26. }
  27. }
  28. if (path.parentPath.isFor({
  29. left: path.node
  30. })) {
  31. path.replaceWith(firstId);
  32. } else {
  33. path.replaceWithMultiple(nodes);
  34. }
  35. }
  36. };
  37. function hoistVariables(path, emit, kind = "var") {
  38. path.traverse(visitor, {
  39. kind,
  40. emit
  41. });
  42. }