source: imaps-frontend/node_modules/@babel/generator/lib/node/index.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.TokenContext = void 0;
7exports.isLastChild = isLastChild;
8exports.needsParens = needsParens;
9exports.needsWhitespace = needsWhitespace;
10exports.needsWhitespaceAfter = needsWhitespaceAfter;
11exports.needsWhitespaceBefore = needsWhitespaceBefore;
12var whitespace = require("./whitespace.js");
13var parens = require("./parentheses.js");
14var _t = require("@babel/types");
15const {
16 FLIPPED_ALIAS_KEYS,
17 VISITOR_KEYS,
18 isCallExpression,
19 isDecorator,
20 isExpressionStatement,
21 isMemberExpression,
22 isNewExpression,
23 isParenthesizedExpression
24} = _t;
25const TokenContext = exports.TokenContext = {
26 expressionStatement: 1,
27 arrowBody: 2,
28 exportDefault: 4,
29 forHead: 8,
30 forInHead: 16,
31 forOfHead: 32,
32 arrowFlowReturnType: 64
33};
34function expandAliases(obj) {
35 const map = new Map();
36 function add(type, func) {
37 const fn = map.get(type);
38 map.set(type, fn ? function (node, parent, stack, inForInit, getRawIdentifier) {
39 var _fn;
40 return (_fn = fn(node, parent, stack, inForInit, getRawIdentifier)) != null ? _fn : func(node, parent, stack, inForInit, getRawIdentifier);
41 } : func);
42 }
43 for (const type of Object.keys(obj)) {
44 const aliases = FLIPPED_ALIAS_KEYS[type];
45 if (aliases) {
46 for (const alias of aliases) {
47 add(alias, obj[type]);
48 }
49 } else {
50 add(type, obj[type]);
51 }
52 }
53 return map;
54}
55const expandedParens = expandAliases(parens);
56const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
57function isOrHasCallExpression(node) {
58 if (isCallExpression(node)) {
59 return true;
60 }
61 return isMemberExpression(node) && isOrHasCallExpression(node.object);
62}
63function needsWhitespace(node, parent, type) {
64 var _expandedWhitespaceNo;
65 if (!node) return false;
66 if (isExpressionStatement(node)) {
67 node = node.expression;
68 }
69 const flag = (_expandedWhitespaceNo = expandedWhitespaceNodes.get(node.type)) == null ? void 0 : _expandedWhitespaceNo(node, parent);
70 if (typeof flag === "number") {
71 return (flag & type) !== 0;
72 }
73 return false;
74}
75function needsWhitespaceBefore(node, parent) {
76 return needsWhitespace(node, parent, 1);
77}
78function needsWhitespaceAfter(node, parent) {
79 return needsWhitespace(node, parent, 2);
80}
81function needsParens(node, parent, tokenContext, inForInit, getRawIdentifier) {
82 var _expandedParens$get;
83 if (!parent) return false;
84 if (isNewExpression(parent) && parent.callee === node) {
85 if (isOrHasCallExpression(node)) return true;
86 }
87 if (isDecorator(parent)) {
88 return !isDecoratorMemberExpression(node) && !(isCallExpression(node) && isDecoratorMemberExpression(node.callee)) && !isParenthesizedExpression(node);
89 }
90 return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, tokenContext, inForInit, getRawIdentifier);
91}
92function isDecoratorMemberExpression(node) {
93 switch (node.type) {
94 case "Identifier":
95 return true;
96 case "MemberExpression":
97 return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object);
98 default:
99 return false;
100 }
101}
102function isLastChild(parent, child) {
103 const visitorKeys = VISITOR_KEYS[parent.type];
104 for (let i = visitorKeys.length - 1; i >= 0; i--) {
105 const val = parent[visitorKeys[i]];
106 if (val === child) {
107 return true;
108 } else if (Array.isArray(val)) {
109 let j = val.length - 1;
110 while (j >= 0 && val[j] === null) j--;
111 return j >= 0 && val[j] === child;
112 } else if (val) {
113 return false;
114 }
115 }
116 return false;
117}
118
119//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.