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.

statements.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.WithStatement = WithStatement;
  6. exports.IfStatement = IfStatement;
  7. exports.ForStatement = ForStatement;
  8. exports.WhileStatement = WhileStatement;
  9. exports.DoWhileStatement = DoWhileStatement;
  10. exports.LabeledStatement = LabeledStatement;
  11. exports.TryStatement = TryStatement;
  12. exports.CatchClause = CatchClause;
  13. exports.SwitchStatement = SwitchStatement;
  14. exports.SwitchCase = SwitchCase;
  15. exports.DebuggerStatement = DebuggerStatement;
  16. exports.VariableDeclaration = VariableDeclaration;
  17. exports.VariableDeclarator = VariableDeclarator;
  18. exports.ThrowStatement = exports.BreakStatement = exports.ReturnStatement = exports.ContinueStatement = exports.ForOfStatement = exports.ForInStatement = void 0;
  19. var t = require("@babel/types");
  20. function WithStatement(node) {
  21. this.word("with");
  22. this.space();
  23. this.token("(");
  24. this.print(node.object, node);
  25. this.token(")");
  26. this.printBlock(node);
  27. }
  28. function IfStatement(node) {
  29. this.word("if");
  30. this.space();
  31. this.token("(");
  32. this.print(node.test, node);
  33. this.token(")");
  34. this.space();
  35. const needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent));
  36. if (needsBlock) {
  37. this.token("{");
  38. this.newline();
  39. this.indent();
  40. }
  41. this.printAndIndentOnComments(node.consequent, node);
  42. if (needsBlock) {
  43. this.dedent();
  44. this.newline();
  45. this.token("}");
  46. }
  47. if (node.alternate) {
  48. if (this.endsWith("}")) this.space();
  49. this.word("else");
  50. this.space();
  51. this.printAndIndentOnComments(node.alternate, node);
  52. }
  53. }
  54. function getLastStatement(statement) {
  55. if (!t.isStatement(statement.body)) return statement;
  56. return getLastStatement(statement.body);
  57. }
  58. function ForStatement(node) {
  59. this.word("for");
  60. this.space();
  61. this.token("(");
  62. this.inForStatementInitCounter++;
  63. this.print(node.init, node);
  64. this.inForStatementInitCounter--;
  65. this.token(";");
  66. if (node.test) {
  67. this.space();
  68. this.print(node.test, node);
  69. }
  70. this.token(";");
  71. if (node.update) {
  72. this.space();
  73. this.print(node.update, node);
  74. }
  75. this.token(")");
  76. this.printBlock(node);
  77. }
  78. function WhileStatement(node) {
  79. this.word("while");
  80. this.space();
  81. this.token("(");
  82. this.print(node.test, node);
  83. this.token(")");
  84. this.printBlock(node);
  85. }
  86. const buildForXStatement = function (op) {
  87. return function (node) {
  88. this.word("for");
  89. this.space();
  90. if (op === "of" && node.await) {
  91. this.word("await");
  92. this.space();
  93. }
  94. this.token("(");
  95. this.print(node.left, node);
  96. this.space();
  97. this.word(op);
  98. this.space();
  99. this.print(node.right, node);
  100. this.token(")");
  101. this.printBlock(node);
  102. };
  103. };
  104. const ForInStatement = buildForXStatement("in");
  105. exports.ForInStatement = ForInStatement;
  106. const ForOfStatement = buildForXStatement("of");
  107. exports.ForOfStatement = ForOfStatement;
  108. function DoWhileStatement(node) {
  109. this.word("do");
  110. this.space();
  111. this.print(node.body, node);
  112. this.space();
  113. this.word("while");
  114. this.space();
  115. this.token("(");
  116. this.print(node.test, node);
  117. this.token(")");
  118. this.semicolon();
  119. }
  120. function buildLabelStatement(prefix, key = "label") {
  121. return function (node) {
  122. this.word(prefix);
  123. const label = node[key];
  124. if (label) {
  125. this.space();
  126. const isLabel = key == "label";
  127. const terminatorState = this.startTerminatorless(isLabel);
  128. this.print(label, node);
  129. this.endTerminatorless(terminatorState);
  130. }
  131. this.semicolon();
  132. };
  133. }
  134. const ContinueStatement = buildLabelStatement("continue");
  135. exports.ContinueStatement = ContinueStatement;
  136. const ReturnStatement = buildLabelStatement("return", "argument");
  137. exports.ReturnStatement = ReturnStatement;
  138. const BreakStatement = buildLabelStatement("break");
  139. exports.BreakStatement = BreakStatement;
  140. const ThrowStatement = buildLabelStatement("throw", "argument");
  141. exports.ThrowStatement = ThrowStatement;
  142. function LabeledStatement(node) {
  143. this.print(node.label, node);
  144. this.token(":");
  145. this.space();
  146. this.print(node.body, node);
  147. }
  148. function TryStatement(node) {
  149. this.word("try");
  150. this.space();
  151. this.print(node.block, node);
  152. this.space();
  153. if (node.handlers) {
  154. this.print(node.handlers[0], node);
  155. } else {
  156. this.print(node.handler, node);
  157. }
  158. if (node.finalizer) {
  159. this.space();
  160. this.word("finally");
  161. this.space();
  162. this.print(node.finalizer, node);
  163. }
  164. }
  165. function CatchClause(node) {
  166. this.word("catch");
  167. this.space();
  168. if (node.param) {
  169. this.token("(");
  170. this.print(node.param, node);
  171. this.print(node.param.typeAnnotation, node);
  172. this.token(")");
  173. this.space();
  174. }
  175. this.print(node.body, node);
  176. }
  177. function SwitchStatement(node) {
  178. this.word("switch");
  179. this.space();
  180. this.token("(");
  181. this.print(node.discriminant, node);
  182. this.token(")");
  183. this.space();
  184. this.token("{");
  185. this.printSequence(node.cases, node, {
  186. indent: true,
  187. addNewlines(leading, cas) {
  188. if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
  189. }
  190. });
  191. this.token("}");
  192. }
  193. function SwitchCase(node) {
  194. if (node.test) {
  195. this.word("case");
  196. this.space();
  197. this.print(node.test, node);
  198. this.token(":");
  199. } else {
  200. this.word("default");
  201. this.token(":");
  202. }
  203. if (node.consequent.length) {
  204. this.newline();
  205. this.printSequence(node.consequent, node, {
  206. indent: true
  207. });
  208. }
  209. }
  210. function DebuggerStatement() {
  211. this.word("debugger");
  212. this.semicolon();
  213. }
  214. function variableDeclarationIndent() {
  215. this.token(",");
  216. this.newline();
  217. if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true);
  218. }
  219. function constDeclarationIndent() {
  220. this.token(",");
  221. this.newline();
  222. if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true);
  223. }
  224. function VariableDeclaration(node, parent) {
  225. if (node.declare) {
  226. this.word("declare");
  227. this.space();
  228. }
  229. this.word(node.kind);
  230. this.space();
  231. let hasInits = false;
  232. if (!t.isFor(parent)) {
  233. for (const declar of node.declarations) {
  234. if (declar.init) {
  235. hasInits = true;
  236. }
  237. }
  238. }
  239. let separator;
  240. if (hasInits) {
  241. separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent;
  242. }
  243. this.printList(node.declarations, node, {
  244. separator
  245. });
  246. if (t.isFor(parent)) {
  247. if (t.isForStatement(parent)) {
  248. if (parent.init === node) return;
  249. } else {
  250. if (parent.left === node) return;
  251. }
  252. }
  253. this.semicolon();
  254. }
  255. function VariableDeclarator(node) {
  256. this.print(node.id, node);
  257. if (node.definite) this.token("!");
  258. this.print(node.id.typeAnnotation, node);
  259. if (node.init) {
  260. this.space();
  261. this.token("=");
  262. this.space();
  263. this.print(node.init, node);
  264. }
  265. }