@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
@@ -0,0 +1 @@
1
+ {"version":3,"names":["virtualTypes","require","_debug","_index","_index2","_t","t","cache","_generator","NodePath_ancestry","NodePath_inference","NodePath_replacement","NodePath_evaluation","NodePath_conversion","NodePath_introspection","NodePath_context","NodePath_removal","NodePath_modification","NodePath_family","NodePath_comments","NodePath_virtual_types_validator","validate","debug","buildDebug","REMOVED","exports","SHOULD_STOP","SHOULD_SKIP","NodePath","constructor","hub","parent","contexts","state","opts","_traverseFlags","skipKeys","parentPath","container","listKey","key","node","type","data","context","scope","get","Error","targetNode","paths","getOrCreateCachedPaths","path","set","setup","getScope","isScope","Scope","setData","val","Object","create","getData","def","undefined","hasNode","buildCodeFrameError","msg","SyntaxError","buildError","traverse","visitor","getPathLocation","parts","inList","unshift","join","message","enabled","toString","generator","code","parentKey","shouldSkip","v","shouldStop","removed","assign","prototype","_guessExecutionStatusRelativeToDifferentFunctions","_guessExecutionStatusRelativeTo","TYPES","typeKey","fn","TypeError","keys","includes","push","_default","default"],"sources":["../../src/path/index.ts"],"sourcesContent":["import type { HubInterface } from \"../hub.ts\";\nimport type TraversalContext from \"../context.ts\";\nimport type { ExplodedTraverseOptions } from \"../index.ts\";\nimport * as virtualTypes from \"./lib/virtual-types.ts\";\nimport buildDebug from \"debug\";\nimport traverse from \"../index.ts\";\nimport type { Visitor } from \"../types.ts\";\nimport Scope from \"../scope/index.ts\";\nimport { validate } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport * as cache from \"../cache.ts\";\nimport generator from \"@babel/generator\";\n\n// NodePath is split across many files.\nimport * as NodePath_ancestry from \"./ancestry.ts\";\nimport * as NodePath_inference from \"./inference/index.ts\";\nimport * as NodePath_replacement from \"./replacement.ts\";\nimport * as NodePath_evaluation from \"./evaluation.ts\";\nimport * as NodePath_conversion from \"./conversion.ts\";\nimport * as NodePath_introspection from \"./introspection.ts\";\nimport * as NodePath_context from \"./context.ts\";\nimport * as NodePath_removal from \"./removal.ts\";\nimport * as NodePath_modification from \"./modification.ts\";\nimport * as NodePath_family from \"./family.ts\";\nimport * as NodePath_comments from \"./comments.ts\";\nimport * as NodePath_virtual_types_validator from \"./lib/virtual-types-validator.ts\";\nimport type { NodePathAssertions } from \"./generated/asserts.ts\";\nimport type { NodePathValidators } from \"./generated/validators.ts\";\n\nconst debug = buildDebug(\"babel\");\n\nexport const REMOVED = 1 << 0;\nexport const SHOULD_STOP = 1 << 1;\nexport const SHOULD_SKIP = 1 << 2;\n\nclass NodePath<T extends t.Node = t.Node> {\n constructor(hub: HubInterface, parent: t.ParentMaps[T[\"type\"]]) {\n this.parent = parent;\n this.hub = hub;\n this.data = null;\n\n this.context = null;\n this.scope = null;\n }\n\n declare parent: t.ParentMaps[T[\"type\"]];\n declare hub: HubInterface;\n declare data: Record<string | symbol, unknown>;\n // TraversalContext is configured by setContext\n declare context: TraversalContext;\n declare scope: Scope;\n\n contexts: Array<TraversalContext> = [];\n state: any = null;\n opts: ExplodedTraverseOptions | null = null;\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n _traverseFlags: number = 0;\n skipKeys: Record<string, boolean> | null = null;\n parentPath: t.ParentMaps[T[\"type\"]] extends null\n ? null\n : NodePath<t.ParentMaps[T[\"type\"]]> | null = null;\n container: t.Node | Array<t.Node> | null = null;\n listKey: string | null = null;\n key: string | number | null = null;\n node: T = null;\n type: T[\"type\"] | null = null;\n\n static get({\n hub,\n parentPath,\n parent,\n container,\n listKey,\n key,\n }: {\n hub?: HubInterface;\n parentPath: NodePath | null;\n parent: t.Node;\n container: t.Node | t.Node[];\n listKey?: string;\n key: string | number;\n }): NodePath {\n if (!hub && parentPath) {\n hub = parentPath.hub;\n }\n\n if (!parent) {\n throw new Error(\"To get a node path the parent needs to exist\");\n }\n\n const targetNode =\n // @ts-expect-error key must present in container\n container[key];\n\n const paths = cache.getOrCreateCachedPaths(hub, parent);\n\n let path = paths.get(targetNode);\n if (!path) {\n path = new NodePath(hub, parent);\n if (targetNode) paths.set(targetNode, path);\n }\n\n path.setup(parentPath, container, listKey, key);\n\n return path;\n }\n\n getScope(scope: Scope): Scope {\n return this.isScope() ? new Scope(this) : scope;\n }\n\n setData(key: string | symbol, val: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n return (this.data[key] = val);\n }\n\n getData(key: string | symbol, def?: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n let val = this.data[key];\n if (val === undefined && def !== undefined) val = this.data[key] = def;\n return val;\n }\n\n hasNode(): this is NodePath<NonNullable<this[\"node\"]>> {\n return this.node != null;\n }\n\n buildCodeFrameError(\n msg: string,\n Error: new () => Error = SyntaxError,\n ): Error {\n return this.hub.buildError(this.node, msg, Error);\n }\n\n traverse<T>(visitor: Visitor<T>, state: T): void;\n traverse(visitor: Visitor): void;\n traverse(visitor: any, state?: any) {\n traverse(this.node, visitor, this.scope, state, this);\n }\n\n set(key: string, node: any) {\n validate(this.node, key, node);\n // @ts-expect-error key must present in this.node\n this.node[key] = node;\n }\n\n getPathLocation(): string {\n const parts = [];\n let path: NodePath = this;\n do {\n let key = path.key;\n if (path.inList) key = `${path.listKey}[${key}]`;\n parts.unshift(key);\n } while ((path = path.parentPath));\n return parts.join(\".\");\n }\n\n debug(message: string) {\n if (!debug.enabled) return;\n debug(`${this.getPathLocation()} ${this.type}: ${message}`);\n }\n\n toString() {\n return generator(this.node).code;\n }\n\n get inList() {\n return !!this.listKey;\n }\n\n set inList(inList) {\n if (!inList) {\n this.listKey = null;\n }\n // ignore inList = true as it should depend on `listKey`\n }\n\n get parentKey(): string {\n return (this.listKey || this.key) as string;\n }\n\n get shouldSkip() {\n return !!(this._traverseFlags & SHOULD_SKIP);\n }\n\n set shouldSkip(v) {\n if (v) {\n this._traverseFlags |= SHOULD_SKIP;\n } else {\n this._traverseFlags &= ~SHOULD_SKIP;\n }\n }\n\n get shouldStop() {\n return !!(this._traverseFlags & SHOULD_STOP);\n }\n\n set shouldStop(v) {\n if (v) {\n this._traverseFlags |= SHOULD_STOP;\n } else {\n this._traverseFlags &= ~SHOULD_STOP;\n }\n }\n\n get removed() {\n return !!(this._traverseFlags & REMOVED);\n }\n set removed(v) {\n if (v) {\n this._traverseFlags |= REMOVED;\n } else {\n this._traverseFlags &= ~REMOVED;\n }\n }\n}\n\nObject.assign(\n NodePath.prototype,\n NodePath_ancestry,\n NodePath_inference,\n NodePath_replacement,\n NodePath_evaluation,\n NodePath_conversion,\n NodePath_introspection,\n NodePath_context,\n NodePath_removal,\n NodePath_modification,\n NodePath_family,\n NodePath_comments,\n);\n\nif (!process.env.BABEL_8_BREAKING) {\n // @ts-expect-error The original _guessExecutionStatusRelativeToDifferentFunctions only worked for paths in\n // different functions, but _guessExecutionStatusRelativeTo works as a replacement in those cases.\n NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions =\n NodePath_introspection._guessExecutionStatusRelativeTo;\n}\n\n// we can not use `import { TYPES } from \"@babel/types\"` here\n// because the transformNamedBabelTypesImportToDestructuring plugin in babel.config.js\n// does not offer live bindings for `TYPES`\n// we can change to `import { TYPES }` when we are publishing ES modules only\nfor (const type of t.TYPES) {\n const typeKey = `is${type}`;\n // @ts-expect-error typeKey must present in t\n const fn = t[typeKey];\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[typeKey] = function (opts: any) {\n return fn(this.node, opts);\n };\n\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[`assert${type}`] = function (opts: any) {\n if (!fn(this.node, opts)) {\n throw new TypeError(`Expected node path of type ${type}`);\n }\n };\n}\n\n// Register virtual types validators after base types validators\nObject.assign(NodePath.prototype, NodePath_virtual_types_validator);\n\nfor (const type of Object.keys(virtualTypes) as (keyof typeof virtualTypes)[]) {\n if (type[0] === \"_\") continue;\n if (!t.TYPES.includes(type)) t.TYPES.push(type);\n}\n\ntype NodePathMixins = typeof NodePath_ancestry &\n typeof NodePath_inference &\n typeof NodePath_replacement &\n typeof NodePath_evaluation &\n typeof NodePath_conversion &\n typeof NodePath_introspection &\n typeof NodePath_context &\n typeof NodePath_removal &\n typeof NodePath_modification &\n typeof NodePath_family &\n typeof NodePath_comments;\n\n// @ts-expect-error TS throws because ensureBlock returns the body node path\n// however, we don't use the return value and treat it as a transform and\n// assertion utilities. For better type inference we annotate it as an\n// assertion method\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ninterface NodePath<T>\n extends NodePathAssertions,\n NodePathValidators,\n NodePathMixins {\n /**\n * @see ./conversion.ts for implementation\n */\n ensureBlock<\n T extends\n | t.Loop\n | t.WithStatement\n | t.Function\n | t.LabeledStatement\n | t.CatchClause,\n >(\n this: NodePath<T>,\n ): asserts this is NodePath<T & { body: t.BlockStatement }>;\n}\n\nexport default NodePath;\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,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,EAAC,CAAC,GAAG,UAAUR,IAAS,EAAE;IACzD,IAAI,CAAC0D,EAAE,CAAC,IAAI,CAACnD,IAAI,EAAEP,IAAI,CAAC,EAAE;MACxB,MAAM,IAAI2D,SAAS,CAAE,8BAA6BnD,IAAK,EAAC,CAAC;IAC3D;EACF,CAAC;AACH;AAGAiB,MAAM,CAAC2B,MAAM,CAAC1D,QAAQ,CAAC2D,SAAS,EAAEnE,gCAAgC,CAAC;AAEnE,KAAK,MAAMsB,IAAI,IAAIiB,MAAM,CAACmC,IAAI,CAAC9F,YAAY,CAAC,EAAmC;EAC7E,IAAI0C,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;EACrB,IAAI,CAACpC,CAAC,CAACoF,KAAK,CAACK,QAAQ,CAACrD,IAAI,CAAC,EAAEpC,CAAC,CAACoF,KAAK,CAACM,IAAI,CAACtD,IAAI,CAAC;AACjD;AAAC,IAAAuD,QAAA,GAsCcrE,QAAQ;AAAAH,OAAA,CAAAyE,OAAA,GAAAD,QAAA"}
@@ -9,14 +9,12 @@ exports.couldBeBaseType = couldBeBaseType;
9
9
  exports.getTypeAnnotation = getTypeAnnotation;
10
10
  exports.isBaseType = isBaseType;
11
11
  exports.isGenericType = isGenericType;
12
-
13
- var inferers = require("./inferers");
14
-
12
+ var inferers = require("./inferers.js");
15
13
  var _t = require("@babel/types");
16
-
17
14
  const {
18
15
  anyTypeAnnotation,
19
16
  isAnyTypeAnnotation,
17
+ isArrayTypeAnnotation,
20
18
  isBooleanTypeAnnotation,
21
19
  isEmptyTypeAnnotation,
22
20
  isFlowBaseAnnotation,
@@ -25,65 +23,60 @@ const {
25
23
  isMixedTypeAnnotation,
26
24
  isNumberTypeAnnotation,
27
25
  isStringTypeAnnotation,
26
+ isTSArrayType,
27
+ isTSTypeAnnotation,
28
+ isTSTypeReference,
29
+ isTupleTypeAnnotation,
28
30
  isTypeAnnotation,
29
31
  isUnionTypeAnnotation,
30
32
  isVoidTypeAnnotation,
31
33
  stringTypeAnnotation,
32
34
  voidTypeAnnotation
33
35
  } = _t;
34
-
35
36
  function getTypeAnnotation() {
36
- if (this.typeAnnotation) return this.typeAnnotation;
37
- let type = this._getTypeAnnotation() || anyTypeAnnotation();
38
- if (isTypeAnnotation(type)) type = type.typeAnnotation;
39
- return this.typeAnnotation = type;
37
+ let type = this.getData("typeAnnotation");
38
+ if (type != null) {
39
+ return type;
40
+ }
41
+ type = this._getTypeAnnotation() || anyTypeAnnotation();
42
+ if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
43
+ type = type.typeAnnotation;
44
+ }
45
+ this.setData("typeAnnotation", type);
46
+ return type;
40
47
  }
41
-
42
48
  const typeAnnotationInferringNodes = new WeakSet();
43
-
44
49
  function _getTypeAnnotation() {
45
50
  const node = this.node;
46
-
47
51
  if (!node) {
48
52
  if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
49
53
  const declar = this.parentPath.parentPath;
50
54
  const declarParent = declar.parentPath;
51
-
52
55
  if (declar.key === "left" && declarParent.isForInStatement()) {
53
56
  return stringTypeAnnotation();
54
57
  }
55
-
56
58
  if (declar.key === "left" && declarParent.isForOfStatement()) {
57
59
  return anyTypeAnnotation();
58
60
  }
59
-
60
61
  return voidTypeAnnotation();
61
62
  } else {
62
63
  return;
63
64
  }
64
65
  }
65
-
66
66
  if (node.typeAnnotation) {
67
67
  return node.typeAnnotation;
68
68
  }
69
-
70
69
  if (typeAnnotationInferringNodes.has(node)) {
71
70
  return;
72
71
  }
73
-
74
72
  typeAnnotationInferringNodes.add(node);
75
-
76
73
  try {
77
74
  var _inferer;
78
-
79
75
  let inferer = inferers[node.type];
80
-
81
76
  if (inferer) {
82
77
  return inferer.call(this, node);
83
78
  }
84
-
85
79
  inferer = inferers[this.parentPath.type];
86
-
87
80
  if ((_inferer = inferer) != null && _inferer.validParent) {
88
81
  return this.parentPath.getTypeAnnotation();
89
82
  }
@@ -91,11 +84,9 @@ function _getTypeAnnotation() {
91
84
  typeAnnotationInferringNodes.delete(node);
92
85
  }
93
86
  }
94
-
95
87
  function isBaseType(baseName, soft) {
96
88
  return _isBaseType(baseName, this.getTypeAnnotation(), soft);
97
89
  }
98
-
99
90
  function _isBaseType(baseName, type, soft) {
100
91
  if (baseName === "string") {
101
92
  return isStringTypeAnnotation(type);
@@ -119,38 +110,40 @@ function _isBaseType(baseName, type, soft) {
119
110
  }
120
111
  }
121
112
  }
122
-
123
113
  function couldBeBaseType(name) {
124
114
  const type = this.getTypeAnnotation();
125
115
  if (isAnyTypeAnnotation(type)) return true;
126
-
127
116
  if (isUnionTypeAnnotation(type)) {
128
117
  for (const type2 of type.types) {
129
118
  if (isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
130
119
  return true;
131
120
  }
132
121
  }
133
-
134
122
  return false;
135
123
  } else {
136
124
  return _isBaseType(name, type, true);
137
125
  }
138
126
  }
139
-
140
127
  function baseTypeStrictlyMatches(rightArg) {
141
128
  const left = this.getTypeAnnotation();
142
129
  const right = rightArg.getTypeAnnotation();
143
-
144
130
  if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) {
145
131
  return right.type === left.type;
146
132
  }
147
-
148
133
  return false;
149
134
  }
150
-
151
135
  function isGenericType(genericName) {
152
136
  const type = this.getTypeAnnotation();
137
+ if (genericName === "Array") {
138
+ if (isTSArrayType(type) || isArrayTypeAnnotation(type) || isTupleTypeAnnotation(type)) {
139
+ return true;
140
+ }
141
+ }
153
142
  return isGenericTypeAnnotation(type) && isIdentifier(type.id, {
154
143
  name: genericName
144
+ }) || isTSTypeReference(type) && isIdentifier(type.typeName, {
145
+ name: genericName
155
146
  });
156
- }
147
+ }
148
+
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["inferers","require","_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","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.ts\";\nimport * as inferers from \"./inferers.ts\";\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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAD,OAAA;AAqBsB;EApBpBE,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;AAQb,SAASqB,iBAAiBA,CAAA,EAAwC;EACvE,IAAIC,IAAI,GAAG,IAAI,CAACC,OAAO,CAAC,gBAAgB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AW,KAAK,OAAO,EAAE;IAE3B,IACE9C,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,CAACqC,EAAE,EAAE;IACpBT,IAAI,EAAEQ;EACR,CAAC,CAAC,IACH5C,iBAAiB,CAACQ,IAAI,CAAC,IACtBd,YAAY,CAACc,IAAI,CAACsC,QAAQ,EAAE;IAC1BV,IAAI,EAAEQ;EACR,CAAC,CAAE;AAET"}
@@ -4,24 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  var _t = require("@babel/types");
9
-
8
+ var _util = require("./util.js");
10
9
  const {
11
10
  BOOLEAN_NUMBER_BINARY_OPERATORS,
12
- createFlowUnionType,
13
- createTSUnionType,
14
11
  createTypeAnnotationBasedOnTypeof,
15
- createUnionTypeAnnotation,
16
- isTSTypeAnnotation,
17
12
  numberTypeAnnotation,
18
13
  voidTypeAnnotation
19
14
  } = _t;
20
-
21
15
  function _default(node) {
22
16
  if (!this.isReferenced()) return;
23
17
  const binding = this.scope.getBinding(node.name);
24
-
25
18
  if (binding) {
26
19
  if (binding.identifier.typeAnnotation) {
27
20
  return binding.identifier.typeAnnotation;
@@ -29,68 +22,48 @@ function _default(node) {
29
22
  return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
30
23
  }
31
24
  }
32
-
33
25
  if (node.name === "undefined") {
34
26
  return voidTypeAnnotation();
35
27
  } else if (node.name === "NaN" || node.name === "Infinity") {
36
28
  return numberTypeAnnotation();
37
29
  } else if (node.name === "arguments") {}
38
30
  }
39
-
40
31
  function getTypeAnnotationBindingConstantViolations(binding, path, name) {
41
32
  const types = [];
42
33
  const functionConstantViolations = [];
43
34
  let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
44
35
  const testType = getConditionalAnnotation(binding, path, name);
45
-
46
36
  if (testType) {
47
37
  const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
48
38
  constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
49
39
  types.push(testType.typeAnnotation);
50
40
  }
51
-
52
41
  if (constantViolations.length) {
53
42
  constantViolations.push(...functionConstantViolations);
54
-
55
43
  for (const violation of constantViolations) {
56
44
  types.push(violation.getTypeAnnotation());
57
45
  }
58
46
  }
59
-
60
47
  if (!types.length) {
61
48
  return;
62
49
  }
63
-
64
- if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
65
- return createTSUnionType(types);
66
- }
67
-
68
- if (createFlowUnionType) {
69
- return createFlowUnionType(types);
70
- }
71
-
72
- return createUnionTypeAnnotation(types);
50
+ return (0, _util.createUnionType)(types);
73
51
  }
74
-
75
52
  function getConstantViolationsBefore(binding, path, functions) {
76
53
  const violations = binding.constantViolations.slice();
77
54
  violations.unshift(binding.path);
78
55
  return violations.filter(violation => {
79
56
  violation = violation.resolve();
80
-
81
57
  const status = violation._guessExecutionStatusRelativeTo(path);
82
-
83
58
  if (functions && status === "unknown") functions.push(violation);
84
59
  return status === "before";
85
60
  });
86
61
  }
87
-
88
62
  function inferAnnotationFromBinaryExpression(name, path) {
89
63
  const operator = path.node.operator;
90
64
  const right = path.get("right").resolve();
91
65
  const left = path.get("left").resolve();
92
66
  let target;
93
-
94
67
  if (left.isIdentifier({
95
68
  name
96
69
  })) {
@@ -100,23 +73,18 @@ function inferAnnotationFromBinaryExpression(name, path) {
100
73
  })) {
101
74
  target = left;
102
75
  }
103
-
104
76
  if (target) {
105
77
  if (operator === "===") {
106
78
  return target.getTypeAnnotation();
107
79
  }
108
-
109
80
  if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
110
81
  return numberTypeAnnotation();
111
82
  }
112
-
113
83
  return;
114
84
  }
115
-
116
85
  if (operator !== "===" && operator !== "==") return;
117
86
  let typeofPath;
118
87
  let typePath;
119
-
120
88
  if (left.isUnaryExpression({
121
89
  operator: "typeof"
122
90
  })) {
@@ -128,7 +96,6 @@ function inferAnnotationFromBinaryExpression(name, path) {
128
96
  typeofPath = right;
129
97
  typePath = left;
130
98
  }
131
-
132
99
  if (!typeofPath) return;
133
100
  if (!typeofPath.get("argument").isIdentifier({
134
101
  name
@@ -139,37 +106,29 @@ function inferAnnotationFromBinaryExpression(name, path) {
139
106
  if (typeof typeValue !== "string") return;
140
107
  return createTypeAnnotationBasedOnTypeof(typeValue);
141
108
  }
142
-
143
109
  function getParentConditionalPath(binding, path, name) {
144
110
  let parentPath;
145
-
146
111
  while (parentPath = path.parentPath) {
147
112
  if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
148
113
  if (path.key === "test") {
149
114
  return;
150
115
  }
151
-
152
116
  return parentPath;
153
117
  }
154
-
155
118
  if (parentPath.isFunction()) {
156
119
  if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
157
120
  }
158
-
159
121
  path = parentPath;
160
122
  }
161
123
  }
162
-
163
124
  function getConditionalAnnotation(binding, path, name) {
164
125
  const ifStatement = getParentConditionalPath(binding, path, name);
165
126
  if (!ifStatement) return;
166
127
  const test = ifStatement.get("test");
167
128
  const paths = [test];
168
129
  const types = [];
169
-
170
130
  for (let i = 0; i < paths.length; i++) {
171
131
  const path = paths[i];
172
-
173
132
  if (path.isLogicalExpression()) {
174
133
  if (path.node.operator === "&&") {
175
134
  paths.push(path.get("left"));
@@ -180,27 +139,13 @@ function getConditionalAnnotation(binding, path, name) {
180
139
  if (type) types.push(type);
181
140
  }
182
141
  }
183
-
184
142
  if (types.length) {
185
- if (isTSTypeAnnotation(types[0]) && createTSUnionType) {
186
- return {
187
- typeAnnotation: createTSUnionType(types),
188
- ifStatement
189
- };
190
- }
191
-
192
- if (createFlowUnionType) {
193
- return {
194
- typeAnnotation: createFlowUnionType(types),
195
- ifStatement
196
- };
197
- }
198
-
199
143
  return {
200
- typeAnnotation: createUnionTypeAnnotation(types),
144
+ typeAnnotation: (0, _util.createUnionType)(types),
201
145
  ifStatement
202
146
  };
203
147
  }
148
+ return getConditionalAnnotation(binding, ifStatement, name);
149
+ }
204
150
 
205
- return getConditionalAnnotation(ifStatement, name);
206
- }
151
+ //# sourceMappingURL=inferer-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","_util","BOOLEAN_NUMBER_BINARY_OPERATORS","createTypeAnnotationBasedOnTypeof","numberTypeAnnotation","voidTypeAnnotation","_default","node","isReferenced","binding","scope","getBinding","name","identifier","typeAnnotation","getTypeAnnotationBindingConstantViolations","path","types","functionConstantViolations","constantViolations","getConstantViolationsBefore","testType","getConditionalAnnotation","testConstantViolations","ifStatement","filter","indexOf","push","length","violation","getTypeAnnotation","createUnionType","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.ts\";\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.ts\";\n\nimport { createUnionType } from \"./util.ts\";\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,IAAAA,EAAA,GAAAC,OAAA;AASA,IAAAC,KAAA,GAAAD,OAAA;AAA4C;EAR1CE,+BAA+B;EAC/BC,iCAAiC;EACjCC,oBAAoB;EACpBC;AAAkB,IAAAN,EAAA;AAOL,SAAAO,SAAwCC,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,C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