@babel/traverse 7.17.9 → 7.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/lib/cache.js +27 -7
  3. package/lib/cache.js.map +1 -0
  4. package/lib/context.js +9 -31
  5. package/lib/context.js.map +1 -0
  6. package/lib/hub.js +2 -6
  7. package/lib/hub.js.map +1 -0
  8. package/lib/index.js +17 -33
  9. package/lib/index.js.map +1 -0
  10. package/lib/path/ancestry.js +3 -42
  11. package/lib/path/ancestry.js.map +1 -0
  12. package/lib/path/comments.js +23 -11
  13. package/lib/path/comments.js.map +1 -0
  14. package/lib/path/context.js +24 -65
  15. package/lib/path/context.js.map +1 -0
  16. package/lib/path/conversion.js +37 -100
  17. package/lib/path/conversion.js.map +1 -0
  18. package/lib/path/evaluation.js +69 -123
  19. package/lib/path/evaluation.js.map +1 -0
  20. package/lib/path/family.js +5 -76
  21. package/lib/path/family.js.map +1 -0
  22. package/lib/path/index.js +26 -90
  23. package/lib/path/index.js.map +1 -0
  24. package/lib/path/inference/index.js +26 -33
  25. package/lib/path/inference/index.js.map +1 -0
  26. package/lib/path/inference/inferer-reference.js +6 -61
  27. package/lib/path/inference/inferer-reference.js.map +1 -0
  28. package/lib/path/inference/inferers.js +32 -86
  29. package/lib/path/inference/inferers.js.map +1 -0
  30. package/lib/path/inference/util.js +30 -0
  31. package/lib/path/inference/util.js.map +1 -0
  32. package/lib/path/introspection.js +54 -105
  33. package/lib/path/introspection.js.map +1 -0
  34. package/lib/path/lib/hoister.js +2 -37
  35. package/lib/path/lib/hoister.js.map +1 -0
  36. package/lib/path/lib/removal-hooks.js +4 -4
  37. package/lib/path/lib/removal-hooks.js.map +1 -0
  38. package/lib/path/lib/virtual-types-validator.js +161 -0
  39. package/lib/path/lib/virtual-types-validator.js.map +1 -0
  40. package/lib/path/lib/virtual-types.js +20 -206
  41. package/lib/path/lib/virtual-types.js.map +1 -0
  42. package/lib/path/modification.js +17 -61
  43. package/lib/path/modification.js.map +1 -0
  44. package/lib/path/removal.js +9 -22
  45. package/lib/path/removal.js.map +1 -0
  46. package/lib/path/replacement.js +17 -72
  47. package/lib/path/replacement.js.map +1 -0
  48. package/lib/scope/binding.js +20 -12
  49. package/lib/scope/binding.js.map +1 -0
  50. package/lib/scope/index.js +115 -245
  51. package/lib/scope/index.js.map +1 -0
  52. package/lib/scope/lib/renamer.js +41 -74
  53. package/lib/scope/lib/renamer.js.map +1 -0
  54. package/lib/traverse-node.js +10 -11
  55. package/lib/traverse-node.js.map +1 -0
  56. package/lib/types.js +1 -3
  57. package/lib/types.js.map +1 -0
  58. package/lib/visitors.js +59 -83
  59. package/lib/visitors.js.map +1 -0
  60. package/package.json +13 -11
  61. package/lib/path/generated/asserts.js +0 -5
  62. package/lib/path/generated/validators.js +0 -5
  63. package/lib/path/generated/virtual-types.js +0 -3
  64. package/scripts/generators/asserts.js +0 -25
  65. package/scripts/generators/validators.js +0 -42
  66. package/scripts/generators/virtual-types.js +0 -24
  67. package/scripts/package.json +0 -1
@@ -26,17 +26,17 @@ exports.RegExpLiteral = RegExpLiteral;
26
26
  exports.RestElement = RestElement;
27
27
  exports.SequenceExpression = SequenceExpression;
28
28
  exports.StringLiteral = StringLiteral;
29
+ exports.TSAsExpression = TSAsExpression;
30
+ exports.TSNonNullExpression = TSNonNullExpression;
29
31
  exports.TaggedTemplateExpression = TaggedTemplateExpression;
30
32
  exports.TemplateLiteral = TemplateLiteral;
31
33
  exports.TypeCastExpression = TypeCastExpression;
32
34
  exports.UnaryExpression = UnaryExpression;
33
35
  exports.UpdateExpression = UpdateExpression;
34
36
  exports.VariableDeclarator = VariableDeclarator;
35
-
36
37
  var _t = require("@babel/types");
37
-
38
- var _infererReference = require("./inferer-reference");
39
-
38
+ var _infererReference = require("./inferer-reference.js");
39
+ var _util = require("./util.js");
40
40
  const {
41
41
  BOOLEAN_BINARY_OPERATORS,
42
42
  BOOLEAN_UNARY_OPERATORS,
@@ -47,58 +47,41 @@ const {
47
47
  arrayTypeAnnotation,
48
48
  booleanTypeAnnotation,
49
49
  buildMatchMemberExpression,
50
- createFlowUnionType,
51
- createTSUnionType,
52
- createUnionTypeAnnotation,
53
50
  genericTypeAnnotation,
54
51
  identifier,
55
- isTSTypeAnnotation,
56
52
  nullLiteralTypeAnnotation,
57
53
  numberTypeAnnotation,
58
54
  stringTypeAnnotation,
59
55
  tupleTypeAnnotation,
60
56
  unionTypeAnnotation,
61
- voidTypeAnnotation
57
+ voidTypeAnnotation,
58
+ isIdentifier
62
59
  } = _t;
63
-
64
60
  function VariableDeclarator() {
65
- var _type;
66
-
67
- const id = this.get("id");
68
- if (!id.isIdentifier()) return;
69
- const init = this.get("init");
70
- let type = init.getTypeAnnotation();
71
-
72
- if (((_type = type) == null ? void 0 : _type.type) === "AnyTypeAnnotation") {
73
- if (init.isCallExpression() && init.get("callee").isIdentifier({
74
- name: "Array"
75
- }) && !init.scope.hasBinding("Array", true)) {
76
- type = ArrayExpression();
77
- }
78
- }
79
-
80
- return type;
61
+ if (!this.get("id").isIdentifier()) return;
62
+ return this.get("init").getTypeAnnotation();
81
63
  }
82
-
83
64
  function TypeCastExpression(node) {
84
65
  return node.typeAnnotation;
85
66
  }
86
-
87
67
  TypeCastExpression.validParent = true;
88
-
68
+ function TSAsExpression(node) {
69
+ return node.typeAnnotation;
70
+ }
71
+ TSAsExpression.validParent = true;
72
+ function TSNonNullExpression() {
73
+ return this.get("expression").getTypeAnnotation();
74
+ }
89
75
  function NewExpression(node) {
90
- if (this.get("callee").isIdentifier()) {
76
+ if (node.callee.type === "Identifier") {
91
77
  return genericTypeAnnotation(node.callee);
92
78
  }
93
79
  }
94
-
95
80
  function TemplateLiteral() {
96
81
  return stringTypeAnnotation();
97
82
  }
98
-
99
83
  function UnaryExpression(node) {
100
84
  const operator = node.operator;
101
-
102
85
  if (operator === "void") {
103
86
  return voidTypeAnnotation();
104
87
  } else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
@@ -109,10 +92,8 @@ function UnaryExpression(node) {
109
92
  return booleanTypeAnnotation();
110
93
  }
111
94
  }
112
-
113
95
  function BinaryExpression(node) {
114
96
  const operator = node.operator;
115
-
116
97
  if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
117
98
  return numberTypeAnnotation();
118
99
  } else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
@@ -120,142 +101,107 @@ function BinaryExpression(node) {
120
101
  } else if (operator === "+") {
121
102
  const right = this.get("right");
122
103
  const left = this.get("left");
123
-
124
104
  if (left.isBaseType("number") && right.isBaseType("number")) {
125
105
  return numberTypeAnnotation();
126
106
  } else if (left.isBaseType("string") || right.isBaseType("string")) {
127
107
  return stringTypeAnnotation();
128
108
  }
129
-
130
109
  return unionTypeAnnotation([stringTypeAnnotation(), numberTypeAnnotation()]);
131
110
  }
132
111
  }
133
-
134
112
  function LogicalExpression() {
135
113
  const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
136
-
137
- if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
138
- return createTSUnionType(argumentTypes);
139
- }
140
-
141
- if (createFlowUnionType) {
142
- return createFlowUnionType(argumentTypes);
143
- }
144
-
145
- return createUnionTypeAnnotation(argumentTypes);
114
+ return (0, _util.createUnionType)(argumentTypes);
146
115
  }
147
-
148
116
  function ConditionalExpression() {
149
117
  const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
150
-
151
- if (isTSTypeAnnotation(argumentTypes[0]) && createTSUnionType) {
152
- return createTSUnionType(argumentTypes);
153
- }
154
-
155
- if (createFlowUnionType) {
156
- return createFlowUnionType(argumentTypes);
157
- }
158
-
159
- return createUnionTypeAnnotation(argumentTypes);
118
+ return (0, _util.createUnionType)(argumentTypes);
160
119
  }
161
-
162
120
  function SequenceExpression() {
163
121
  return this.get("expressions").pop().getTypeAnnotation();
164
122
  }
165
-
166
123
  function ParenthesizedExpression() {
167
124
  return this.get("expression").getTypeAnnotation();
168
125
  }
169
-
170
126
  function AssignmentExpression() {
171
127
  return this.get("right").getTypeAnnotation();
172
128
  }
173
-
174
129
  function UpdateExpression(node) {
175
130
  const operator = node.operator;
176
-
177
131
  if (operator === "++" || operator === "--") {
178
132
  return numberTypeAnnotation();
179
133
  }
180
134
  }
181
-
182
135
  function StringLiteral() {
183
136
  return stringTypeAnnotation();
184
137
  }
185
-
186
138
  function NumericLiteral() {
187
139
  return numberTypeAnnotation();
188
140
  }
189
-
190
141
  function BooleanLiteral() {
191
142
  return booleanTypeAnnotation();
192
143
  }
193
-
194
144
  function NullLiteral() {
195
145
  return nullLiteralTypeAnnotation();
196
146
  }
197
-
198
147
  function RegExpLiteral() {
199
148
  return genericTypeAnnotation(identifier("RegExp"));
200
149
  }
201
-
202
150
  function ObjectExpression() {
203
151
  return genericTypeAnnotation(identifier("Object"));
204
152
  }
205
-
206
153
  function ArrayExpression() {
207
154
  return genericTypeAnnotation(identifier("Array"));
208
155
  }
209
-
210
156
  function RestElement() {
211
157
  return ArrayExpression();
212
158
  }
213
-
214
159
  RestElement.validParent = true;
215
-
216
160
  function Func() {
217
161
  return genericTypeAnnotation(identifier("Function"));
218
162
  }
219
-
220
163
  const isArrayFrom = buildMatchMemberExpression("Array.from");
221
164
  const isObjectKeys = buildMatchMemberExpression("Object.keys");
222
165
  const isObjectValues = buildMatchMemberExpression("Object.values");
223
166
  const isObjectEntries = buildMatchMemberExpression("Object.entries");
224
-
225
167
  function CallExpression() {
226
168
  const {
227
169
  callee
228
170
  } = this.node;
229
-
230
171
  if (isObjectKeys(callee)) {
231
172
  return arrayTypeAnnotation(stringTypeAnnotation());
232
- } else if (isArrayFrom(callee) || isObjectValues(callee)) {
173
+ } else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, {
174
+ name: "Array"
175
+ })) {
233
176
  return arrayTypeAnnotation(anyTypeAnnotation());
234
177
  } else if (isObjectEntries(callee)) {
235
178
  return arrayTypeAnnotation(tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]));
236
179
  }
237
-
238
180
  return resolveCall(this.get("callee"));
239
181
  }
240
-
241
182
  function TaggedTemplateExpression() {
242
183
  return resolveCall(this.get("tag"));
243
184
  }
244
-
245
185
  function resolveCall(callee) {
246
186
  callee = callee.resolve();
247
-
248
187
  if (callee.isFunction()) {
249
- if (callee.is("async")) {
250
- if (callee.is("generator")) {
188
+ const {
189
+ node
190
+ } = callee;
191
+ if (node.async) {
192
+ if (node.generator) {
251
193
  return genericTypeAnnotation(identifier("AsyncIterator"));
252
194
  } else {
253
195
  return genericTypeAnnotation(identifier("Promise"));
254
196
  }
255
197
  } else {
256
- if (callee.node.returnType) {
198
+ if (node.generator) {
199
+ return genericTypeAnnotation(identifier("Iterator"));
200
+ } else if (callee.node.returnType) {
257
201
  return callee.node.returnType;
258
202
  } else {}
259
203
  }
260
204
  }
261
- }
205
+ }
206
+
207
+ //# sourceMappingURL=inferers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","_infererReference","_util","BOOLEAN_BINARY_OPERATORS","BOOLEAN_UNARY_OPERATORS","NUMBER_BINARY_OPERATORS","NUMBER_UNARY_OPERATORS","STRING_UNARY_OPERATORS","anyTypeAnnotation","arrayTypeAnnotation","booleanTypeAnnotation","buildMatchMemberExpression","genericTypeAnnotation","identifier","nullLiteralTypeAnnotation","numberTypeAnnotation","stringTypeAnnotation","tupleTypeAnnotation","unionTypeAnnotation","voidTypeAnnotation","isIdentifier","VariableDeclarator","get","getTypeAnnotation","TypeCastExpression","node","typeAnnotation","validParent","TSAsExpression","TSNonNullExpression","NewExpression","callee","type","TemplateLiteral","UnaryExpression","operator","indexOf","BinaryExpression","right","left","isBaseType","LogicalExpression","argumentTypes","createUnionType","ConditionalExpression","SequenceExpression","pop","ParenthesizedExpression","AssignmentExpression","UpdateExpression","StringLiteral","NumericLiteral","BooleanLiteral","NullLiteral","RegExpLiteral","ObjectExpression","ArrayExpression","RestElement","Func","isArrayFrom","isObjectKeys","isObjectValues","isObjectEntries","CallExpression","name","resolveCall","TaggedTemplateExpression","resolve","isFunction","async","generator","returnType"],"sources":["../../../src/path/inference/inferers.ts"],"sourcesContent":["import {\n BOOLEAN_BINARY_OPERATORS,\n BOOLEAN_UNARY_OPERATORS,\n NUMBER_BINARY_OPERATORS,\n NUMBER_UNARY_OPERATORS,\n STRING_UNARY_OPERATORS,\n anyTypeAnnotation,\n arrayTypeAnnotation,\n booleanTypeAnnotation,\n buildMatchMemberExpression,\n genericTypeAnnotation,\n identifier,\n nullLiteralTypeAnnotation,\n numberTypeAnnotation,\n stringTypeAnnotation,\n tupleTypeAnnotation,\n unionTypeAnnotation,\n voidTypeAnnotation,\n isIdentifier,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nexport { default as Identifier } from \"./inferer-reference.ts\";\n\nimport { createUnionType } from \"./util.ts\";\nimport type NodePath from \"../index.ts\";\n\nexport function VariableDeclarator(this: NodePath<t.VariableDeclarator>) {\n if (!this.get(\"id\").isIdentifier()) return;\n return this.get(\"init\").getTypeAnnotation();\n}\n\nexport function TypeCastExpression(node: t.TypeCastExpression) {\n return node.typeAnnotation;\n}\n\nTypeCastExpression.validParent = true;\n\nexport function TSAsExpression(node: t.TSAsExpression) {\n return node.typeAnnotation;\n}\n\nTSAsExpression.validParent = true;\n\nexport function TSNonNullExpression(this: NodePath<t.TSNonNullExpression>) {\n return this.get(\"expression\").getTypeAnnotation();\n}\n\nexport function NewExpression(\n this: NodePath<t.NewExpression>,\n node: t.NewExpression,\n) {\n if (node.callee.type === \"Identifier\") {\n // only resolve identifier callee\n return genericTypeAnnotation(node.callee);\n }\n}\n\nexport function TemplateLiteral() {\n return stringTypeAnnotation();\n}\n\nexport function UnaryExpression(node: t.UnaryExpression) {\n const operator = node.operator;\n\n if (operator === \"void\") {\n return voidTypeAnnotation();\n } else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {\n return numberTypeAnnotation();\n } else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {\n return stringTypeAnnotation();\n } else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {\n return booleanTypeAnnotation();\n }\n}\n\nexport function BinaryExpression(\n this: NodePath<t.BinaryExpression>,\n node: t.BinaryExpression,\n) {\n const operator = node.operator;\n\n if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {\n return numberTypeAnnotation();\n } else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {\n return booleanTypeAnnotation();\n } else if (operator === \"+\") {\n const right = this.get(\"right\");\n const left = this.get(\"left\");\n\n if (left.isBaseType(\"number\") && right.isBaseType(\"number\")) {\n // both numbers so this will be a number\n return numberTypeAnnotation();\n } else if (left.isBaseType(\"string\") || right.isBaseType(\"string\")) {\n // one is a string so the result will be a string\n return stringTypeAnnotation();\n }\n\n // unsure if left and right are strings or numbers so stay on the safe side\n return unionTypeAnnotation([\n stringTypeAnnotation(),\n numberTypeAnnotation(),\n ]);\n }\n}\n\nexport function LogicalExpression(this: NodePath<t.LogicalExpression>) {\n const argumentTypes = [\n this.get(\"left\").getTypeAnnotation(),\n this.get(\"right\").getTypeAnnotation(),\n ];\n\n return createUnionType(argumentTypes);\n}\n\nexport function ConditionalExpression(this: NodePath<t.ConditionalExpression>) {\n const argumentTypes = [\n this.get(\"consequent\").getTypeAnnotation(),\n this.get(\"alternate\").getTypeAnnotation(),\n ];\n\n return createUnionType(argumentTypes);\n}\n\nexport function SequenceExpression(this: NodePath<t.SequenceExpression>) {\n return this.get(\"expressions\").pop().getTypeAnnotation();\n}\n\nexport function ParenthesizedExpression(\n this: NodePath<t.ParenthesizedExpression>,\n) {\n return this.get(\"expression\").getTypeAnnotation();\n}\n\nexport function AssignmentExpression(this: NodePath<t.AssignmentExpression>) {\n return this.get(\"right\").getTypeAnnotation();\n}\n\nexport function UpdateExpression(\n this: NodePath<t.UpdateExpression>,\n node: t.UpdateExpression,\n) {\n const operator = node.operator;\n if (operator === \"++\" || operator === \"--\") {\n return numberTypeAnnotation();\n }\n}\n\nexport function StringLiteral() {\n return stringTypeAnnotation();\n}\n\nexport function NumericLiteral() {\n return numberTypeAnnotation();\n}\n\nexport function BooleanLiteral() {\n return booleanTypeAnnotation();\n}\n\nexport function NullLiteral() {\n return nullLiteralTypeAnnotation();\n}\n\nexport function RegExpLiteral() {\n return genericTypeAnnotation(identifier(\"RegExp\"));\n}\n\nexport function ObjectExpression() {\n return genericTypeAnnotation(identifier(\"Object\"));\n}\n\nexport function ArrayExpression() {\n return genericTypeAnnotation(identifier(\"Array\"));\n}\n\nexport function RestElement() {\n return ArrayExpression();\n}\n\nRestElement.validParent = true;\n\nfunction Func() {\n return genericTypeAnnotation(identifier(\"Function\"));\n}\n\nexport {\n Func as FunctionExpression,\n Func as ArrowFunctionExpression,\n Func as FunctionDeclaration,\n Func as ClassExpression,\n Func as ClassDeclaration,\n};\n\nconst isArrayFrom = buildMatchMemberExpression(\"Array.from\");\nconst isObjectKeys = buildMatchMemberExpression(\"Object.keys\");\nconst isObjectValues = buildMatchMemberExpression(\"Object.values\");\nconst isObjectEntries = buildMatchMemberExpression(\"Object.entries\");\nexport function CallExpression(this: NodePath<t.CallExpression>) {\n const { callee } = this.node;\n if (isObjectKeys(callee)) {\n return arrayTypeAnnotation(stringTypeAnnotation());\n } else if (\n isArrayFrom(callee) ||\n isObjectValues(callee) ||\n // Detect \"var foo = Array()\" calls so we can optimize for arrays vs iterables.\n isIdentifier(callee, { name: \"Array\" })\n ) {\n return arrayTypeAnnotation(anyTypeAnnotation());\n } else if (isObjectEntries(callee)) {\n return arrayTypeAnnotation(\n tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]),\n );\n }\n\n return resolveCall(this.get(\"callee\"));\n}\n\nexport function TaggedTemplateExpression(\n this: NodePath<t.TaggedTemplateExpression>,\n) {\n return resolveCall(this.get(\"tag\"));\n}\n\nfunction resolveCall(callee: NodePath) {\n callee = callee.resolve();\n\n if (callee.isFunction()) {\n const { node } = callee;\n if (node.async) {\n if (node.generator) {\n return genericTypeAnnotation(identifier(\"AsyncIterator\"));\n } else {\n return genericTypeAnnotation(identifier(\"Promise\"));\n }\n } else {\n if (node.generator) {\n return genericTypeAnnotation(identifier(\"Iterator\"));\n } else if (callee.node.returnType) {\n return callee.node.returnType;\n } else {\n // todo: get union type of all return arguments\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,EAAA,GAAAC,OAAA;AAsBA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAA4C;EAvB1CG,wBAAwB;EACxBC,uBAAuB;EACvBC,uBAAuB;EACvBC,sBAAsB;EACtBC,sBAAsB;EACtBC,iBAAiB;EACjBC,mBAAmB;EACnBC,qBAAqB;EACrBC,0BAA0B;EAC1BC,qBAAqB;EACrBC,UAAU;EACVC,yBAAyB;EACzBC,oBAAoB;EACpBC,oBAAoB;EACpBC,mBAAmB;EACnBC,mBAAmB;EACnBC,kBAAkB;EAClBC;AAAY,IAAArB,EAAA;AASP,SAASsB,kBAAkBA,CAAA,EAAuC;EACvE,IAAI,CAAC,IAAI,CAACC,GAAG,CAAC,IAAI,CAAC,CAACF,YAAY,CAAC,CAAC,EAAE;EACpC,OAAO,IAAI,CAACE,GAAG,CAAC,MAAM,CAAC,CAACC,iBAAiB,CAAC,CAAC;AAC7C;AAEO,SAASC,kBAAkBA,CAACC,IAA0B,EAAE;EAC7D,OAAOA,IAAI,CAACC,cAAc;AAC5B;AAEAF,kBAAkB,CAACG,WAAW,GAAG,IAAI;AAE9B,SAASC,cAAcA,CAACH,IAAsB,EAAE;EACrD,OAAOA,IAAI,CAACC,cAAc;AAC5B;AAEAE,cAAc,CAACD,WAAW,GAAG,IAAI;AAE1B,SAASE,mBAAmBA,CAAA,EAAwC;EACzE,OAAO,IAAI,CAACP,GAAG,CA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,EAAE;QAClB,OAAO1D,qBAAqB,CAACC,UAAU,CAAC,eAAe,CAAC,CAAC;MAC3D,CAAC,MAAM;QACL,OAAOD,qBAAqB,CAACC,UAAU,CAAC,SAAS,CAAC,CAAC;MACrD;IACF,CAAC,MAAM;MACL,IAAIY,IAAI,CAAC6C,SAAS,EAAE;QAClB,OAAO1D,qBAAqB,CAACC,UAAU,CAAC,UAAU,CAAC,CAAC;MACtD,CAAC,MAAM,IAAIkB,MAAM,CAACN,IAAI,CAAC8C,UAAU,EAAE;QACjC,OAAOxC,MAAM,CAACN,IAAI,CAAC8C,UAAU;MAC/B,CAAC,MAAM,CAEP;IACF;EACF;AACF"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createUnionType = createUnionType;
7
+ var _t = require("@babel/types");
8
+ const {
9
+ createFlowUnionType,
10
+ createTSUnionType,
11
+ createUnionTypeAnnotation,
12
+ isFlowType,
13
+ isTSType
14
+ } = _t;
15
+ function createUnionType(types) {
16
+ {
17
+ if (isFlowType(types[0])) {
18
+ if (createFlowUnionType) {
19
+ return createFlowUnionType(types);
20
+ }
21
+ return createUnionTypeAnnotation(types);
22
+ } else {
23
+ if (createTSUnionType) {
24
+ return createTSUnionType(types);
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","createFlowUnionType","createTSUnionType","createUnionTypeAnnotation","isFlowType","isTSType","createUnionType","types"],"sources":["../../../src/path/inference/util.ts"],"sourcesContent":["import {\n createFlowUnionType,\n createTSUnionType,\n createUnionTypeAnnotation,\n isFlowType,\n isTSType,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nexport function createUnionType(\n types: Array<t.FlowType | t.TSType>,\n): t.FlowType | t.TSType {\n if (process.env.BABEL_8_BREAKING) {\n if (isFlowType(types[0])) {\n return createFlowUnionType(types as t.FlowType[]);\n }\n if (isTSType(types[0])) {\n return createTSUnionType(types as t.TSType[]);\n }\n } else {\n if (isFlowType(types[0])) {\n if (createFlowUnionType) {\n return createFlowUnionType(types as t.FlowType[]);\n }\n\n return createUnionTypeAnnotation(types as t.FlowType[]);\n } else {\n if (createTSUnionType) {\n return createTSUnionType(types as t.TSType[]);\n }\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,EAAA,GAAAC,OAAA;AAMsB;EALpBC,mBAAmB;EACnBC,iBAAiB;EACjBC,yBAAyB;EACzBC,UAAU;EACVC;AAAQ,IAAAN,EAAA;AAIH,SAASO,eAAeA,CAC7BC,KAAmC,EACZ;EAQhB;IACL,IAAIH,UAAU,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MACxB,IAAIN,mBAAmB,EAAE;QACvB,OAAOA,mBAAmB,CAACM,KAAqB,CAAC;MACnD;MAEA,OAAOJ,yBAAyB,CAACI,KAAqB,CAAC;IACzD,CAAC,MAAM;MACL,IAAIL,iBAAiB,EAAE;QACrB,OAAOA,iBAAiB,CAACK,KAAmB,CAAC;MAC/C;IACF;EACF;AACF"}