{"version":3,"names":["_t","require","isBinding","isBlockScoped","nodeIsBlockScoped","isExportDeclaration","isExpression","nodeIsExpression","isFlow","nodeIsFlow","isForStatement","isForXStatement","isIdentifier","isImportDeclaration","isImportSpecifier","isJSXIdentifier","isJSXMemberExpression","isMemberExpression","isRestElement","nodeIsRestElement","isReferenced","nodeIsReferenced","isScope","nodeIsScope","isStatement","nodeIsStatement","isVar","nodeIsVar","isVariableDeclaration","react","isForOfStatement","isCompatTag","isReferencedIdentifier","opts","node","parent","name","parentPath","isReferencedMemberExpression","isBindingIdentifier","grandparent","left","init","isUser","loc","isGenerated","isPure","constantsOnly","scope","importKind","exportKind","isRestProperty","isObjectPattern","isSpreadProperty","isObjectExpression","isForAwaitStatement","await","exports","isExistentialTypeParam","Error","isNumericLiteralTypeAnnotation"],"sources":["../../../src/path/lib/virtual-types-validator.ts"],"sourcesContent":["import type NodePath from \"../index.ts\";\nimport {\n isBinding,\n isBlockScoped as nodeIsBlockScoped,\n isExportDeclaration,\n isExpression as nodeIsExpression,\n isFlow as nodeIsFlow,\n isForStatement,\n isForXStatement,\n isIdentifier,\n isImportDeclaration,\n isImportSpecifier,\n isJSXIdentifier,\n isJSXMemberExpression,\n isMemberExpression,\n isRestElement as nodeIsRestElement,\n isReferenced as nodeIsReferenced,\n isScope as nodeIsScope,\n isStatement as nodeIsStatement,\n isVar as nodeIsVar,\n isVariableDeclaration,\n react,\n isForOfStatement,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nconst { isCompatTag } = react;\nimport type { VirtualTypeAliases } from \"./virtual-types.ts\";\n\ntype Opts = Partial<{\n [Prop in keyof Obj]: Obj[Prop] extends t.Node\n ? t.Node\n : Obj[Prop] extends t.Node[]\n ? t.Node[]\n : Obj[Prop];\n}>;\n\nexport interface VirtualTypeNodePathValidators {\n isBindingIdentifier(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isBlockScoped(opts?: Opts): boolean;\n /**\n * @deprecated\n */\n isExistentialTypeParam(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isExpression(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isFlow(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isForAwaitStatement(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isGenerated(opts?: VirtualTypeAliases[\"Generated\"]): boolean;\n /**\n * @deprecated\n */\n isNumericLiteralTypeAnnotation(\n opts?: VirtualTypeAliases[\"NumericLiteralTypeAnnotation\"],\n ): void;\n isPure(opts?: VirtualTypeAliases[\"Pure\"]): boolean;\n isReferenced(opts?: VirtualTypeAliases[\"Referenced\"]): boolean;\n isReferencedIdentifier(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isReferencedMemberExpression(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isRestProperty(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isScope(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isSpreadProperty(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isStatement(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n isUser(opts?: VirtualTypeAliases[\"User\"]): boolean;\n isVar(\n this: NodePath,\n opts?: Opts,\n ): this is NodePath;\n}\n\nexport function isReferencedIdentifier(this: NodePath, opts?: any): boolean {\n const { node, parent } = this;\n if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {\n if (isJSXIdentifier(node, opts)) {\n if (isCompatTag(node.name)) return false;\n } else {\n // not a JSXIdentifier or an Identifier\n return false;\n }\n }\n\n // check if node is referenced\n return nodeIsReferenced(node, parent, this.parentPath.parent);\n}\n\nexport function isReferencedMemberExpression(this: NodePath): boolean {\n const { node, parent } = this;\n return isMemberExpression(node) && nodeIsReferenced(node, parent);\n}\n\nexport function isBindingIdentifier(this: NodePath): boolean {\n const { node, parent } = this;\n const grandparent = this.parentPath.parent;\n return isIdentifier(node) && isBinding(node, parent, grandparent);\n}\n\nexport function isStatement(this: NodePath): boolean {\n const { node, parent } = this;\n if (nodeIsStatement(node)) {\n if (isVariableDeclaration(node)) {\n if (isForXStatement(parent, { left: node })) return false;\n if (isForStatement(parent, { init: node })) return false;\n }\n\n return true;\n } else {\n return false;\n }\n}\n\nexport function isExpression(this: NodePath): boolean {\n if (this.isIdentifier()) {\n return this.isReferencedIdentifier();\n } else {\n return nodeIsExpression(this.node);\n }\n}\n\nexport function isScope(this: NodePath): boolean {\n return nodeIsScope(this.node, this.parent);\n}\n\nexport function isReferenced(this: NodePath): boolean {\n return nodeIsReferenced(this.node, this.parent);\n}\n\nexport function isBlockScoped(this: NodePath): boolean {\n return nodeIsBlockScoped(this.node);\n}\n\nexport function isVar(this: NodePath): boolean {\n return nodeIsVar(this.node);\n}\n\nexport function isUser(this: NodePath): boolean {\n return this.node && !!this.node.loc;\n}\n\nexport function isGenerated(this: NodePath): boolean {\n return !this.isUser();\n}\n\nexport function isPure(this: NodePath, constantsOnly?: boolean): boolean {\n return this.scope.isPure(this.node, constantsOnly);\n}\n\nexport function isFlow(this: NodePath): boolean {\n const { node } = this;\n if (nodeIsFlow(node)) {\n return true;\n } else if (isImportDeclaration(node)) {\n return node.importKind === \"type\" || node.importKind === \"typeof\";\n } else if (isExportDeclaration(node)) {\n return node.exportKind === \"type\";\n } else if (isImportSpecifier(node)) {\n return node.importKind === \"type\" || node.importKind === \"typeof\";\n } else {\n return false;\n }\n}\n\n// TODO: 7.0 Backwards Compat\nexport function isRestProperty(this: NodePath): boolean {\n return (\n nodeIsRestElement(this.node) &&\n this.parentPath &&\n this.parentPath.isObjectPattern()\n );\n}\n\nexport function isSpreadProperty(this: NodePath): boolean {\n return (\n nodeIsRestElement(this.node) &&\n this.parentPath &&\n this.parentPath.isObjectExpression()\n );\n}\n\nexport function isForAwaitStatement(this: NodePath): boolean {\n return isForOfStatement(this.node, { await: true });\n}\n\nif (!process.env.BABEL_8_BREAKING && !USE_ESM) {\n // eslint-disable-next-line no-restricted-globals\n exports.isExistentialTypeParam = function isExistentialTypeParam(\n this: NodePath,\n ): void {\n throw new Error(\n \"`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.\",\n );\n };\n\n // eslint-disable-next-line no-restricted-globals\n exports.isNumericLiteralTypeAnnotation =\n function isNumericLiteralTypeAnnotation(this: NodePath): void {\n throw new Error(\n \"`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.\",\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,EAAA,GAAAC,OAAA;AAsBsB;EArBpBC,SAAS;EACTC,aAAa,EAAIC,iBAAiB;EAClCC,mBAAmB;EACnBC,YAAY,EAAIC,gBAAgB;EAChCC,MAAM,EAAIC,UAAU;EACpBC,cAAc;EACdC,eAAe;EACfC,YAAY;EACZC,mBAAmB;EACnBC,iBAAiB;EACjBC,eAAe;EACfC,qBAAqB;EACrBC,kBAAkB;EAClBC,aAAa,EAAIC,iBAAiB;EAClCC,YAAY,EAAIC,gBAAgB;EAChCC,OAAO,EAAIC,WAAW;EACtBC,WAAW,EAAIC,eAAe;EAC9BC,KAAK,EAAIC,SAAS;EAClBC,qBAAqB;EACrBC,KAAK;EACLC;AAAgB,IAAA9B,EAAA;AAGlB,MAAM;EAAE+B;AAAY,CAAC,GAAGF,KAAK;AA4EtB,SAASG,sBAAsBA,CAAiBC,IAAU,EAAW;EAC1E,MAAM;IAAEC,IAAI;IAAEC;EAAO,CAAC,GAAG,IAAI;EAC7B,IAAI,CAACvB,YAAY,CAACsB,IAAI,EAAED,IAAI,CAAC,IAAI,CAACjB,qBAAqB,CAACmB,MAAM,EAAEF,IAAI,CAAC,EAAE;IACrE,IAAIlB,eAAe,CAACmB,IAAI,EAAED,IAAI,CAAC,EAAE;MAC/B,IAAIF,WAAW,CAACG,IAAI,CAACE,IAAI,CAAC,EAAE,OAAO,KAAK;IAC1C,CAAC,MAAM;MAEL,OAAO,KAAK;IACd;EACF;EAGA,O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