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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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