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

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

Update repo after prototype presentation

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