@tachybase/module-cloud-component 0.23.22 → 0.23.35

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 (48) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +7 -7
  3. package/dist/node_modules/@babel/core/lib/index.js +76 -76
  4. package/dist/node_modules/@babel/core/node_modules/.bin/parser +4 -4
  5. package/dist/node_modules/@babel/core/package.json +1 -1
  6. package/dist/node_modules/@babel/parser/LICENSE +19 -0
  7. package/dist/node_modules/@babel/parser/bin/babel-parser.js +15 -0
  8. package/dist/node_modules/@babel/parser/index.cjs +5 -0
  9. package/dist/node_modules/@babel/parser/lib/index.js +1 -0
  10. package/dist/node_modules/@babel/parser/package.json +1 -0
  11. package/dist/node_modules/@babel/parser/typings/babel-parser.d.ts +267 -0
  12. package/dist/node_modules/@babel/traverse/LICENSE +22 -0
  13. package/dist/node_modules/@babel/traverse/lib/cache.js +44 -0
  14. package/dist/node_modules/@babel/traverse/lib/context.js +119 -0
  15. package/dist/node_modules/@babel/traverse/lib/hub.js +19 -0
  16. package/dist/node_modules/@babel/traverse/lib/index.js +13 -0
  17. package/dist/node_modules/@babel/traverse/lib/path/ancestry.js +141 -0
  18. package/dist/node_modules/@babel/traverse/lib/path/comments.js +52 -0
  19. package/dist/node_modules/@babel/traverse/lib/path/context.js +242 -0
  20. package/dist/node_modules/@babel/traverse/lib/path/conversion.js +609 -0
  21. package/dist/node_modules/@babel/traverse/lib/path/evaluation.js +347 -0
  22. package/dist/node_modules/@babel/traverse/lib/path/family.js +340 -0
  23. package/dist/node_modules/@babel/traverse/lib/path/index.js +292 -0
  24. package/dist/node_modules/@babel/traverse/lib/path/inference/index.js +149 -0
  25. package/dist/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js +151 -0
  26. package/dist/node_modules/@babel/traverse/lib/path/inference/inferers.js +207 -0
  27. package/dist/node_modules/@babel/traverse/lib/path/inference/util.js +30 -0
  28. package/dist/node_modules/@babel/traverse/lib/path/introspection.js +398 -0
  29. package/dist/node_modules/@babel/traverse/lib/path/lib/hoister.js +171 -0
  30. package/dist/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js +37 -0
  31. package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js +163 -0
  32. package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types.js +26 -0
  33. package/dist/node_modules/@babel/traverse/lib/path/modification.js +229 -0
  34. package/dist/node_modules/@babel/traverse/lib/path/removal.js +69 -0
  35. package/dist/node_modules/@babel/traverse/lib/path/replacement.js +263 -0
  36. package/dist/node_modules/@babel/traverse/lib/scope/binding.js +83 -0
  37. package/dist/node_modules/@babel/traverse/lib/scope/index.js +981 -0
  38. package/dist/node_modules/@babel/traverse/lib/scope/lib/renamer.js +131 -0
  39. package/dist/node_modules/@babel/traverse/lib/traverse-node.js +29 -0
  40. package/dist/node_modules/@babel/traverse/lib/types.js +3 -0
  41. package/dist/node_modules/@babel/traverse/lib/visitors.js +258 -0
  42. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser +17 -0
  43. package/dist/node_modules/@babel/traverse/package.json +1 -0
  44. package/dist/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  45. package/dist/node_modules/@hapi/topo/lib/index.js +1 -0
  46. package/dist/node_modules/@hapi/topo/package.json +1 -0
  47. package/dist/server/services/cloud-libraries-service.js +36 -1
  48. package/package.json +13 -9
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0;
7
+ var virtualTypes = require("./lib/virtual-types.js");
8
+ var _debug = require("debug");
9
+ var _index = require("../index.js");
10
+ var _index2 = require("../scope/index.js");
11
+ var _t = require("@babel/types");
12
+ var t = _t;
13
+ var cache = require("../cache.js");
14
+ var _generator = require("@babel/generator");
15
+ var NodePath_ancestry = require("./ancestry.js");
16
+ var NodePath_inference = require("./inference/index.js");
17
+ var NodePath_replacement = require("./replacement.js");
18
+ var NodePath_evaluation = require("./evaluation.js");
19
+ var NodePath_conversion = require("./conversion.js");
20
+ var NodePath_introspection = require("./introspection.js");
21
+ var _context = require("./context.js");
22
+ var NodePath_context = _context;
23
+ var NodePath_removal = require("./removal.js");
24
+ var NodePath_modification = require("./modification.js");
25
+ var NodePath_family = require("./family.js");
26
+ var NodePath_comments = require("./comments.js");
27
+ var NodePath_virtual_types_validator = require("./lib/virtual-types-validator.js");
28
+ const {
29
+ validate
30
+ } = _t;
31
+ const debug = _debug("babel");
32
+ const REMOVED = exports.REMOVED = 1 << 0;
33
+ const SHOULD_STOP = exports.SHOULD_STOP = 1 << 1;
34
+ const SHOULD_SKIP = exports.SHOULD_SKIP = 1 << 2;
35
+ const NodePath_Final = exports.default = class NodePath {
36
+ constructor(hub, parent) {
37
+ this.contexts = [];
38
+ this.state = null;
39
+ this.opts = null;
40
+ this._traverseFlags = 0;
41
+ this.skipKeys = null;
42
+ this.parentPath = null;
43
+ this.container = null;
44
+ this.listKey = null;
45
+ this.key = null;
46
+ this.node = null;
47
+ this.type = null;
48
+ this.parent = parent;
49
+ this.hub = hub;
50
+ this.data = null;
51
+ this.context = null;
52
+ this.scope = null;
53
+ }
54
+ get removed() {
55
+ return (this._traverseFlags & 1) > 0;
56
+ }
57
+ set removed(v) {
58
+ if (v) this._traverseFlags |= 1;else this._traverseFlags &= -2;
59
+ }
60
+ get shouldStop() {
61
+ return (this._traverseFlags & 2) > 0;
62
+ }
63
+ set shouldStop(v) {
64
+ if (v) this._traverseFlags |= 2;else this._traverseFlags &= -3;
65
+ }
66
+ get shouldSkip() {
67
+ return (this._traverseFlags & 4) > 0;
68
+ }
69
+ set shouldSkip(v) {
70
+ if (v) this._traverseFlags |= 4;else this._traverseFlags &= -5;
71
+ }
72
+ static get({
73
+ hub,
74
+ parentPath,
75
+ parent,
76
+ container,
77
+ listKey,
78
+ key
79
+ }) {
80
+ if (!hub && parentPath) {
81
+ hub = parentPath.hub;
82
+ }
83
+ if (!parent) {
84
+ throw new Error("To get a node path the parent needs to exist");
85
+ }
86
+ const targetNode = container[key];
87
+ const paths = cache.getOrCreateCachedPaths(hub, parent);
88
+ let path = paths.get(targetNode);
89
+ if (!path) {
90
+ path = new NodePath(hub, parent);
91
+ if (targetNode) paths.set(targetNode, path);
92
+ }
93
+ _context.setup.call(path, parentPath, container, listKey, key);
94
+ return path;
95
+ }
96
+ getScope(scope) {
97
+ return this.isScope() ? new _index2.default(this) : scope;
98
+ }
99
+ setData(key, val) {
100
+ if (this.data == null) {
101
+ this.data = Object.create(null);
102
+ }
103
+ return this.data[key] = val;
104
+ }
105
+ getData(key, def) {
106
+ if (this.data == null) {
107
+ this.data = Object.create(null);
108
+ }
109
+ let val = this.data[key];
110
+ if (val === undefined && def !== undefined) val = this.data[key] = def;
111
+ return val;
112
+ }
113
+ hasNode() {
114
+ return this.node != null;
115
+ }
116
+ buildCodeFrameError(msg, Error = SyntaxError) {
117
+ return this.hub.buildError(this.node, msg, Error);
118
+ }
119
+ traverse(visitor, state) {
120
+ (0, _index.default)(this.node, visitor, this.scope, state, this);
121
+ }
122
+ set(key, node) {
123
+ validate(this.node, key, node);
124
+ this.node[key] = node;
125
+ }
126
+ getPathLocation() {
127
+ const parts = [];
128
+ let path = this;
129
+ do {
130
+ let key = path.key;
131
+ if (path.inList) key = `${path.listKey}[${key}]`;
132
+ parts.unshift(key);
133
+ } while (path = path.parentPath);
134
+ return parts.join(".");
135
+ }
136
+ debug(message) {
137
+ if (!debug.enabled) return;
138
+ debug(`${this.getPathLocation()} ${this.type}: ${message}`);
139
+ }
140
+ toString() {
141
+ return (0, _generator.default)(this.node).code;
142
+ }
143
+ get inList() {
144
+ return !!this.listKey;
145
+ }
146
+ set inList(inList) {
147
+ if (!inList) {
148
+ this.listKey = null;
149
+ }
150
+ }
151
+ get parentKey() {
152
+ return this.listKey || this.key;
153
+ }
154
+ };
155
+ const methods = {
156
+ findParent: NodePath_ancestry.findParent,
157
+ find: NodePath_ancestry.find,
158
+ getFunctionParent: NodePath_ancestry.getFunctionParent,
159
+ getStatementParent: NodePath_ancestry.getStatementParent,
160
+ getEarliestCommonAncestorFrom: NodePath_ancestry.getEarliestCommonAncestorFrom,
161
+ getDeepestCommonAncestorFrom: NodePath_ancestry.getDeepestCommonAncestorFrom,
162
+ getAncestry: NodePath_ancestry.getAncestry,
163
+ isAncestor: NodePath_ancestry.isAncestor,
164
+ isDescendant: NodePath_ancestry.isDescendant,
165
+ inType: NodePath_ancestry.inType,
166
+ getTypeAnnotation: NodePath_inference.getTypeAnnotation,
167
+ isBaseType: NodePath_inference.isBaseType,
168
+ couldBeBaseType: NodePath_inference.couldBeBaseType,
169
+ baseTypeStrictlyMatches: NodePath_inference.baseTypeStrictlyMatches,
170
+ isGenericType: NodePath_inference.isGenericType,
171
+ replaceWithMultiple: NodePath_replacement.replaceWithMultiple,
172
+ replaceWithSourceString: NodePath_replacement.replaceWithSourceString,
173
+ replaceWith: NodePath_replacement.replaceWith,
174
+ replaceExpressionWithStatements: NodePath_replacement.replaceExpressionWithStatements,
175
+ replaceInline: NodePath_replacement.replaceInline,
176
+ evaluateTruthy: NodePath_evaluation.evaluateTruthy,
177
+ evaluate: NodePath_evaluation.evaluate,
178
+ toComputedKey: NodePath_conversion.toComputedKey,
179
+ ensureBlock: NodePath_conversion.ensureBlock,
180
+ unwrapFunctionEnvironment: NodePath_conversion.unwrapFunctionEnvironment,
181
+ arrowFunctionToExpression: NodePath_conversion.arrowFunctionToExpression,
182
+ splitExportDeclaration: NodePath_conversion.splitExportDeclaration,
183
+ ensureFunctionName: NodePath_conversion.ensureFunctionName,
184
+ matchesPattern: NodePath_introspection.matchesPattern,
185
+ isStatic: NodePath_introspection.isStatic,
186
+ isNodeType: NodePath_introspection.isNodeType,
187
+ canHaveVariableDeclarationOrExpression: NodePath_introspection.canHaveVariableDeclarationOrExpression,
188
+ canSwapBetweenExpressionAndStatement: NodePath_introspection.canSwapBetweenExpressionAndStatement,
189
+ isCompletionRecord: NodePath_introspection.isCompletionRecord,
190
+ isStatementOrBlock: NodePath_introspection.isStatementOrBlock,
191
+ referencesImport: NodePath_introspection.referencesImport,
192
+ getSource: NodePath_introspection.getSource,
193
+ willIMaybeExecuteBefore: NodePath_introspection.willIMaybeExecuteBefore,
194
+ _guessExecutionStatusRelativeTo: NodePath_introspection._guessExecutionStatusRelativeTo,
195
+ resolve: NodePath_introspection.resolve,
196
+ isConstantExpression: NodePath_introspection.isConstantExpression,
197
+ isInStrictMode: NodePath_introspection.isInStrictMode,
198
+ isDenylisted: NodePath_context.isDenylisted,
199
+ visit: NodePath_context.visit,
200
+ skip: NodePath_context.skip,
201
+ skipKey: NodePath_context.skipKey,
202
+ stop: NodePath_context.stop,
203
+ setContext: NodePath_context.setContext,
204
+ requeue: NodePath_context.requeue,
205
+ requeueComputedKeyAndDecorators: NodePath_context.requeueComputedKeyAndDecorators,
206
+ remove: NodePath_removal.remove,
207
+ insertBefore: NodePath_modification.insertBefore,
208
+ insertAfter: NodePath_modification.insertAfter,
209
+ unshiftContainer: NodePath_modification.unshiftContainer,
210
+ pushContainer: NodePath_modification.pushContainer,
211
+ getOpposite: NodePath_family.getOpposite,
212
+ getCompletionRecords: NodePath_family.getCompletionRecords,
213
+ getSibling: NodePath_family.getSibling,
214
+ getPrevSibling: NodePath_family.getPrevSibling,
215
+ getNextSibling: NodePath_family.getNextSibling,
216
+ getAllNextSiblings: NodePath_family.getAllNextSiblings,
217
+ getAllPrevSiblings: NodePath_family.getAllPrevSiblings,
218
+ get: NodePath_family.get,
219
+ getAssignmentIdentifiers: NodePath_family.getAssignmentIdentifiers,
220
+ getBindingIdentifiers: NodePath_family.getBindingIdentifiers,
221
+ getOuterBindingIdentifiers: NodePath_family.getOuterBindingIdentifiers,
222
+ getBindingIdentifierPaths: NodePath_family.getBindingIdentifierPaths,
223
+ getOuterBindingIdentifierPaths: NodePath_family.getOuterBindingIdentifierPaths,
224
+ shareCommentsWithSiblings: NodePath_comments.shareCommentsWithSiblings,
225
+ addComment: NodePath_comments.addComment,
226
+ addComments: NodePath_comments.addComments
227
+ };
228
+ Object.assign(NodePath_Final.prototype, methods);
229
+ {
230
+ NodePath_Final.prototype.arrowFunctionToShadowed = NodePath_conversion[String("arrowFunctionToShadowed")];
231
+ Object.assign(NodePath_Final.prototype, {
232
+ has: NodePath_introspection[String("has")],
233
+ is: NodePath_introspection[String("is")],
234
+ isnt: NodePath_introspection[String("isnt")],
235
+ equals: NodePath_introspection[String("equals")],
236
+ hoist: NodePath_modification[String("hoist")],
237
+ updateSiblingKeys: NodePath_modification.updateSiblingKeys,
238
+ call: NodePath_context.call,
239
+ isBlacklisted: NodePath_context[String("isBlacklisted")],
240
+ setScope: NodePath_context.setScope,
241
+ resync: NodePath_context.resync,
242
+ popContext: NodePath_context.popContext,
243
+ pushContext: NodePath_context.pushContext,
244
+ setup: NodePath_context.setup,
245
+ setKey: NodePath_context.setKey
246
+ });
247
+ }
248
+ {
249
+ NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
250
+ NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
251
+ Object.assign(NodePath_Final.prototype, {
252
+ _getTypeAnnotation: NodePath_inference._getTypeAnnotation,
253
+ _replaceWith: NodePath_replacement._replaceWith,
254
+ _resolve: NodePath_introspection._resolve,
255
+ _call: NodePath_context._call,
256
+ _resyncParent: NodePath_context._resyncParent,
257
+ _resyncKey: NodePath_context._resyncKey,
258
+ _resyncList: NodePath_context._resyncList,
259
+ _resyncRemoved: NodePath_context._resyncRemoved,
260
+ _getQueueContexts: NodePath_context._getQueueContexts,
261
+ _removeFromScope: NodePath_removal._removeFromScope,
262
+ _callRemovalHooks: NodePath_removal._callRemovalHooks,
263
+ _remove: NodePath_removal._remove,
264
+ _markRemoved: NodePath_removal._markRemoved,
265
+ _assertUnremoved: NodePath_removal._assertUnremoved,
266
+ _containerInsert: NodePath_modification._containerInsert,
267
+ _containerInsertBefore: NodePath_modification._containerInsertBefore,
268
+ _containerInsertAfter: NodePath_modification._containerInsertAfter,
269
+ _verifyNodeList: NodePath_modification._verifyNodeList,
270
+ _getKey: NodePath_family._getKey,
271
+ _getPattern: NodePath_family._getPattern
272
+ });
273
+ }
274
+ for (const type of t.TYPES) {
275
+ const typeKey = `is${type}`;
276
+ const fn = t[typeKey];
277
+ NodePath_Final.prototype[typeKey] = function (opts) {
278
+ return fn(this.node, opts);
279
+ };
280
+ NodePath_Final.prototype[`assert${type}`] = function (opts) {
281
+ if (!fn(this.node, opts)) {
282
+ throw new TypeError(`Expected node path of type ${type}`);
283
+ }
284
+ };
285
+ }
286
+ Object.assign(NodePath_Final.prototype, NodePath_virtual_types_validator);
287
+ for (const type of Object.keys(virtualTypes)) {
288
+ if (type[0] === "_") continue;
289
+ if (!t.TYPES.includes(type)) t.TYPES.push(type);
290
+ }
291
+
292
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getTypeAnnotation = _getTypeAnnotation;
7
+ exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
8
+ exports.couldBeBaseType = couldBeBaseType;
9
+ exports.getTypeAnnotation = getTypeAnnotation;
10
+ exports.isBaseType = isBaseType;
11
+ exports.isGenericType = isGenericType;
12
+ var inferers = require("./inferers.js");
13
+ var _t = require("@babel/types");
14
+ const {
15
+ anyTypeAnnotation,
16
+ isAnyTypeAnnotation,
17
+ isArrayTypeAnnotation,
18
+ isBooleanTypeAnnotation,
19
+ isEmptyTypeAnnotation,
20
+ isFlowBaseAnnotation,
21
+ isGenericTypeAnnotation,
22
+ isIdentifier,
23
+ isMixedTypeAnnotation,
24
+ isNumberTypeAnnotation,
25
+ isStringTypeAnnotation,
26
+ isTSArrayType,
27
+ isTSTypeAnnotation,
28
+ isTSTypeReference,
29
+ isTupleTypeAnnotation,
30
+ isTypeAnnotation,
31
+ isUnionTypeAnnotation,
32
+ isVoidTypeAnnotation,
33
+ stringTypeAnnotation,
34
+ voidTypeAnnotation
35
+ } = _t;
36
+ function getTypeAnnotation() {
37
+ let type = this.getData("typeAnnotation");
38
+ if (type != null) {
39
+ return type;
40
+ }
41
+ type = _getTypeAnnotation.call(this) || anyTypeAnnotation();
42
+ if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
43
+ type = type.typeAnnotation;
44
+ }
45
+ this.setData("typeAnnotation", type);
46
+ return type;
47
+ }
48
+ const typeAnnotationInferringNodes = new WeakSet();
49
+ function _getTypeAnnotation() {
50
+ const node = this.node;
51
+ if (!node) {
52
+ if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
53
+ const declar = this.parentPath.parentPath;
54
+ const declarParent = declar.parentPath;
55
+ if (declar.key === "left" && declarParent.isForInStatement()) {
56
+ return stringTypeAnnotation();
57
+ }
58
+ if (declar.key === "left" && declarParent.isForOfStatement()) {
59
+ return anyTypeAnnotation();
60
+ }
61
+ return voidTypeAnnotation();
62
+ } else {
63
+ return;
64
+ }
65
+ }
66
+ if (node.typeAnnotation) {
67
+ return node.typeAnnotation;
68
+ }
69
+ if (typeAnnotationInferringNodes.has(node)) {
70
+ return;
71
+ }
72
+ typeAnnotationInferringNodes.add(node);
73
+ try {
74
+ var _inferer;
75
+ let inferer = inferers[node.type];
76
+ if (inferer) {
77
+ return inferer.call(this, node);
78
+ }
79
+ inferer = inferers[this.parentPath.type];
80
+ if ((_inferer = inferer) != null && _inferer.validParent) {
81
+ return this.parentPath.getTypeAnnotation();
82
+ }
83
+ } finally {
84
+ typeAnnotationInferringNodes.delete(node);
85
+ }
86
+ }
87
+ function isBaseType(baseName, soft) {
88
+ return _isBaseType(baseName, this.getTypeAnnotation(), soft);
89
+ }
90
+ function _isBaseType(baseName, type, soft) {
91
+ if (baseName === "string") {
92
+ return isStringTypeAnnotation(type);
93
+ } else if (baseName === "number") {
94
+ return isNumberTypeAnnotation(type);
95
+ } else if (baseName === "boolean") {
96
+ return isBooleanTypeAnnotation(type);
97
+ } else if (baseName === "any") {
98
+ return isAnyTypeAnnotation(type);
99
+ } else if (baseName === "mixed") {
100
+ return isMixedTypeAnnotation(type);
101
+ } else if (baseName === "empty") {
102
+ return isEmptyTypeAnnotation(type);
103
+ } else if (baseName === "void") {
104
+ return isVoidTypeAnnotation(type);
105
+ } else {
106
+ if (soft) {
107
+ return false;
108
+ } else {
109
+ throw new Error(`Unknown base type ${baseName}`);
110
+ }
111
+ }
112
+ }
113
+ function couldBeBaseType(name) {
114
+ const type = this.getTypeAnnotation();
115
+ if (isAnyTypeAnnotation(type)) return true;
116
+ if (isUnionTypeAnnotation(type)) {
117
+ for (const type2 of type.types) {
118
+ if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
119
+ return true;
120
+ }
121
+ }
122
+ return false;
123
+ } else {
124
+ return _isBaseType(name, type, true);
125
+ }
126
+ }
127
+ function baseTypeStrictlyMatches(rightArg) {
128
+ const left = this.getTypeAnnotation();
129
+ const right = rightArg.getTypeAnnotation();
130
+ if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {
131
+ return right.type === left.type;
132
+ }
133
+ return false;
134
+ }
135
+ function isGenericType(genericName) {
136
+ const type = this.getTypeAnnotation();
137
+ if (genericName === "Array") {
138
+ if (isTSArrayType(type) || isArrayTypeAnnotation(type) || isTupleTypeAnnotation(type)) {
139
+ return true;
140
+ }
141
+ }
142
+ return isGenericTypeAnnotation(type) && isIdentifier(type.id, {
143
+ name: genericName
144
+ }) || isTSTypeReference(type) && isIdentifier(type.typeName, {
145
+ name: genericName
146
+ });
147
+ }
148
+
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _t = require("@babel/types");
8
+ var _util = require("./util.js");
9
+ const {
10
+ BOOLEAN_NUMBER_BINARY_OPERATORS,
11
+ createTypeAnnotationBasedOnTypeof,
12
+ numberTypeAnnotation,
13
+ voidTypeAnnotation
14
+ } = _t;
15
+ function _default(node) {
16
+ if (!this.isReferenced()) return;
17
+ const binding = this.scope.getBinding(node.name);
18
+ if (binding) {
19
+ if (binding.identifier.typeAnnotation) {
20
+ return binding.identifier.typeAnnotation;
21
+ } else {
22
+ return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
23
+ }
24
+ }
25
+ if (node.name === "undefined") {
26
+ return voidTypeAnnotation();
27
+ } else if (node.name === "NaN" || node.name === "Infinity") {
28
+ return numberTypeAnnotation();
29
+ } else if (node.name === "arguments") {}
30
+ }
31
+ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
32
+ const types = [];
33
+ const functionConstantViolations = [];
34
+ let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
35
+ const testType = getConditionalAnnotation(binding, path, name);
36
+ if (testType) {
37
+ const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
38
+ constantViolations = constantViolations.filter(path => !testConstantViolations.includes(path));
39
+ types.push(testType.typeAnnotation);
40
+ }
41
+ if (constantViolations.length) {
42
+ constantViolations.push(...functionConstantViolations);
43
+ for (const violation of constantViolations) {
44
+ types.push(violation.getTypeAnnotation());
45
+ }
46
+ }
47
+ if (!types.length) {
48
+ return;
49
+ }
50
+ return (0, _util.createUnionType)(types);
51
+ }
52
+ function getConstantViolationsBefore(binding, path, functions) {
53
+ const violations = binding.constantViolations.slice();
54
+ violations.unshift(binding.path);
55
+ return violations.filter(violation => {
56
+ violation = violation.resolve();
57
+ const status = violation._guessExecutionStatusRelativeTo(path);
58
+ if (functions && status === "unknown") functions.push(violation);
59
+ return status === "before";
60
+ });
61
+ }
62
+ function inferAnnotationFromBinaryExpression(name, path) {
63
+ const operator = path.node.operator;
64
+ const right = path.get("right").resolve();
65
+ const left = path.get("left").resolve();
66
+ let target;
67
+ if (left.isIdentifier({
68
+ name
69
+ })) {
70
+ target = right;
71
+ } else if (right.isIdentifier({
72
+ name
73
+ })) {
74
+ target = left;
75
+ }
76
+ if (target) {
77
+ if (operator === "===") {
78
+ return target.getTypeAnnotation();
79
+ }
80
+ if (BOOLEAN_NUMBER_BINARY_OPERATORS.includes(operator)) {
81
+ return numberTypeAnnotation();
82
+ }
83
+ return;
84
+ }
85
+ if (operator !== "===" && operator !== "==") return;
86
+ let typeofPath;
87
+ let typePath;
88
+ if (left.isUnaryExpression({
89
+ operator: "typeof"
90
+ })) {
91
+ typeofPath = left;
92
+ typePath = right;
93
+ } else if (right.isUnaryExpression({
94
+ operator: "typeof"
95
+ })) {
96
+ typeofPath = right;
97
+ typePath = left;
98
+ }
99
+ if (!typeofPath) return;
100
+ if (!typeofPath.get("argument").isIdentifier({
101
+ name
102
+ })) return;
103
+ typePath = typePath.resolve();
104
+ if (!typePath.isLiteral()) return;
105
+ const typeValue = typePath.node.value;
106
+ if (typeof typeValue !== "string") return;
107
+ return createTypeAnnotationBasedOnTypeof(typeValue);
108
+ }
109
+ function getParentConditionalPath(binding, path, name) {
110
+ let parentPath;
111
+ while (parentPath = path.parentPath) {
112
+ if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
113
+ if (path.key === "test") {
114
+ return;
115
+ }
116
+ return parentPath;
117
+ }
118
+ if (parentPath.isFunction()) {
119
+ if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
120
+ }
121
+ path = parentPath;
122
+ }
123
+ }
124
+ function getConditionalAnnotation(binding, path, name) {
125
+ const ifStatement = getParentConditionalPath(binding, path, name);
126
+ if (!ifStatement) return;
127
+ const test = ifStatement.get("test");
128
+ const paths = [test];
129
+ const types = [];
130
+ for (let i = 0; i < paths.length; i++) {
131
+ const path = paths[i];
132
+ if (path.isLogicalExpression()) {
133
+ if (path.node.operator === "&&") {
134
+ paths.push(path.get("left"));
135
+ paths.push(path.get("right"));
136
+ }
137
+ } else if (path.isBinaryExpression()) {
138
+ const type = inferAnnotationFromBinaryExpression(name, path);
139
+ if (type) types.push(type);
140
+ }
141
+ }
142
+ if (types.length) {
143
+ return {
144
+ typeAnnotation: (0, _util.createUnionType)(types),
145
+ ifStatement
146
+ };
147
+ }
148
+ return getConditionalAnnotation(binding, ifStatement, name);
149
+ }
150
+
151
+ //# sourceMappingURL=inferer-reference.js.map