hexo/node_modules/@babel/traverse/lib/visitors.js.map

1 line
17 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"names":["virtualTypes","require","_t","DEPRECATED_KEYS","DEPRECATED_ALIASES","FLIPPED_ALIAS_KEYS","TYPES","__internal__deprecationWarning","deprecationWarning","isVirtualType","type","explode","visitor","_exploded","nodeType","Object","keys","shouldIgnoreKey","parts","split","length","fns","part","verify","__esModule","ensureEntranceObjects","ensureCallbackArrays","wrapCheck","types","mergePair","aliases","deprecatedKey","deprecatedAlias","alias","existing","assign","_verified","Error","validateVisitorMethods","indexOf","visitors","visitorKey","path","val","concat","fn","TypeError","merge","states","wrapper","rootVisitor","i","state","visitorType","wrapWithStateOrWrapper","nodeVisitor","oldVisitor","newVisitor","key","Array","isArray","map","newFn","call","toString","obj","enter","exit","apply","arguments","dest","src"],"sources":["../src/visitors.ts"],"sourcesContent":["import * as virtualTypes from \"./path/lib/virtual-types\";\nimport {\n DEPRECATED_KEYS,\n DEPRECATED_ALIASES,\n FLIPPED_ALIAS_KEYS,\n TYPES,\n __internal__deprecationWarning as deprecationWarning,\n} from \"@babel/types\";\nimport type { NodePath, Visitor } from \"./index\";\n\ntype VIRTUAL_TYPES = keyof typeof virtualTypes;\nfunction isVirtualType(type: string): type is VIRTUAL_TYPES {\n return type in virtualTypes;\n}\n\n/**\n * explode() will take a visitor object with all of the various shorthands\n * that we support, and validates & normalizes it into a common format, ready\n * to be used in traversal\n *\n * The various shorthands are:\n * * `Identifier() { ... }` -> `Identifier: { enter() { ... } }`\n * * `\"Identifier|NumericLiteral\": { ... }` -> `Identifier: { ... }, NumericLiteral: { ... }`\n * * Aliases in `@babel/types`: e.g. `Property: { ... }` -> `ObjectProperty: { ... }, ClassProperty: { ... }`\n *\n * Other normalizations are:\n * * Visitors of virtual types are wrapped, so that they are only visited when\n * their dynamic check passes\n * * `enter` and `exit` functions are wrapped in arrays, to ease merging of\n * visitors\n */\nexport function explode(visitor: Visitor) {\n if (visitor._exploded) return visitor;\n visitor._exploded = true;\n\n // normalise pipes\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n const parts: Array<string> = nodeType.split(\"|\");\n if (parts.length === 1) continue;\n\n const fns = visitor[nodeType];\n delete visitor[nodeType];\n\n for (const part of parts) {\n // @ts-expect-error part will be verified by `verify` later\n visitor[part] = fns;\n }\n }\n\n // verify data structure\n verify(visitor);\n\n // make sure there's no __esModule type since this is because we're using loose mode\n // and it sets __esModule to be enumerable on all modules :(\n // @ts-expect-error ESModule interop\n delete visitor.__esModule;\n\n // ensure visitors are objects\n ensureEntranceObjects(visitor);\n\n // ensure enter/exit callbacks are arrays\n ensureCallbackArrays(visitor);\n\n // add type wrappers\n for (const nodeType of Object.keys(visitor)) {\n if (shouldIgnoreKey(nodeType)) continue;\n\n if (!isVirtualType(nodeType)) continue;\n\n // wrap all the functions\n const fns = visitor[nodeType];\n for (const type of Object.keys(fns)) {\n // @ts-expect-error manipulating visitors\n fns[type] = wrapCheck(nodeType, fns[type]);\n }\n\n // clear it from the visitor\n delete visitor[nodeType];\n\n const types = virtualTypes[nodeType];\n if (types !== null) {\n for (const type of types) {\n // merge the visitor if necessary or just put it back in\n if (visitor[type]) {\n mergePair(visitor[type], fns);\n } else {\n // @ts-expect-error Expression produces too complex union\n visitor[type] = fns;\n }\n }\n } else {\n mergePair(visitor, fns);\n }\n }\n\n // add aliases\n for (const nodeType of Object.keys(visitor) as (keyof Visitor)[]) {\n if (shouldIgnoreKey(nodeType)) conti