source: imaps-frontend/node_modules/terser/lib/utils/first_in_statement.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import {
2 AST_Binary,
3 AST_Conditional,
4 AST_Chain,
5 AST_Dot,
6 AST_Object,
7 AST_Sequence,
8 AST_Statement,
9 AST_Sub,
10 AST_UnaryPostfix,
11 AST_PrefixedTemplateString
12} from "../ast.js";
13
14// return true if the node at the top of the stack (that means the
15// innermost node in the current output) is lexically the first in
16// a statement.
17function first_in_statement(stack) {
18 let node = stack.parent(-1);
19 for (let i = 0, p; p = stack.parent(i); i++) {
20 if (p instanceof AST_Statement && p.body === node)
21 return true;
22 if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
23 (p.TYPE === "Call" && p.expression === node) ||
24 (p instanceof AST_PrefixedTemplateString && p.prefix === node) ||
25 (p instanceof AST_Dot && p.expression === node) ||
26 (p instanceof AST_Sub && p.expression === node) ||
27 (p instanceof AST_Chain && p.expression === node) ||
28 (p instanceof AST_Conditional && p.condition === node) ||
29 (p instanceof AST_Binary && p.left === node) ||
30 (p instanceof AST_UnaryPostfix && p.expression === node)
31 ) {
32 node = p;
33 } else {
34 return false;
35 }
36 }
37}
38
39// Returns whether the leftmost item in the expression is an object
40function left_is_object(node) {
41 if (node instanceof AST_Object) return true;
42 if (node instanceof AST_Sequence) return left_is_object(node.expressions[0]);
43 if (node.TYPE === "Call") return left_is_object(node.expression);
44 if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix);
45 if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression);
46 if (node instanceof AST_Chain) return left_is_object(node.expression);
47 if (node instanceof AST_Conditional) return left_is_object(node.condition);
48 if (node instanceof AST_Binary) return left_is_object(node.left);
49 if (node instanceof AST_UnaryPostfix) return left_is_object(node.expression);
50 return false;
51}
52
53export { first_in_statement, left_is_object };
Note: See TracBrowser for help on using the repository browser.