source: imaps-frontend/node_modules/@babel/traverse/lib/path/inference/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: 4.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports._getTypeAnnotation = _getTypeAnnotation;
7exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
8exports.couldBeBaseType = couldBeBaseType;
9exports.getTypeAnnotation = getTypeAnnotation;
10exports.isBaseType = isBaseType;
11exports.isGenericType = isGenericType;
12var inferers = require("./inferers.js");
13var _t = require("@babel/types");
14const {
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;
36function 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}
48const typeAnnotationInferringNodes = new WeakSet();
49function _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}
87function isBaseType(baseName, soft) {
88 return _isBaseType(baseName, this.getTypeAnnotation(), soft);
89}
90function _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}
113function 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}
127function 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}
135function 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
Note: See TracBrowser for help on using the repository browser.