@babel/traverse 8.0.0-alpha.2 → 8.0.0-alpha.3

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 (59) hide show
  1. package/lib/index.js +132 -130
  2. package/lib/index.js.map +1 -1
  3. package/package.json +11 -11
  4. package/lib/cache.js +0 -28
  5. package/lib/cache.js.map +0 -1
  6. package/lib/context.js +0 -108
  7. package/lib/context.js.map +0 -1
  8. package/lib/hub.js +0 -12
  9. package/lib/hub.js.map +0 -1
  10. package/lib/path/ancestry.js +0 -126
  11. package/lib/path/ancestry.js.map +0 -1
  12. package/lib/path/comments.js +0 -46
  13. package/lib/path/comments.js.map +0 -1
  14. package/lib/path/context.js +0 -194
  15. package/lib/path/context.js.map +0 -1
  16. package/lib/path/conversion.js +0 -453
  17. package/lib/path/conversion.js.map +0 -1
  18. package/lib/path/evaluation.js +0 -333
  19. package/lib/path/evaluation.js.map +0 -1
  20. package/lib/path/family.js +0 -322
  21. package/lib/path/family.js.map +0 -1
  22. package/lib/path/index.js +0 -181
  23. package/lib/path/index.js.map +0 -1
  24. package/lib/path/inference/index.js +0 -137
  25. package/lib/path/inference/index.js.map +0 -1
  26. package/lib/path/inference/inferer-reference.js +0 -145
  27. package/lib/path/inference/inferer-reference.js.map +0 -1
  28. package/lib/path/inference/inferers.js +0 -172
  29. package/lib/path/inference/inferers.js.map +0 -1
  30. package/lib/path/inference/util.js +0 -20
  31. package/lib/path/inference/util.js.map +0 -1
  32. package/lib/path/introspection.js +0 -360
  33. package/lib/path/introspection.js.map +0 -1
  34. package/lib/path/lib/hoister.js +0 -164
  35. package/lib/path/lib/hoister.js.map +0 -1
  36. package/lib/path/lib/removal-hooks.js +0 -31
  37. package/lib/path/lib/removal-hooks.js.map +0 -1
  38. package/lib/path/lib/virtual-types-validator.js +0 -133
  39. package/lib/path/lib/virtual-types-validator.js.map +0 -1
  40. package/lib/path/lib/virtual-types.js +0 -20
  41. package/lib/path/lib/virtual-types.js.map +0 -1
  42. package/lib/path/modification.js +0 -209
  43. package/lib/path/modification.js.map +0 -1
  44. package/lib/path/removal.js +0 -48
  45. package/lib/path/removal.js.map +0 -1
  46. package/lib/path/replacement.js +0 -192
  47. package/lib/path/replacement.js.map +0 -1
  48. package/lib/scope/binding.js +0 -78
  49. package/lib/scope/binding.js.map +0 -1
  50. package/lib/scope/index.js +0 -870
  51. package/lib/scope/index.js.map +0 -1
  52. package/lib/scope/lib/renamer.js +0 -105
  53. package/lib/scope/lib/renamer.js.map +0 -1
  54. package/lib/traverse-node.js +0 -23
  55. package/lib/traverse-node.js.map +0 -1
  56. package/lib/types.js +0 -3
  57. package/lib/types.js.map +0 -1
  58. package/lib/visitors.js +0 -210
  59. package/lib/visitors.js.map +0 -1
@@ -1,137 +0,0 @@
1
- import * as inferers from "./inferers.js";
2
- import * as _t from "@babel/types";
3
- const {
4
- anyTypeAnnotation,
5
- isAnyTypeAnnotation,
6
- isArrayTypeAnnotation,
7
- isBooleanTypeAnnotation,
8
- isEmptyTypeAnnotation,
9
- isFlowBaseAnnotation,
10
- isGenericTypeAnnotation,
11
- isIdentifier,
12
- isMixedTypeAnnotation,
13
- isNumberTypeAnnotation,
14
- isStringTypeAnnotation,
15
- isTSArrayType,
16
- isTSTypeAnnotation,
17
- isTSTypeReference,
18
- isTupleTypeAnnotation,
19
- isTypeAnnotation,
20
- isUnionTypeAnnotation,
21
- isVoidTypeAnnotation,
22
- stringTypeAnnotation,
23
- voidTypeAnnotation
24
- } = _t;
25
- export function getTypeAnnotation() {
26
- let type = this.getData("typeAnnotation");
27
- if (type != null) {
28
- return type;
29
- }
30
- type = this._getTypeAnnotation() || anyTypeAnnotation();
31
- if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
32
- type = type.typeAnnotation;
33
- }
34
- this.setData("typeAnnotation", type);
35
- return type;
36
- }
37
- const typeAnnotationInferringNodes = new WeakSet();
38
- export function _getTypeAnnotation() {
39
- const node = this.node;
40
- if (!node) {
41
- if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
42
- const declar = this.parentPath.parentPath;
43
- const declarParent = declar.parentPath;
44
- if (declar.key === "left" && declarParent.isForInStatement()) {
45
- return stringTypeAnnotation();
46
- }
47
- if (declar.key === "left" && declarParent.isForOfStatement()) {
48
- return anyTypeAnnotation();
49
- }
50
- return voidTypeAnnotation();
51
- } else {
52
- return;
53
- }
54
- }
55
- if (node.typeAnnotation) {
56
- return node.typeAnnotation;
57
- }
58
- if (typeAnnotationInferringNodes.has(node)) {
59
- return;
60
- }
61
- typeAnnotationInferringNodes.add(node);
62
- try {
63
- let inferer = inferers[node.type];
64
- if (inferer) {
65
- return inferer.call(this, node);
66
- }
67
- inferer = inferers[this.parentPath.type];
68
- if (inferer?.validParent) {
69
- return this.parentPath.getTypeAnnotation();
70
- }
71
- } finally {
72
- typeAnnotationInferringNodes.delete(node);
73
- }
74
- }
75
- export function isBaseType(baseName, soft) {
76
- return _isBaseType(baseName, this.getTypeAnnotation(), soft);
77
- }
78
- function _isBaseType(baseName, type, soft) {
79
- if (baseName === "string") {
80
- return isStringTypeAnnotation(type);
81
- } else if (baseName === "number") {
82
- return isNumberTypeAnnotation(type);
83
- } else if (baseName === "boolean") {
84
- return isBooleanTypeAnnotation(type);
85
- } else if (baseName === "any") {
86
- return isAnyTypeAnnotation(type);
87
- } else if (baseName === "mixed") {
88
- return isMixedTypeAnnotation(type);
89
- } else if (baseName === "empty") {
90
- return isEmptyTypeAnnotation(type);
91
- } else if (baseName === "void") {
92
- return isVoidTypeAnnotation(type);
93
- } else {
94
- if (soft) {
95
- return false;
96
- } else {
97
- throw new Error(`Unknown base type ${baseName}`);
98
- }
99
- }
100
- }
101
- export function couldBeBaseType(name) {
102
- const type = this.getTypeAnnotation();
103
- if (isAnyTypeAnnotation(type)) return true;
104
- if (isUnionTypeAnnotation(type)) {
105
- for (const type2 of type.types) {
106
- if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
107
- return true;
108
- }
109
- }
110
- return false;
111
- } else {
112
- return _isBaseType(name, type, true);
113
- }
114
- }
115
- export function baseTypeStrictlyMatches(rightArg) {
116
- const left = this.getTypeAnnotation();
117
- const right = rightArg.getTypeAnnotation();
118
- if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {
119
- return right.type === left.type;
120
- }
121
- return false;
122
- }
123
- export function isGenericType(genericName) {
124
- const type = this.getTypeAnnotation();
125
- if (genericName === "Array") {
126
- if (isTSArrayType(type) || isArrayTypeAnnotation(type) || isTupleTypeAnnotation(type)) {
127
- return true;
128
- }
129
- }
130
- return isGenericTypeAnnotation(type) && isIdentifier(type.id, {
131
- name: genericName
132
- }) || isTSTypeReference(type) && isIdentifier(type.typeName, {
133
- name: genericName
134
- });
135
- }
136
-
137
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["inferers","_t","anyTypeAnnotation","isAnyTypeAnnotation","isArrayTypeAnnotation","isBooleanTypeAnnotation","isEmptyTypeAnnotation","isFlowBaseAnnotation","isGenericTypeAnnotation","isIdentifier","isMixedTypeAnnotation","isNumberTypeAnnotation","isStringTypeAnnotation","isTSArrayType","isTSTypeAnnotation","isTSTypeReference","isTupleTypeAnnotation","isTypeAnnotation","isUnionTypeAnnotation","isVoidTypeAnnotation","stringTypeAnnotation","voidTypeAnnotation","getTypeAnnotation","type","getData","_getTypeAnnotation","typeAnnotation","setData","typeAnnotationInferringNodes","WeakSet","node","key","parentPath","isVariableDeclarator","declar","declarParent","isForInStatement","isForOfStatement","has","add","inferer","call","validParent","delete","isBaseType","baseName","soft","_isBaseType","Error","couldBeBaseType","name","type2","types","baseTypeStrictlyMatches","rightArg","left","right","isGenericType","genericName","id","typeName"],"sources":["../../../src/path/inference/index.ts"],"sourcesContent":["import type NodePath from \"../index\";\nimport * as inferers from \"./inferers\";\nimport {\n anyTypeAnnotation,\n isAnyTypeAnnotation,\n isArrayTypeAnnotation,\n isBooleanTypeAnnotation,\n isEmptyTypeAnnotation,\n isFlowBaseAnnotation,\n isGenericTypeAnnotation,\n isIdentifier,\n isMixedTypeAnnotation,\n isNumberTypeAnnotation,\n isStringTypeAnnotation,\n isTSArrayType,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTupleTypeAnnotation,\n isTypeAnnotation,\n isUnionTypeAnnotation,\n isVoidTypeAnnotation,\n stringTypeAnnotation,\n voidTypeAnnotation,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Infer the type of the current `NodePath`.\n */\n\nexport function getTypeAnnotation(this: NodePath): t.FlowType | t.TSType {\n let type = this.getData(\"typeAnnotation\");\n if (type != null) {\n return type;\n }\n type = this._getTypeAnnotation() || anyTypeAnnotation();\n if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {\n type = type.typeAnnotation;\n }\n this.setData(\"typeAnnotation\", type);\n return type;\n}\n\n// Used to avoid infinite recursion in cases like\n// var b, c; if (0) { c = 1; b = c; } c = b;\n// It also works with indirect recursion.\nconst typeAnnotationInferringNodes = new WeakSet();\n\n/**\n * todo: split up this method\n */\n\nexport function _getTypeAnnotation(this: NodePath): any {\n const node = this.node;\n\n if (!node) {\n // handle initializerless variables, add in checks for loop initializers too\n if (this.key === \"init\" && this.parentPath.isVariableDeclarator()) {\n const declar = this.parentPath.parentPath;\n const declarParent = declar.parentPath;\n\n // for (let NODE in bar) {}\n if (declar.key === \"left\" && declarParent.isForInStatement()) {\n return stringTypeAnnotation();\n }\n\n // for (let NODE of bar) {}\n if (declar.key === \"left\" && declarParent.isForOfStatement()) {\n return anyTypeAnnotation();\n }\n\n return voidTypeAnnotation();\n } else {\n return;\n }\n }\n\n // @ts-expect-error typeAnnotation may not index node\n if (node.typeAnnotation) {\n // @ts-expect-error typeAnnotation may not index node\n return node.typeAnnotation;\n }\n\n if (typeAnnotationInferringNodes.has(node)) {\n // Bail out from type inference to avoid infinite loops\n return;\n }\n typeAnnotationInferringNodes.add(node);\n\n try {\n let inferer =\n // @ts-expect-error inferers do not cover all AST types\n inferers[node.type];\n if (inferer) {\n return inferer.call(this, node);\n }\n\n // @ts-expect-error inferers do not cover all AST types\n inferer = inferers[this.parentPath.type];\n if (inferer?.validParent) {\n return this.parentPath.getTypeAnnotation();\n }\n } finally {\n typeAnnotationInferringNodes.delete(node);\n }\n}\n\nexport function isBaseType(\n this: NodePath,\n baseName: string,\n soft?: boolean,\n): boolean {\n return _isBaseType(baseName, this.getTypeAnnotation(), soft);\n}\n\nfunction _isBaseType(\n baseName: string,\n type?: t.FlowType | t.TSType,\n soft?: boolean,\n): boolean {\n if (baseName === \"string\") {\n return isStringTypeAnnotation(type);\n } else if (baseName === \"number\") {\n return isNumberTypeAnnotation(type);\n } else if (baseName === \"boolean\") {\n return isBooleanTypeAnnotation(type);\n } else if (baseName === \"any\") {\n return isAnyTypeAnnotation(type);\n } else if (baseName === \"mixed\") {\n return isMixedTypeAnnotation(type);\n } else if (baseName === \"empty\") {\n return isEmptyTypeAnnotation(type);\n } else if (baseName === \"void\") {\n return isVoidTypeAnnotation(type);\n } else {\n if (soft) {\n return false;\n } else {\n throw new Error(`Unknown base type ${baseName}`);\n }\n }\n}\n\nexport function couldBeBaseType(this: NodePath, name: string): boolean {\n const type = this.getTypeAnnotation();\n if (isAnyTypeAnnotation(type)) return true;\n\n if (isUnionTypeAnnotation(type)) {\n for (const type2 of type.types) {\n if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {\n return true;\n }\n }\n return false;\n } else {\n return _isBaseType(name, type, true);\n }\n}\n\nexport function baseTypeStrictlyMatches(\n this: NodePath,\n rightArg: NodePath,\n): boolean {\n const left = this.getTypeAnnotation();\n const right = rightArg.getTypeAnnotation();\n\n if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {\n return right.type === left.type;\n }\n return false;\n}\n\nexport function isGenericType(this: NodePath, genericName: string): boolean {\n const type = this.getTypeAnnotation();\n if (genericName === \"Array\") {\n // T[]\n if (\n isTSArrayType(type) ||\n isArrayTypeAnnotation(type) ||\n isTupleTypeAnnotation(type)\n ) {\n return true;\n }\n }\n return (\n (isGenericTypeAnnotation(type) &&\n isIdentifier(type.id, {\n name: genericName,\n })) ||\n (isTSTypeReference(type) &&\n isIdentifier(type.typeName, {\n name: genericName,\n }))\n );\n}\n"],"mappings":"AACA,OAAO,KAAKA,QAAQ,MAAM,eAAY;AACtC,YAAAC,EAAA,MAqBO,cAAc;AAAC;EApBpBC,iBAAiB;EACjBC,mBAAmB;EACnBC,qBAAqB;EACrBC,uBAAuB;EACvBC,qBAAqB;EACrBC,oBAAoB;EACpBC,uBAAuB;EACvBC,YAAY;EACZC,qBAAqB;EACrBC,sBAAsB;EACtBC,sBAAsB;EACtBC,aAAa;EACbC,kBAAkB;EAClBC,iBAAiB;EACjBC,qBAAqB;EACrBC,gBAAgB;EAChBC,qBAAqB;EACrBC,oBAAoB;EACpBC,oBAAoB;EACpBC;AAAkB,IAAApB,EAAA;AAQpB,OAAO,SAASqB,iBAAiBA,CAAA,EAAwC;EACvE,IAAIC,IAAI,GAAG,IAAI,CAACC,OAAO,CAAC,gBAAgB,CAAC;EACzC,IAAID,IAAI,IAAI,IAAI,EAAE;IAChB,OAAOA,IAAI;EACb;EACAA,IAAI,GAAG,IAAI,CAACE,kBAAkB,CAAC,CAAC,IAAIvB,iBAAiB,CAAC,CAAC;EACvD,IAAIe,gBAAgB,CAACM,IAAI,CAAC,IAAIT,kBAAkB,CAACS,IAAI,CAAC,EAAE;IACtDA,IAAI,GAAGA,IAAI,CAACG,cAAc;EAC5B;EACA,IAAI,CAACC,OAAO,CAAC,gBAAgB,EAAEJ,IAAI,CAAC;EACpC,OAAOA,IAAI;AACb;AAKA,MAAMK,4BAA4B,GAAG,IAAIC,OAAO,CAAC,CAAC;AAMlD,OAAO,SAASJ,kBAAkBA,CAAA,EAAsB;EACtD,MAAMK,IAAI,GAAG,IAAI,CAACA,IAAI;EAEtB,IAAI,CAACA,IAAI,EAAE;IAET,IAAI,IAAI,CAACC,GAAG,KAAK,MAA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AAI,EAAEC,KAAK,EAAE,IAAI,CAAC,EAAE;QAChE,OAAO,IAAI;MACb;IACF;IACA,OAAO,KAAK;EACd,CAAC,MAAM;IACL,OAAOJ,WAAW,CAACG,IAAI,EAAE3B,IAAI,EAAE,IAAI,CAAC;EACtC;AACF;AAEA,OAAO,SAAS8B,uBAAuBA,CAErCC,QAAkB,EACT;EACT,MAAMC,IAAI,GAAG,IAAI,CAACjC,iBAAiB,CAAC,CAAC;EACrC,MAAMkC,KAAK,GAAGF,QAAQ,CAAChC,iBAAiB,CAAC,CAAC;EAE1C,IAAI,CAACnB,mBAAmB,CAACoD,IAAI,CAAC,IAAIhD,oBAAoB,CAACgD,IAAI,CAAC,EAAE;IAC5D,OAAOC,KAAK,CAACjC,IAAI,KAAKgC,IAAI,CAAChC,IAAI;EACjC;EACA,OAAO,KAAK;AACd;AAEA,OAAO,SAASkC,aAAaA,CAAiBC,WAAmB,EAAW;EAC1E,MAAMnC,IAAI,GAAG,IAAI,CAACD,iBAAiB,CAAC,CAAC;EACrC,IAAIoC,WAAW,KAAK,OAAO,EAAE;IAE3B,IACE7C,aAAa,CAACU,IAAI,CAAC,IACnBnB,qBAAqB,CAACmB,IAAI,CAAC,IAC3BP,qBAAqB,CAACO,IAAI,CAAC,EAC3B;MACA,OAAO,IAAI;IACb;EACF;EACA,OACGf,uBAAuB,CAACe,IAAI,CAAC,IAC5Bd,YAAY,CAACc,IAAI,CAACoC,EAAE,EAAE;IACpBT,IAAI,EAAEQ;EACR,CAAC,CAAC,IACH3C,iBAAiB,CAACQ,IAAI,CAAC,IACtBd,YAAY,CAACc,IAAI,CAACqC,QAAQ,EAAE;IAC1BV,IAAI,EAAEQ;EACR,CAAC,CAAE;AAET"}
@@ -1,145 +0,0 @@
1
- import * as _t from "@babel/types";
2
- const {
3
- BOOLEAN_NUMBER_BINARY_OPERATORS,
4
- createTypeAnnotationBasedOnTypeof,
5
- numberTypeAnnotation,
6
- voidTypeAnnotation
7
- } = _t;
8
- import { createUnionType } from "./util.js";
9
- export default function (node) {
10
- if (!this.isReferenced()) return;
11
- const binding = this.scope.getBinding(node.name);
12
- if (binding) {
13
- if (binding.identifier.typeAnnotation) {
14
- return binding.identifier.typeAnnotation;
15
- } else {
16
- return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
17
- }
18
- }
19
- if (node.name === "undefined") {
20
- return voidTypeAnnotation();
21
- } else if (node.name === "NaN" || node.name === "Infinity") {
22
- return numberTypeAnnotation();
23
- } else if (node.name === "arguments") {}
24
- }
25
- function getTypeAnnotationBindingConstantViolations(binding, path, name) {
26
- const types = [];
27
- const functionConstantViolations = [];
28
- let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
29
- const testType = getConditionalAnnotation(binding, path, name);
30
- if (testType) {
31
- const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
32
- constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
33
- types.push(testType.typeAnnotation);
34
- }
35
- if (constantViolations.length) {
36
- constantViolations.push(...functionConstantViolations);
37
- for (const violation of constantViolations) {
38
- types.push(violation.getTypeAnnotation());
39
- }
40
- }
41
- if (!types.length) {
42
- return;
43
- }
44
- return createUnionType(types);
45
- }
46
- function getConstantViolationsBefore(binding, path, functions) {
47
- const violations = binding.constantViolations.slice();
48
- violations.unshift(binding.path);
49
- return violations.filter(violation => {
50
- violation = violation.resolve();
51
- const status = violation._guessExecutionStatusRelativeTo(path);
52
- if (functions && status === "unknown") functions.push(violation);
53
- return status === "before";
54
- });
55
- }
56
- function inferAnnotationFromBinaryExpression(name, path) {
57
- const operator = path.node.operator;
58
- const right = path.get("right").resolve();
59
- const left = path.get("left").resolve();
60
- let target;
61
- if (left.isIdentifier({
62
- name
63
- })) {
64
- target = right;
65
- } else if (right.isIdentifier({
66
- name
67
- })) {
68
- target = left;
69
- }
70
- if (target) {
71
- if (operator === "===") {
72
- return target.getTypeAnnotation();
73
- }
74
- if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
75
- return numberTypeAnnotation();
76
- }
77
- return;
78
- }
79
- if (operator !== "===" && operator !== "==") return;
80
- let typeofPath;
81
- let typePath;
82
- if (left.isUnaryExpression({
83
- operator: "typeof"
84
- })) {
85
- typeofPath = left;
86
- typePath = right;
87
- } else if (right.isUnaryExpression({
88
- operator: "typeof"
89
- })) {
90
- typeofPath = right;
91
- typePath = left;
92
- }
93
- if (!typeofPath) return;
94
- if (!typeofPath.get("argument").isIdentifier({
95
- name
96
- })) return;
97
- typePath = typePath.resolve();
98
- if (!typePath.isLiteral()) return;
99
- const typeValue = typePath.node.value;
100
- if (typeof typeValue !== "string") return;
101
- return createTypeAnnotationBasedOnTypeof(typeValue);
102
- }
103
- function getParentConditionalPath(binding, path, name) {
104
- let parentPath;
105
- while (parentPath = path.parentPath) {
106
- if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
107
- if (path.key === "test") {
108
- return;
109
- }
110
- return parentPath;
111
- }
112
- if (parentPath.isFunction()) {
113
- if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
114
- }
115
- path = parentPath;
116
- }
117
- }
118
- function getConditionalAnnotation(binding, path, name) {
119
- const ifStatement = getParentConditionalPath(binding, path, name);
120
- if (!ifStatement) return;
121
- const test = ifStatement.get("test");
122
- const paths = [test];
123
- const types = [];
124
- for (let i = 0; i < paths.length; i++) {
125
- const path = paths[i];
126
- if (path.isLogicalExpression()) {
127
- if (path.node.operator === "&&") {
128
- paths.push(path.get("left"));
129
- paths.push(path.get("right"));
130
- }
131
- } else if (path.isBinaryExpression()) {
132
- const type = inferAnnotationFromBinaryExpression(name, path);
133
- if (type) types.push(type);
134
- }
135
- }
136
- if (types.length) {
137
- return {
138
- typeAnnotation: createUnionType(types),
139
- ifStatement
140
- };
141
- }
142
- return getConditionalAnnotation(binding, ifStatement, name);
143
- }
144
-
145
- //# sourceMappingURL=inferer-reference.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_t","BOOLEAN_NUMBER_BINARY_OPERATORS","createTypeAnnotationBasedOnTypeof","numberTypeAnnotation","voidTypeAnnotation","createUnionType","node","isReferenced","binding","scope","getBinding","name","identifier","typeAnnotation","getTypeAnnotationBindingConstantViolations","path","types","functionConstantViolations","constantViolations","getConstantViolationsBefore","testType","getConditionalAnnotation","testConstantViolations","ifStatement","filter","indexOf","push","length","violation","getTypeAnnotation","functions","violations","slice","unshift","resolve","status","_guessExecutionStatusRelativeTo","inferAnnotationFromBinaryExpression","operator","right","get","left","target","isIdentifier","typeofPath","typePath","isUnaryExpression","isLiteral","typeValue","value","getParentConditionalPath","parentPath","isIfStatement","isConditionalExpression","key","isFunction","test","paths","i","isLogicalExpression","isBinaryExpression","type"],"sources":["../../../src/path/inference/inferer-reference.ts"],"sourcesContent":["import type NodePath from \"../index\";\nimport {\n BOOLEAN_NUMBER_BINARY_OPERATORS,\n createTypeAnnotationBasedOnTypeof,\n numberTypeAnnotation,\n voidTypeAnnotation,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type Binding from \"../../scope/binding\";\n\nimport { createUnionType } from \"./util\";\n\nexport default function (this: NodePath<t.Identifier>, node: t.Identifier) {\n if (!this.isReferenced()) return;\n\n // check if a binding exists of this value and if so then return a union type of all\n // possible types that the binding could be\n const binding = this.scope.getBinding(node.name);\n if (binding) {\n if (binding.identifier.typeAnnotation) {\n return binding.identifier.typeAnnotation;\n } else {\n return getTypeAnnotationBindingConstantViolations(\n binding,\n this,\n node.name,\n );\n }\n }\n\n // built-in values\n if (node.name === \"undefined\") {\n return voidTypeAnnotation();\n } else if (node.name === \"NaN\" || node.name === \"Infinity\") {\n return numberTypeAnnotation();\n } else if (node.name === \"arguments\") {\n // todo\n }\n}\n\nfunction getTypeAnnotationBindingConstantViolations(\n binding: Binding,\n path: NodePath<t.Identifier>,\n name: string,\n) {\n const types = [];\n\n const functionConstantViolations: NodePath[] = [];\n let constantViolations = getConstantViolationsBefore(\n binding,\n path,\n functionConstantViolations,\n );\n\n const testType = getConditionalAnnotation(binding, path, name);\n if (testType) {\n const testConstantViolations = getConstantViolationsBefore(\n binding,\n testType.ifStatement,\n );\n\n // remove constant violations observed before the IfStatement\n constantViolations = constantViolations.filter(\n path => testConstantViolations.indexOf(path) < 0,\n );\n\n // clear current types and add in observed test type\n types.push(testType.typeAnnotation);\n }\n\n if (constantViolations.length) {\n // pick one constant from each scope which will represent the last possible\n // control flow path that it could've taken/been\n /* This code is broken for the following problems:\n * It thinks that assignments can only happen in scopes.\n * What about conditionals, if statements without block,\n * or guarded assignments.\n * It also checks to see if one of the assignments is in the\n * same scope and uses that as the only \"violation\". However,\n * the binding is returned by `getConstantViolationsBefore` so we for\n * sure always going to return that as the only \"violation\".\n let rawConstantViolations = constantViolations.reverse();\n let visitedScopes = [];\n constantViolations = [];\n for (let violation of (rawConstantViolations: Array<NodePath>)) {\n let violationScope = violation.scope;\n if (visitedScopes.indexOf(violationScope) >= 0) continue;\n\n visitedScopes.push(violationScope);\n constantViolations.push(violation);\n\n if (violationScope === path.scope) {\n constantViolations = [violation];\n break;\n }\n }*/\n\n // add back on function constant violations since we can't track calls\n constantViolations.push(...functionConstantViolations);\n\n // push on inferred types of violated paths\n for (const violation of constantViolations) {\n types.push(violation.getTypeAnnotation());\n }\n }\n\n if (!types.length) {\n return;\n }\n\n return createUnionType(types);\n}\n\nfunction getConstantViolationsBefore(\n binding: Binding,\n path: NodePath,\n functions?: NodePath[],\n) {\n const violations = binding.constantViolations.slice();\n violations.unshift(binding.path);\n return violations.filter(violation => {\n violation = violation.resolve();\n const status = violation._guessExecutionStatusRelativeTo(path);\n if (functions && status === \"unknown\") functions.push(violation);\n return status === \"before\";\n });\n}\n\nfunction inferAnnotationFromBinaryExpression(\n name: string,\n path: NodePath<t.BinaryExpression>,\n) {\n const operator = path.node.operator;\n\n const right = path.get(\"right\").resolve();\n const left = path.get(\"left\").resolve();\n\n let target;\n if (left.isIdentifier({ name })) {\n target = right;\n } else if (right.isIdentifier({ name })) {\n target = left;\n }\n\n if (target) {\n if (operator === \"===\") {\n return target.getTypeAnnotation();\n }\n if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {\n return numberTypeAnnotation();\n }\n\n return;\n }\n\n if (operator !== \"===\" && operator !== \"==\") return;\n\n //\n let typeofPath: NodePath<t.UnaryExpression>;\n let typePath: NodePath<t.Expression>;\n if (left.isUnaryExpression({ operator: \"typeof\" })) {\n typeofPath = left;\n typePath = right as NodePath<t.Expression>;\n } else if (right.isUnaryExpression({ operator: \"typeof\" })) {\n typeofPath = right;\n typePath = left as NodePath<t.Expression>;\n }\n\n if (!typeofPath) return;\n // and that the argument of the typeof path references us!\n if (!typeofPath.get(\"argument\").isIdentifier({ name })) return;\n\n // ensure that the type path is a Literal\n typePath = typePath.resolve() as NodePath<t.Expression>;\n if (!typePath.isLiteral()) return;\n\n // and that it's a string so we can infer it\n // @ts-expect-error todo(flow->ts): value is not defined for NullLiteral and some other\n const typeValue = typePath.node.value;\n if (typeof typeValue !== \"string\") return;\n\n // turn type value into a type annotation\n // @ts-expect-error todo(flow->ts): move validation from helper or relax type constraint to just a string\n return createTypeAnnotationBasedOnTypeof(typeValue);\n}\n\nfunction getParentConditionalPath(\n binding: Binding,\n path: NodePath,\n name: string,\n) {\n let parentPath;\n while ((parentPath = path.parentPath)) {\n if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {\n if (path.key === \"test\") {\n return;\n }\n\n return parentPath as NodePath<t.IfStatement | t.ConditionalExpression>;\n }\n if (parentPath.isFunction()) {\n if (parentPath.parentPath.scope.getBinding(name) !== binding) return;\n }\n\n path = parentPath;\n }\n}\n\nfunction getConditionalAnnotation<T extends t.Node>(\n binding: Binding,\n path: NodePath<T>,\n name?: string,\n): {\n typeAnnotation: t.FlowType | t.TSType;\n ifStatement: NodePath<t.IfStatement | t.ConditionalExpression>;\n} {\n const ifStatement = getParentConditionalPath(binding, path, name);\n if (!ifStatement) return;\n\n const test = ifStatement.get(\"test\");\n const paths = [test];\n const types = [];\n\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n\n if (path.isLogicalExpression()) {\n if (path.node.operator === \"&&\") {\n paths.push(path.get(\"left\"));\n paths.push(path.get(\"right\"));\n }\n } else if (path.isBinaryExpression()) {\n const type = inferAnnotationFromBinaryExpression(name, path);\n if (type) types.push(type);\n }\n }\n\n if (types.length) {\n return {\n typeAnnotation: createUnionType(types),\n ifStatement,\n };\n }\n\n return getConditionalAnnotation(binding, ifStatement, name);\n}\n"],"mappings":"AACA,YAAAA,EAAA,MAKO,cAAc;AAAC;EAJpBC,+BAA+B;EAC/BC,iCAAiC;EACjCC,oBAAoB;EACpBC;AAAkB,IAAAJ,EAAA;AAKpB,SAASK,eAAe,QAAQ,WAAQ;AAExC,eAAe,UAAwCC,IAAkB,EAAE;EACzE,IAAI,CAAC,IAAI,CAACC,YAAY,CAAC,CAAC,EAAE;EAI1B,MAAMC,OAAO,GAAG,IAAI,CAACC,KAAK,CAACC,UAAU,CAACJ,IAAI,CAACK,IAAI,CAAC;EAChD,IAAIH,OAAO,EAAE;IACX,IAAIA,OAAO,CAACI,UAAU,CAACC,cAAc,EAAE;MACrC,OAAOL,OAAO,CAACI,UAAU,CAACC,cAAc;IAC1C,CAAC,MAAM;MACL,OAAOC,0CAA0C,CAC/CN,OAAO,EACP,IAAI,EACJF,IAAI,CAACK,IACP,CAAC;IACH;EACF;EAGA,IAAIL,IAAI,CAACK,IAAI,KAAK,WAAW,EAAE;IAC7B,OAAOP,kBAAkB,CAAC,CAAC;EAC7B,CAAC,MAAM,IAAIE,IAAI,CAACK,IAAI,KAAK,KAAK,IAAIL,IAAI,CAACK,IAAI,KAAK,UAAU,EAAE;IAC1D,OAAOR,oBAAoB,CAAC,CAAC;EAC/B,CAAC,MAAM,IAAIG,IAAI,CAACK,IAAI,KAAK,WAAW,EAAE,CAEtC;AACF;AAEA,SAASG,0CAA0CA,CACjDN,OAAgB,EAChBO,IAA4B,EAC5BJ,IAAY,EACZ;EACA,MAA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;EACpC,MAAMiB,KAAK,GAAG,CAACD,IAAI,CAAC;EACpB,MAAMxC,KAAK,GAAG,EAAE;EAEhB,KAAK,IAAI0C,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,KAAK,CAAC9B,MAAM,EAAE+B,CAAC,EAAE,EAAE;IACrC,MAAM3C,IAAI,GAAG0C,KAAK,CAACC,CAAC,CAAC;IAErB,IAAI3C,IAAI,CAAC4C,mBAAmB,CAAC,CAAC,EAAE;MAC9B,IAAI5C,IAAI,CAACT,IAAI,CAACgC,QAAQ,KAAK,IAAI,EAAE;QAC/BmB,KAAK,CAAC/B,IAAI,CAACX,IAAI,CAACyB,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5BiB,KAAK,CAAC/B,IAAI,CAACX,IAAI,CAACyB,GAAG,CAAC,OAAO,CAAC,CAAC;MAC/B;IACF,CAAC,MAAM,IAAIzB,IAAI,CAAC6C,kBAAkB,CAAC,CAAC,EAAE;MACpC,MAAMC,IAAI,GAAGxB,mCAAmC,CAAC1B,IAAI,EAAEI,IAAI,CAAC;MAC5D,IAAI8C,IAAI,EAAE7C,KAAK,CAACU,IAAI,CAACmC,IAAI,CAAC;IAC5B;EACF;EAEA,IAAI7C,KAAK,CAACW,MAAM,EAAE;IAChB,OAAO;MACLd,cAAc,EAAER,eAAe,CAACW,KAAK,CAAC;MACtCO;IACF,CAAC;EACH;EAEA,OAAOF,wBAAwB,CAACb,OAAO,EAAEe,WAAW,EAAEZ,IAAI,CAAC;AAC7D"}
@@ -1,172 +0,0 @@
1
- import * as _t from "@babel/types";
2
- const {
3
- BOOLEAN_BINARY_OPERATORS,
4
- BOOLEAN_UNARY_OPERATORS,
5
- NUMBER_BINARY_OPERATORS,
6
- NUMBER_UNARY_OPERATORS,
7
- STRING_UNARY_OPERATORS,
8
- anyTypeAnnotation,
9
- arrayTypeAnnotation,
10
- booleanTypeAnnotation,
11
- buildMatchMemberExpression,
12
- genericTypeAnnotation,
13
- identifier,
14
- nullLiteralTypeAnnotation,
15
- numberTypeAnnotation,
16
- stringTypeAnnotation,
17
- tupleTypeAnnotation,
18
- unionTypeAnnotation,
19
- voidTypeAnnotation,
20
- isIdentifier
21
- } = _t;
22
- export { default as Identifier } from "./inferer-reference.js";
23
- import { createUnionType } from "./util.js";
24
- export function VariableDeclarator() {
25
- if (!this.get("id").isIdentifier()) return;
26
- return this.get("init").getTypeAnnotation();
27
- }
28
- export function TypeCastExpression(node) {
29
- return node.typeAnnotation;
30
- }
31
- TypeCastExpression.validParent = true;
32
- export function TSAsExpression(node) {
33
- return node.typeAnnotation;
34
- }
35
- TSAsExpression.validParent = true;
36
- export function TSNonNullExpression() {
37
- return this.get("expression").getTypeAnnotation();
38
- }
39
- export function NewExpression(node) {
40
- if (node.callee.type === "Identifier") {
41
- return genericTypeAnnotation(node.callee);
42
- }
43
- }
44
- export function TemplateLiteral() {
45
- return stringTypeAnnotation();
46
- }
47
- export function UnaryExpression(node) {
48
- const operator = node.operator;
49
- if (operator === "void") {
50
- return voidTypeAnnotation();
51
- } else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
52
- return numberTypeAnnotation();
53
- } else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
54
- return stringTypeAnnotation();
55
- } else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
56
- return booleanTypeAnnotation();
57
- }
58
- }
59
- export function BinaryExpression(node) {
60
- const operator = node.operator;
61
- if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
62
- return numberTypeAnnotation();
63
- } else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
64
- return booleanTypeAnnotation();
65
- } else if (operator === "+") {
66
- const right = this.get("right");
67
- const left = this.get("left");
68
- if (left.isBaseType("number") && right.isBaseType("number")) {
69
- return numberTypeAnnotation();
70
- } else if (left.isBaseType("string") || right.isBaseType("string")) {
71
- return stringTypeAnnotation();
72
- }
73
- return unionTypeAnnotation([stringTypeAnnotation(), numberTypeAnnotation()]);
74
- }
75
- }
76
- export function LogicalExpression() {
77
- const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
78
- return createUnionType(argumentTypes);
79
- }
80
- export function ConditionalExpression() {
81
- const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
82
- return createUnionType(argumentTypes);
83
- }
84
- export function SequenceExpression() {
85
- return this.get("expressions").pop().getTypeAnnotation();
86
- }
87
- export function ParenthesizedExpression() {
88
- return this.get("expression").getTypeAnnotation();
89
- }
90
- export function AssignmentExpression() {
91
- return this.get("right").getTypeAnnotation();
92
- }
93
- export function UpdateExpression(node) {
94
- const operator = node.operator;
95
- if (operator === "++" || operator === "--") {
96
- return numberTypeAnnotation();
97
- }
98
- }
99
- export function StringLiteral() {
100
- return stringTypeAnnotation();
101
- }
102
- export function NumericLiteral() {
103
- return numberTypeAnnotation();
104
- }
105
- export function BooleanLiteral() {
106
- return booleanTypeAnnotation();
107
- }
108
- export function NullLiteral() {
109
- return nullLiteralTypeAnnotation();
110
- }
111
- export function RegExpLiteral() {
112
- return genericTypeAnnotation(identifier("RegExp"));
113
- }
114
- export function ObjectExpression() {
115
- return genericTypeAnnotation(identifier("Object"));
116
- }
117
- export function ArrayExpression() {
118
- return genericTypeAnnotation(identifier("Array"));
119
- }
120
- export function RestElement() {
121
- return ArrayExpression();
122
- }
123
- RestElement.validParent = true;
124
- function Func() {
125
- return genericTypeAnnotation(identifier("Function"));
126
- }
127
- export { Func as FunctionExpression, Func as ArrowFunctionExpression, Func as FunctionDeclaration, Func as ClassExpression, Func as ClassDeclaration };
128
- const isArrayFrom = buildMatchMemberExpression("Array.from");
129
- const isObjectKeys = buildMatchMemberExpression("Object.keys");
130
- const isObjectValues = buildMatchMemberExpression("Object.values");
131
- const isObjectEntries = buildMatchMemberExpression("Object.entries");
132
- export function CallExpression() {
133
- const {
134
- callee
135
- } = this.node;
136
- if (isObjectKeys(callee)) {
137
- return arrayTypeAnnotation(stringTypeAnnotation());
138
- } else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, {
139
- name: "Array"
140
- })) {
141
- return arrayTypeAnnotation(anyTypeAnnotation());
142
- } else if (isObjectEntries(callee)) {
143
- return arrayTypeAnnotation(tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]));
144
- }
145
- return resolveCall(this.get("callee"));
146
- }
147
- export function TaggedTemplateExpression() {
148
- return resolveCall(this.get("tag"));
149
- }
150
- function resolveCall(callee) {
151
- callee = callee.resolve();
152
- if (callee.isFunction()) {
153
- const {
154
- node
155
- } = callee;
156
- if (node.async) {
157
- if (node.generator) {
158
- return genericTypeAnnotation(identifier("AsyncIterator"));
159
- } else {
160
- return genericTypeAnnotation(identifier("Promise"));
161
- }
162
- } else {
163
- if (node.generator) {
164
- return genericTypeAnnotation(identifier("Iterator"));
165
- } else if (callee.node.returnType) {
166
- return callee.node.returnType;
167
- } else {}
168
- }
169
- }
170
- }
171
-
172
- //# sourceMappingURL=inferers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_t","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","default","Identifier","createUnionType","VariableDeclarator","get","getTypeAnnotation","TypeCastExpression","node","typeAnnotation","validParent","TSAsExpression","TSNonNullExpression","NewExpression","callee","type","TemplateLiteral","UnaryExpression","operator","indexOf","BinaryExpression","right","left","isBaseType","LogicalExpression","argumentTypes","ConditionalExpression","SequenceExpression","pop","ParenthesizedExpression","AssignmentExpression","UpdateExpression","StringLiteral","NumericLiteral","BooleanLiteral","NullLiteral","RegExpLiteral","ObjectExpression","ArrayExpression","RestElement","Func","FunctionExpression","ArrowFunctionExpression","FunctionDeclaration","ClassExpression","ClassDeclaration","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\";\n\nimport { createUnionType } from \"./util\";\nimport type NodePath from \"..\";\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,YAAAA,EAAA,MAmBO,cAAc;AAAC;EAlBpBC,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,IAAAlB,EAAA;AAId,SAASmB,OAAO,IAAIC,UAAU,QAAQ,wBAAqB;AAE3D,SAASC,eAAe,QAAQ,WAAQ;AAGxC,OAAO,SAASC,kBAAkBA,CAAA,EAAuC;EACvE,IAAI,CAAC,IAAI,CAACC,GAAG,CAAC,IAAI,CAAC,CAACL,YAAY,CAAC,CAAC,EAAE;EACpC,OAAO,IAAI,CAACK,GAAG,CAAC,MAAM,CAAC,CAACC,iBAAiB,CAAC,CAAC;AAC7C;AAEA,OAAO,SAASC,kBAAkBA,CAACC,IAA0B,EAAE;EAC7D,OAAOA,IAAI,CAACC,cAAc;AAC5B;AAEAF,kBAAkB,CAACG,WAAW,GAAG,IAAI;AAErC,OAAO,SAASC,cAAcA,CAACH,IAAsB,EAAE;EACrD,OAAOA,IAAI,CAACC,cAAc;AAC5B;AAEAE,cAAc,CAACD,WAAW,GAAG,IAAI;AAEjC,OAAO,SAASE,mBAAmBA,CAAA,EAAwC;E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AC,CAAC;AACrC;AAEA,SAAS+C,WAAWA,CAACtC,MAAgB,EAAE;EACrCA,MAAM,GAAGA,MAAM,CAACwC,OAAO,CAAC,CAAC;EAEzB,IAAIxC,MAAM,CAACyC,UAAU,CAAC,CAAC,EAAE;IACvB,MAAM;MAAE/C;IAAK,CAAC,GAAGM,MAAM;IACvB,IAAIN,IAAI,CAACgD,KAAK,EAAE;MACd,IAAIhD,IAAI,CAACiD,SAAS,EAAE;QAClB,OAAOjE,qBAAqB,CAACC,UAAU,CAAC,eAAe,CAAC,CAAC;MAC3D,CAAC,MAAM;QACL,OAAOD,qBAAqB,CAACC,UAAU,CAAC,SAAS,CAAC,CAAC;MACrD;IACF,CAAC,MAAM;MACL,IAAIe,IAAI,CAACiD,SAAS,EAAE;QAClB,OAAOjE,qBAAqB,CAACC,UAAU,CAAC,UAAU,CAAC,CAAC;MACtD,CAAC,MAAM,IAAIqB,MAAM,CAACN,IAAI,CAACkD,UAAU,EAAE;QACjC,OAAO5C,MAAM,CAACN,IAAI,CAACkD,UAAU;MAC/B,CAAC,MAAM,CAEP;IACF;EACF;AACF"}
@@ -1,20 +0,0 @@
1
- import * as _t from "@babel/types";
2
- const {
3
- createFlowUnionType,
4
- createTSUnionType,
5
- createUnionTypeAnnotation,
6
- isFlowType,
7
- isTSType
8
- } = _t;
9
- export function createUnionType(types) {
10
- {
11
- if (isFlowType(types[0])) {
12
- return createFlowUnionType(types);
13
- }
14
- if (isTSType(types[0])) {
15
- return createTSUnionType(types);
16
- }
17
- }
18
- }
19
-
20
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_t","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,YAAAA,EAAA,MAMO,cAAc;AAAC;EALpBC,mBAAmB;EACnBC,iBAAiB;EACjBC,yBAAyB;EACzBC,UAAU;EACVC;AAAQ,IAAAL,EAAA;AAIV,OAAO,SAASM,eAAeA,CAC7BC,KAAmC,EACZ;EACW;IAChC,IAAIH,UAAU,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MACxB,OAAON,mBAAmB,CAACM,KAAqB,CAAC;IACnD;IACA,IAAIF,QAAQ,CAACE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MACtB,OAAOL,iBAAiB,CAACK,KAAmB,CAAC;IAC/C;EACF;AAaF"}