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.

parentheses.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.NullableTypeAnnotation = NullableTypeAnnotation;
  6. exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
  7. exports.UpdateExpression = UpdateExpression;
  8. exports.ObjectExpression = ObjectExpression;
  9. exports.DoExpression = DoExpression;
  10. exports.Binary = Binary;
  11. exports.IntersectionTypeAnnotation = exports.UnionTypeAnnotation = UnionTypeAnnotation;
  12. exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
  13. exports.TSAsExpression = TSAsExpression;
  14. exports.TSTypeAssertion = TSTypeAssertion;
  15. exports.TSIntersectionType = exports.TSUnionType = TSUnionType;
  16. exports.TSInferType = TSInferType;
  17. exports.BinaryExpression = BinaryExpression;
  18. exports.SequenceExpression = SequenceExpression;
  19. exports.AwaitExpression = exports.YieldExpression = YieldExpression;
  20. exports.ClassExpression = ClassExpression;
  21. exports.UnaryLike = UnaryLike;
  22. exports.FunctionExpression = FunctionExpression;
  23. exports.ArrowFunctionExpression = ArrowFunctionExpression;
  24. exports.ConditionalExpression = ConditionalExpression;
  25. exports.OptionalCallExpression = exports.OptionalMemberExpression = OptionalMemberExpression;
  26. exports.AssignmentExpression = AssignmentExpression;
  27. exports.LogicalExpression = LogicalExpression;
  28. exports.Identifier = Identifier;
  29. var t = require("@babel/types");
  30. const PRECEDENCE = {
  31. "||": 0,
  32. "??": 0,
  33. "&&": 1,
  34. "|": 2,
  35. "^": 3,
  36. "&": 4,
  37. "==": 5,
  38. "===": 5,
  39. "!=": 5,
  40. "!==": 5,
  41. "<": 6,
  42. ">": 6,
  43. "<=": 6,
  44. ">=": 6,
  45. in: 6,
  46. instanceof: 6,
  47. ">>": 7,
  48. "<<": 7,
  49. ">>>": 7,
  50. "+": 8,
  51. "-": 8,
  52. "*": 9,
  53. "/": 9,
  54. "%": 9,
  55. "**": 10
  56. };
  57. const isClassExtendsClause = (node, parent) => (t.isClassDeclaration(parent) || t.isClassExpression(parent)) && parent.superClass === node;
  58. const hasPostfixPart = (node, parent) => (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.object === node || (t.isCallExpression(parent) || t.isOptionalCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node || t.isTaggedTemplateExpression(parent) && parent.tag === node || t.isTSNonNullExpression(parent);
  59. function NullableTypeAnnotation(node, parent) {
  60. return t.isArrayTypeAnnotation(parent);
  61. }
  62. function FunctionTypeAnnotation(node, parent, printStack) {
  63. return t.isUnionTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isArrayTypeAnnotation(parent) || t.isTypeAnnotation(parent) && t.isArrowFunctionExpression(printStack[printStack.length - 3]);
  64. }
  65. function UpdateExpression(node, parent) {
  66. return hasPostfixPart(node, parent) || isClassExtendsClause(node, parent);
  67. }
  68. function ObjectExpression(node, parent, printStack) {
  69. return isFirstInContext(printStack, {
  70. expressionStatement: true,
  71. arrowBody: true
  72. });
  73. }
  74. function DoExpression(node, parent, printStack) {
  75. return !node.async && isFirstInContext(printStack, {
  76. expressionStatement: true
  77. });
  78. }
  79. function Binary(node, parent) {
  80. if (node.operator === "**" && t.isBinaryExpression(parent, {
  81. operator: "**"
  82. })) {
  83. return parent.left === node;
  84. }
  85. if (isClassExtendsClause(node, parent)) {
  86. return true;
  87. }
  88. if (hasPostfixPart(node, parent) || t.isUnaryLike(parent) || t.isAwaitExpression(parent)) {
  89. return true;
  90. }
  91. if (t.isBinary(parent)) {
  92. const parentOp = parent.operator;
  93. const parentPos = PRECEDENCE[parentOp];
  94. const nodeOp = node.operator;
  95. const nodePos = PRECEDENCE[nodeOp];
  96. if (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent) || parentPos > nodePos) {
  97. return true;
  98. }
  99. }
  100. }
  101. function UnionTypeAnnotation(node, parent) {
  102. return t.isArrayTypeAnnotation(parent) || t.isNullableTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isUnionTypeAnnotation(parent);
  103. }
  104. function OptionalIndexedAccessType(node, parent) {
  105. return t.isIndexedAccessType(parent, {
  106. objectType: node
  107. });
  108. }
  109. function TSAsExpression() {
  110. return true;
  111. }
  112. function TSTypeAssertion() {
  113. return true;
  114. }
  115. function TSUnionType(node, parent) {
  116. return t.isTSArrayType(parent) || t.isTSOptionalType(parent) || t.isTSIntersectionType(parent) || t.isTSUnionType(parent) || t.isTSRestType(parent);
  117. }
  118. function TSInferType(node, parent) {
  119. return t.isTSArrayType(parent) || t.isTSOptionalType(parent);
  120. }
  121. function BinaryExpression(node, parent) {
  122. return node.operator === "in" && (t.isVariableDeclarator(parent) || t.isFor(parent));
  123. }
  124. function SequenceExpression(node, parent) {
  125. if (t.isForStatement(parent) || t.isThrowStatement(parent) || t.isReturnStatement(parent) || t.isIfStatement(parent) && parent.test === node || t.isWhileStatement(parent) && parent.test === node || t.isForInStatement(parent) && parent.right === node || t.isSwitchStatement(parent) && parent.discriminant === node || t.isExpressionStatement(parent) && parent.expression === node) {
  126. return false;
  127. }
  128. return true;
  129. }
  130. function YieldExpression(node, parent) {
  131. return t.isBinary(parent) || t.isUnaryLike(parent) || hasPostfixPart(node, parent) || t.isAwaitExpression(parent) && t.isYieldExpression(node) || t.isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent);
  132. }
  133. function ClassExpression(node, parent, printStack) {
  134. return isFirstInContext(printStack, {
  135. expressionStatement: true,
  136. exportDefault: true
  137. });
  138. }
  139. function UnaryLike(node, parent) {
  140. return hasPostfixPart(node, parent) || t.isBinaryExpression(parent, {
  141. operator: "**",
  142. left: node
  143. }) || isClassExtendsClause(node, parent);
  144. }
  145. function FunctionExpression(node, parent, printStack) {
  146. return isFirstInContext(printStack, {
  147. expressionStatement: true,
  148. exportDefault: true
  149. });
  150. }
  151. function ArrowFunctionExpression(node, parent) {
  152. return t.isExportDeclaration(parent) || ConditionalExpression(node, parent);
  153. }
  154. function ConditionalExpression(node, parent) {
  155. if (t.isUnaryLike(parent) || t.isBinary(parent) || t.isConditionalExpression(parent, {
  156. test: node
  157. }) || t.isAwaitExpression(parent) || t.isTSTypeAssertion(parent) || t.isTSAsExpression(parent)) {
  158. return true;
  159. }
  160. return UnaryLike(node, parent);
  161. }
  162. function OptionalMemberExpression(node, parent) {
  163. return t.isCallExpression(parent, {
  164. callee: node
  165. }) || t.isMemberExpression(parent, {
  166. object: node
  167. });
  168. }
  169. function AssignmentExpression(node, parent) {
  170. if (t.isObjectPattern(node.left)) {
  171. return true;
  172. } else {
  173. return ConditionalExpression(node, parent);
  174. }
  175. }
  176. function LogicalExpression(node, parent) {
  177. switch (node.operator) {
  178. case "||":
  179. if (!t.isLogicalExpression(parent)) return false;
  180. return parent.operator === "??" || parent.operator === "&&";
  181. case "&&":
  182. return t.isLogicalExpression(parent, {
  183. operator: "??"
  184. });
  185. case "??":
  186. return t.isLogicalExpression(parent) && parent.operator !== "??";
  187. }
  188. }
  189. function Identifier(node, parent, printStack) {
  190. if (node.name === "let") {
  191. const isFollowedByBracket = t.isMemberExpression(parent, {
  192. object: node,
  193. computed: true
  194. }) || t.isOptionalMemberExpression(parent, {
  195. object: node,
  196. computed: true,
  197. optional: false
  198. });
  199. return isFirstInContext(printStack, {
  200. expressionStatement: isFollowedByBracket,
  201. forHead: isFollowedByBracket,
  202. forInHead: isFollowedByBracket,
  203. forOfHead: true
  204. });
  205. }
  206. return node.name === "async" && t.isForOfStatement(parent) && node === parent.left;
  207. }
  208. function isFirstInContext(printStack, {
  209. expressionStatement = false,
  210. arrowBody = false,
  211. exportDefault = false,
  212. forHead = false,
  213. forInHead = false,
  214. forOfHead = false
  215. }) {
  216. let i = printStack.length - 1;
  217. let node = printStack[i];
  218. i--;
  219. let parent = printStack[i];
  220. while (i >= 0) {
  221. if (expressionStatement && t.isExpressionStatement(parent, {
  222. expression: node
  223. }) || exportDefault && t.isExportDefaultDeclaration(parent, {
  224. declaration: node
  225. }) || arrowBody && t.isArrowFunctionExpression(parent, {
  226. body: node
  227. }) || forHead && t.isForStatement(parent, {
  228. init: node
  229. }) || forInHead && t.isForInStatement(parent, {
  230. left: node
  231. }) || forOfHead && t.isForOfStatement(parent, {
  232. left: node
  233. })) {
  234. return true;
  235. }
  236. if (hasPostfixPart(node, parent) && !t.isNewExpression(parent) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isConditional(parent, {
  237. test: node
  238. }) || t.isBinary(parent, {
  239. left: node
  240. }) || t.isAssignmentExpression(parent, {
  241. left: node
  242. })) {
  243. node = parent;
  244. i--;
  245. parent = printStack[i];
  246. } else {
  247. return false;
  248. }
  249. }
  250. return false;
  251. }