{"version":3,"names":["virtualTypes","require","_debug","_index","_scope","_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","pathCache","Map","set","path","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\";\nimport type TraversalContext from \"../context\";\nimport * as virtualTypes from \"./lib/virtual-types\";\nimport buildDebug from \"debug\";\nimport traverse from \"../index\";\nimport type { Visitor } from \"../types\";\nimport Scope from \"../scope\";\nimport { validate } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport { path as pathCache } from \"../cache\";\nimport generator from \"@babel/generator\";\n\n// NodePath is split across many files.\nimport * as NodePath_ancestry from \"./ancestry\";\nimport * as NodePath_inference from \"./inference\";\nimport * as NodePath_replacement from \"./replacement\";\nimport * as NodePath_evaluation from \"./evaluation\";\nimport * as NodePath_conversion from \"./conversion\";\nimport * as NodePath_introspection from \"./introspection\";\nimport * as NodePath_context from \"./context\";\nimport * as NodePath_removal from \"./removal\";\nimport * as NodePath_modification from \"./modification\";\nimport * as NodePath_family from \"./family\";\nimport * as NodePath_comments from \"./comments\";\nimport * as NodePath_virtual_types_validator from \"./lib/virtual-types-validator\";\nimport type { NodePathAssertions } from \"./generated/asserts\";\nimport type { NodePathValidators } from \"./generated/validators\";\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 {\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;\n // TraversalContext is configured by setContext\n declare context: TraversalContext;\n declare scope: Scope;\n\n contexts: Array = [];\n state: any = null;\n opts: any = null;\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n _traverseFlags: number = 0;\n skipKeys: any = null;\n parentPath: t.ParentMaps[T[\"type\"]] extends null\n ? null\n : NodePath | null = null;\n container: t.Node | Array | 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 let paths = pathCache.get(parent);\n if (!paths) {\n paths = new Map();\n pathCache.set(parent, paths);\n }\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> {\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(visitor: Visitor, 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\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,\n ): asserts this is NodePath;\n}\n\nexport default NodePath;\n"],"mappings":";;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,EAAA,GAAAJ,OAAA;AAAwC,IAAAK,CAAA,GAAAD,EAAA;AAExC,IAAAE,MAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAGA,IAAAQ,iBAAA,GAAAR,OAAA;AACA,IAAAS,kBAAA,GAAAT,OAAA;AACA,IAAAU,oBAAA,GAAAV,OAAA;AACA,IAAAW,mBAAA,GAAAX,OAAA;AACA,IAAAY,mBAAA,GAAAZ,OAAA;AACA,IAAAa,sBAAA,GAAAb,OAAA;AACA,IAAAc,gBAAA,GAAAd,OAAA;AACA,IAAAe,gBAAA,GAAAf,OAAA;AACA,IAAAgB,qBAAA,GAAAhB,OAAA;AACA,IAAAiB,eAAA,GAAAjB,OAAA;AACA,IAAAkB,iBAAA,GAAAlB,OAAA;AACA,IAAAmB,gCAAA,GAAAnB,OAAA;AAAkF;EAjBzEoB;AAAQ,IAAAhB,EAAA;AAqBjB,MAAMiB,KAAK,GAAGC,MAAU,CAAC,OAAO,CAAC;AAE1B,MAAMC,OAAO,GAAG,CAAC,IAAI,CAAC;AAACC,OAAA,CAAAD,OAAA,GAAAA,OAAA;AACvB,MAAME,WAAW,GAAG,CAAC,IAAI,CAAC;AAACD,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAC3B,MAAMC,WAAW,GAAG,CAAC,IAAI,CAAC;AAACF,OAAA,CAAAE,WAAA,GAAAA,WAAA;AAElC,MAAMC,QAAQ,CAA4B;EACxCC,WAAWA,CAACC,GAAiB,EAAEC,MAA+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