source: imaps-frontend/node_modules/@babel/generator/lib/node/parentheses.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: 10.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.AssignmentExpression = AssignmentExpression;
7exports.Binary = Binary;
8exports.BinaryExpression = BinaryExpression;
9exports.ClassExpression = ClassExpression;
10exports.ArrowFunctionExpression = exports.ConditionalExpression = ConditionalExpression;
11exports.DoExpression = DoExpression;
12exports.FunctionExpression = FunctionExpression;
13exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
14exports.Identifier = Identifier;
15exports.LogicalExpression = LogicalExpression;
16exports.NullableTypeAnnotation = NullableTypeAnnotation;
17exports.ObjectExpression = ObjectExpression;
18exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
19exports.OptionalCallExpression = exports.OptionalMemberExpression = OptionalMemberExpression;
20exports.SequenceExpression = SequenceExpression;
21exports.TSSatisfiesExpression = exports.TSAsExpression = TSAsExpression;
22exports.TSInferType = TSInferType;
23exports.TSInstantiationExpression = TSInstantiationExpression;
24exports.UnaryLike = exports.TSTypeAssertion = UnaryLike;
25exports.TSIntersectionType = exports.TSUnionType = TSUnionType;
26exports.IntersectionTypeAnnotation = exports.UnionTypeAnnotation = UnionTypeAnnotation;
27exports.UpdateExpression = UpdateExpression;
28exports.AwaitExpression = exports.YieldExpression = YieldExpression;
29var _t = require("@babel/types");
30var _index = require("./index.js");
31const {
32 isArrayTypeAnnotation,
33 isBinaryExpression,
34 isCallExpression,
35 isForOfStatement,
36 isIndexedAccessType,
37 isMemberExpression,
38 isObjectPattern,
39 isOptionalMemberExpression,
40 isYieldExpression,
41 isStatement
42} = _t;
43const PRECEDENCE = new Map([["||", 0], ["??", 0], ["|>", 0], ["&&", 1], ["|", 2], ["^", 3], ["&", 4], ["==", 5], ["===", 5], ["!=", 5], ["!==", 5], ["<", 6], [">", 6], ["<=", 6], [">=", 6], ["in", 6], ["instanceof", 6], [">>", 7], ["<<", 7], [">>>", 7], ["+", 8], ["-", 8], ["*", 9], ["/", 9], ["%", 9], ["**", 10]]);
44function getBinaryPrecedence(node, nodeType) {
45 if (nodeType === "BinaryExpression" || nodeType === "LogicalExpression") {
46 return PRECEDENCE.get(node.operator);
47 }
48 if (nodeType === "TSAsExpression" || nodeType === "TSSatisfiesExpression") {
49 return PRECEDENCE.get("in");
50 }
51}
52function isTSTypeExpression(nodeType) {
53 return nodeType === "TSAsExpression" || nodeType === "TSSatisfiesExpression" || nodeType === "TSTypeAssertion";
54}
55const isClassExtendsClause = (node, parent) => {
56 const parentType = parent.type;
57 return (parentType === "ClassDeclaration" || parentType === "ClassExpression") && parent.superClass === node;
58};
59const hasPostfixPart = (node, parent) => {
60 const parentType = parent.type;
61 return (parentType === "MemberExpression" || parentType === "OptionalMemberExpression") && parent.object === node || (parentType === "CallExpression" || parentType === "OptionalCallExpression" || parentType === "NewExpression") && parent.callee === node || parentType === "TaggedTemplateExpression" && parent.tag === node || parentType === "TSNonNullExpression";
62};
63function NullableTypeAnnotation(node, parent) {
64 return isArrayTypeAnnotation(parent);
65}
66function FunctionTypeAnnotation(node, parent, tokenContext) {
67 const parentType = parent.type;
68 return (parentType === "UnionTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "ArrayTypeAnnotation" || Boolean(tokenContext & _index.TokenContext.arrowFlowReturnType)
69 );
70}
71function UpdateExpression(node, parent) {
72 return hasPostfixPart(node, parent) || isClassExtendsClause(node, parent);
73}
74function needsParenBeforeExpressionBrace(tokenContext) {
75 return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.arrowBody));
76}
77function ObjectExpression(node, parent, tokenContext) {
78 return needsParenBeforeExpressionBrace(tokenContext);
79}
80function DoExpression(node, parent, tokenContext) {
81 return !node.async && Boolean(tokenContext & _index.TokenContext.expressionStatement);
82}
83function Binary(node, parent) {
84 const parentType = parent.type;
85 if (node.type === "BinaryExpression" && node.operator === "**" && parentType === "BinaryExpression" && parent.operator === "**") {
86 return parent.left === node;
87 }
88 if (isClassExtendsClause(node, parent)) {
89 return true;
90 }
91 if (hasPostfixPart(node, parent) || parentType === "UnaryExpression" || parentType === "SpreadElement" || parentType === "AwaitExpression") {
92 return true;
93 }
94 const parentPos = getBinaryPrecedence(parent, parentType);
95 if (parentPos != null) {
96 const nodePos = getBinaryPrecedence(node, node.type);
97 if (parentPos === nodePos && parentType === "BinaryExpression" && parent.right === node || parentPos > nodePos) {
98 return true;
99 }
100 }
101 return undefined;
102}
103function UnionTypeAnnotation(node, parent) {
104 const parentType = parent.type;
105 return parentType === "ArrayTypeAnnotation" || parentType === "NullableTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "UnionTypeAnnotation";
106}
107function OptionalIndexedAccessType(node, parent) {
108 return isIndexedAccessType(parent) && parent.objectType === node;
109}
110function TSAsExpression(node, parent) {
111 if ((parent.type === "AssignmentExpression" || parent.type === "AssignmentPattern") && parent.left === node) {
112 return true;
113 }
114 if (parent.type === "BinaryExpression" && (parent.operator === "|" || parent.operator === "&") && node === parent.left) {
115 return true;
116 }
117 return Binary(node, parent);
118}
119function TSUnionType(node, parent) {
120 const parentType = parent.type;
121 return parentType === "TSArrayType" || parentType === "TSOptionalType" || parentType === "TSIntersectionType" || parentType === "TSRestType";
122}
123function TSInferType(node, parent) {
124 const parentType = parent.type;
125 return parentType === "TSArrayType" || parentType === "TSOptionalType";
126}
127function TSInstantiationExpression(node, parent) {
128 const parentType = parent.type;
129 return (parentType === "CallExpression" || parentType === "OptionalCallExpression" || parentType === "NewExpression" || parentType === "TSInstantiationExpression") && !!parent.typeParameters;
130}
131function BinaryExpression(node, parent, tokenContext, inForStatementInit) {
132 return node.operator === "in" && inForStatementInit;
133}
134function SequenceExpression(node, parent) {
135 const parentType = parent.type;
136 if (parentType === "SequenceExpression" || parentType === "ParenthesizedExpression" || parentType === "MemberExpression" && parent.property === node || parentType === "OptionalMemberExpression" && parent.property === node || parentType === "TemplateLiteral") {
137 return false;
138 }
139 if (parentType === "ClassDeclaration") {
140 return true;
141 }
142 if (parentType === "ForOfStatement") {
143 return parent.right === node;
144 }
145 if (parentType === "ExportDefaultDeclaration") {
146 return true;
147 }
148 return !isStatement(parent);
149}
150function YieldExpression(node, parent) {
151 const parentType = parent.type;
152 return parentType === "BinaryExpression" || parentType === "LogicalExpression" || parentType === "UnaryExpression" || parentType === "SpreadElement" || hasPostfixPart(node, parent) || parentType === "AwaitExpression" && isYieldExpression(node) || parentType === "ConditionalExpression" && node === parent.test || isClassExtendsClause(node, parent) || isTSTypeExpression(parentType);
153}
154function ClassExpression(node, parent, tokenContext) {
155 return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.exportDefault));
156}
157function UnaryLike(node, parent) {
158 return hasPostfixPart(node, parent) || isBinaryExpression(parent) && parent.operator === "**" && parent.left === node || isClassExtendsClause(node, parent);
159}
160function FunctionExpression(node, parent, tokenContext) {
161 return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.exportDefault));
162}
163function ConditionalExpression(node, parent) {
164 const parentType = parent.type;
165 if (parentType === "UnaryExpression" || parentType === "SpreadElement" || parentType === "BinaryExpression" || parentType === "LogicalExpression" || parentType === "ConditionalExpression" && parent.test === node || parentType === "AwaitExpression" || isTSTypeExpression(parentType)) {
166 return true;
167 }
168 return UnaryLike(node, parent);
169}
170function OptionalMemberExpression(node, parent) {
171 return isCallExpression(parent) && parent.callee === node || isMemberExpression(parent) && parent.object === node;
172}
173function AssignmentExpression(node, parent, tokenContext) {
174 if (needsParenBeforeExpressionBrace(tokenContext) && isObjectPattern(node.left)) {
175 return true;
176 } else {
177 return ConditionalExpression(node, parent);
178 }
179}
180function LogicalExpression(node, parent) {
181 const parentType = parent.type;
182 if (isTSTypeExpression(parentType)) return true;
183 if (parentType !== "LogicalExpression") return false;
184 switch (node.operator) {
185 case "||":
186 return parent.operator === "??" || parent.operator === "&&";
187 case "&&":
188 return parent.operator === "??";
189 case "??":
190 return parent.operator !== "??";
191 }
192}
193function Identifier(node, parent, tokenContext, _inForInit, getRawIdentifier) {
194 var _node$extra;
195 const parentType = parent.type;
196 if ((_node$extra = node.extra) != null && _node$extra.parenthesized && parentType === "AssignmentExpression" && parent.left === node) {
197 const rightType = parent.right.type;
198 if ((rightType === "FunctionExpression" || rightType === "ClassExpression") && parent.right.id == null) {
199 return true;
200 }
201 }
202 if (getRawIdentifier && getRawIdentifier(node) !== node.name) {
203 return false;
204 }
205 if (node.name === "let") {
206 const isFollowedByBracket = isMemberExpression(parent, {
207 object: node,
208 computed: true
209 }) || isOptionalMemberExpression(parent, {
210 object: node,
211 computed: true,
212 optional: false
213 });
214 if (isFollowedByBracket && tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.forHead | _index.TokenContext.forInHead)) {
215 return true;
216 }
217 return Boolean(tokenContext & _index.TokenContext.forOfHead);
218 }
219 return node.name === "async" && isForOfStatement(parent, {
220 left: node,
221 await: false
222 });
223}
224
225//# sourceMappingURL=parentheses.js.map
Note: See TracBrowser for help on using the repository browser.