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.

family.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getOpposite = getOpposite;
  6. exports.getCompletionRecords = getCompletionRecords;
  7. exports.getSibling = getSibling;
  8. exports.getPrevSibling = getPrevSibling;
  9. exports.getNextSibling = getNextSibling;
  10. exports.getAllNextSiblings = getAllNextSiblings;
  11. exports.getAllPrevSiblings = getAllPrevSiblings;
  12. exports.get = get;
  13. exports._getKey = _getKey;
  14. exports._getPattern = _getPattern;
  15. exports.getBindingIdentifiers = getBindingIdentifiers;
  16. exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
  17. exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
  18. exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
  19. var _index = require("./index");
  20. var t = require("@babel/types");
  21. const NORMAL_COMPLETION = 0;
  22. const BREAK_COMPLETION = 1;
  23. function NormalCompletion(path) {
  24. return {
  25. type: NORMAL_COMPLETION,
  26. path
  27. };
  28. }
  29. function BreakCompletion(path) {
  30. return {
  31. type: BREAK_COMPLETION,
  32. path
  33. };
  34. }
  35. function getOpposite() {
  36. if (this.key === "left") {
  37. return this.getSibling("right");
  38. } else if (this.key === "right") {
  39. return this.getSibling("left");
  40. }
  41. return null;
  42. }
  43. function addCompletionRecords(path, records, context) {
  44. if (path) return records.concat(_getCompletionRecords(path, context));
  45. return records;
  46. }
  47. function completionRecordForSwitch(cases, records, context) {
  48. let lastNormalCompletions = [];
  49. for (let i = 0; i < cases.length; i++) {
  50. const casePath = cases[i];
  51. const caseCompletions = _getCompletionRecords(casePath, context);
  52. const normalCompletions = [];
  53. const breakCompletions = [];
  54. for (const c of caseCompletions) {
  55. if (c.type === NORMAL_COMPLETION) {
  56. normalCompletions.push(c);
  57. }
  58. if (c.type === BREAK_COMPLETION) {
  59. breakCompletions.push(c);
  60. }
  61. }
  62. if (normalCompletions.length) {
  63. lastNormalCompletions = normalCompletions;
  64. }
  65. records = records.concat(breakCompletions);
  66. }
  67. records = records.concat(lastNormalCompletions);
  68. return records;
  69. }
  70. function normalCompletionToBreak(completions) {
  71. completions.forEach(c => {
  72. c.type = BREAK_COMPLETION;
  73. });
  74. }
  75. function replaceBreakStatementInBreakCompletion(completions, reachable) {
  76. completions.forEach(c => {
  77. if (c.path.isBreakStatement({
  78. label: null
  79. })) {
  80. if (reachable) {
  81. c.path.replaceWith(t.unaryExpression("void", t.numericLiteral(0)));
  82. } else {
  83. c.path.remove();
  84. }
  85. }
  86. });
  87. }
  88. function getStatementListCompletion(paths, context) {
  89. let completions = [];
  90. if (context.canHaveBreak) {
  91. let lastNormalCompletions = [];
  92. for (let i = 0; i < paths.length; i++) {
  93. const path = paths[i];
  94. const newContext = Object.assign({}, context, {
  95. inCaseClause: false
  96. });
  97. if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
  98. newContext.shouldPopulateBreak = true;
  99. } else {
  100. newContext.shouldPopulateBreak = false;
  101. }
  102. const statementCompletions = _getCompletionRecords(path, newContext);
  103. if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
  104. if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({
  105. label: null
  106. }))) {
  107. normalCompletionToBreak(lastNormalCompletions);
  108. completions = completions.concat(lastNormalCompletions);
  109. if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
  110. completions = completions.concat(statementCompletions);
  111. replaceBreakStatementInBreakCompletion(statementCompletions, true);
  112. }
  113. replaceBreakStatementInBreakCompletion(statementCompletions, false);
  114. } else {
  115. completions = completions.concat(statementCompletions);
  116. if (!context.shouldPopulateBreak) {
  117. replaceBreakStatementInBreakCompletion(statementCompletions, true);
  118. }
  119. }
  120. break;
  121. }
  122. if (i === paths.length - 1) {
  123. completions = completions.concat(statementCompletions);
  124. } else {
  125. completions = completions.concat(statementCompletions.filter(c => c.type === BREAK_COMPLETION));
  126. lastNormalCompletions = statementCompletions.filter(c => c.type === NORMAL_COMPLETION);
  127. }
  128. }
  129. } else if (paths.length) {
  130. completions = completions.concat(_getCompletionRecords(paths[paths.length - 1], context));
  131. }
  132. return completions;
  133. }
  134. function _getCompletionRecords(path, context) {
  135. let records = [];
  136. if (path.isIfStatement()) {
  137. records = addCompletionRecords(path.get("consequent"), records, context);
  138. records = addCompletionRecords(path.get("alternate"), records, context);
  139. } else if (path.isDoExpression() || path.isFor() || path.isWhile() || path.isLabeledStatement()) {
  140. records = addCompletionRecords(path.get("body"), records, context);
  141. } else if (path.isProgram() || path.isBlockStatement()) {
  142. records = records.concat(getStatementListCompletion(path.get("body"), context));
  143. } else if (path.isFunction()) {
  144. return _getCompletionRecords(path.get("body"), context);
  145. } else if (path.isTryStatement()) {
  146. records = addCompletionRecords(path.get("block"), records, context);
  147. records = addCompletionRecords(path.get("handler"), records, context);
  148. } else if (path.isCatchClause()) {
  149. records = addCompletionRecords(path.get("body"), records, context);
  150. } else if (path.isSwitchStatement()) {
  151. records = completionRecordForSwitch(path.get("cases"), records, context);
  152. } else if (path.isSwitchCase()) {
  153. records = records.concat(getStatementListCompletion(path.get("consequent"), {
  154. canHaveBreak: true,
  155. shouldPopulateBreak: false,
  156. inCaseClause: true
  157. }));
  158. } else if (path.isBreakStatement()) {
  159. records.push(BreakCompletion(path));
  160. } else {
  161. records.push(NormalCompletion(path));
  162. }
  163. return records;
  164. }
  165. function getCompletionRecords() {
  166. const records = _getCompletionRecords(this, {
  167. canHaveBreak: false,
  168. shouldPopulateBreak: false,
  169. inCaseClause: false
  170. });
  171. return records.map(r => r.path);
  172. }
  173. function getSibling(key) {
  174. return _index.default.get({
  175. parentPath: this.parentPath,
  176. parent: this.parent,
  177. container: this.container,
  178. listKey: this.listKey,
  179. key: key
  180. }).setContext(this.context);
  181. }
  182. function getPrevSibling() {
  183. return this.getSibling(this.key - 1);
  184. }
  185. function getNextSibling() {
  186. return this.getSibling(this.key + 1);
  187. }
  188. function getAllNextSiblings() {
  189. let _key = this.key;
  190. let sibling = this.getSibling(++_key);
  191. const siblings = [];
  192. while (sibling.node) {
  193. siblings.push(sibling);
  194. sibling = this.getSibling(++_key);
  195. }
  196. return siblings;
  197. }
  198. function getAllPrevSiblings() {
  199. let _key = this.key;
  200. let sibling = this.getSibling(--_key);
  201. const siblings = [];
  202. while (sibling.node) {
  203. siblings.push(sibling);
  204. sibling = this.getSibling(--_key);
  205. }
  206. return siblings;
  207. }
  208. function get(key, context = true) {
  209. if (context === true) context = this.context;
  210. const parts = key.split(".");
  211. if (parts.length === 1) {
  212. return this._getKey(key, context);
  213. } else {
  214. return this._getPattern(parts, context);
  215. }
  216. }
  217. function _getKey(key, context) {
  218. const node = this.node;
  219. const container = node[key];
  220. if (Array.isArray(container)) {
  221. return container.map((_, i) => {
  222. return _index.default.get({
  223. listKey: key,
  224. parentPath: this,
  225. parent: node,
  226. container: container,
  227. key: i
  228. }).setContext(context);
  229. });
  230. } else {
  231. return _index.default.get({
  232. parentPath: this,
  233. parent: node,
  234. container: node,
  235. key: key
  236. }).setContext(context);
  237. }
  238. }
  239. function _getPattern(parts, context) {
  240. let path = this;
  241. for (const part of parts) {
  242. if (part === ".") {
  243. path = path.parentPath;
  244. } else {
  245. if (Array.isArray(path)) {
  246. path = path[part];
  247. } else {
  248. path = path.get(part, context);
  249. }
  250. }
  251. }
  252. return path;
  253. }
  254. function getBindingIdentifiers(duplicates) {
  255. return t.getBindingIdentifiers(this.node, duplicates);
  256. }
  257. function getOuterBindingIdentifiers(duplicates) {
  258. return t.getOuterBindingIdentifiers(this.node, duplicates);
  259. }
  260. function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
  261. const path = this;
  262. let search = [].concat(path);
  263. const ids = Object.create(null);
  264. while (search.length) {
  265. const id = search.shift();
  266. if (!id) continue;
  267. if (!id.node) continue;
  268. const keys = t.getBindingIdentifiers.keys[id.node.type];
  269. if (id.isIdentifier()) {
  270. if (duplicates) {
  271. const _ids = ids[id.node.name] = ids[id.node.name] || [];
  272. _ids.push(id);
  273. } else {
  274. ids[id.node.name] = id;
  275. }
  276. continue;
  277. }
  278. if (id.isExportDeclaration()) {
  279. const declaration = id.get("declaration");
  280. if (declaration.isDeclaration()) {
  281. search.push(declaration);
  282. }
  283. continue;
  284. }
  285. if (outerOnly) {
  286. if (id.isFunctionDeclaration()) {
  287. search.push(id.get("id"));
  288. continue;
  289. }
  290. if (id.isFunctionExpression()) {
  291. continue;
  292. }
  293. }
  294. if (keys) {
  295. for (let i = 0; i < keys.length; i++) {
  296. const key = keys[i];
  297. const child = id.get(key);
  298. if (Array.isArray(child) || child.node) {
  299. search = search.concat(child);
  300. }
  301. }
  302. }
  303. }
  304. return ids;
  305. }
  306. function getOuterBindingIdentifierPaths(duplicates) {
  307. return this.getBindingIdentifierPaths(duplicates, true);
  308. }