You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
10 KiB
1 line
10 KiB
4 weeks ago
|
{"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","call","typeAnnotation","setData","typeAnnotationInferringNodes","WeakSet","node","key","parentPath","isVariableDeclarator","declar","declarParent","isForInStatement","isForOfStatement","has","add","_inferer","inferer","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 = _getTypeAnnotation.call(this) || 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 _is
|