1 line
7 KiB
Plaintext
1 line
7 KiB
Plaintext
|
{"version":3,"names":["require","visitors","exports","_t","cache","_traverseNode","_index","_index2","_hub","VISITOR_KEYS","removeProperties","traverseFast","traverse","parent","opts","scope","state","parentPath","visitSelf","noScope","type","Error","explode","traverseNode","_default","default","verify","cheap","node","enter","path","skipKeys","clearNode","tree","hasDenylistedType","has","stop","hasType","denylistTypes","includes","denylist"],"sources":["../src/index.ts"],"sourcesContent":["import \"./path/context.ts\"; // We have some cycles, this ensures correct order to avoid TDZ\nimport * as visitors from \"./visitors.ts\";\nimport {\n VISITOR_KEYS,\n removeProperties,\n type RemovePropertiesOptions,\n traverseFast,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport * as cache from \"./cache.ts\";\nimport type NodePath from \"./path/index.ts\";\nimport type { default as Scope, Binding } from \"./scope/index.ts\";\nimport type { ExplodedVisitor, Visitor, VisitorBase } from \"./types.ts\";\nimport { traverseNode } from \"./traverse-node.ts\";\n\nexport type { ExplodedVisitor, Visitor, VisitorBase, Binding };\nexport { default as NodePath } from \"./path/index.ts\";\nexport { default as Scope } from \"./scope/index.ts\";\nexport { default as Hub } from \"./hub.ts\";\nexport type { HubInterface } from \"./hub.ts\";\n\nexport { visitors };\n\nexport type TraverseOptions<S = t.Node> = {\n scope?: Scope;\n noScope?: boolean;\n denylist?: string[];\n shouldSkip?: (node: NodePath) => boolean;\n} & Visitor<S>;\n\nexport type ExplodedTraverseOptions<S = t.Node> = TraverseOptions<S> &\n ExplodedVisitor<S>;\n\nfunction traverse<S>(\n parent: t.Node,\n opts: TraverseOptions<S>,\n scope: Scope | undefined,\n state: S,\n parentPath?: NodePath,\n visitSelf?: boolean,\n): void;\n\nfunction traverse(\n parent: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n visitSelf?: boolean,\n): void;\n\nfunction traverse<Options extends TraverseOptions>(\n parent: t.Node,\n // @ts-expect-error provide {} as default value for Options\n opts: Options = {},\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n visitSelf?: boolean,\n) {\n if (!parent) return;\n\n if (!opts.noScope && !scope) {\n if (parent.type !== \"Program\" && parent.type !== \"File\") {\n throw new Error(\n \"You must pass a scope and parentPath unless traversing a Program/File. \" +\n `Instead of that you tried to traverse a ${parent.type} node without ` +\n \"passing scope and parentPath.\",\n );\n }\n }\n\n if (!parentPath && visitSelf) {\n throw new Error(\"visitSelf can only be used when providing a NodePath.\");\n }\n\n if (!VISITOR_KEYS[parent.type]) {\n return;\n }\n\n visitors.explode(opts as Visitor);\n\n traverseNode(\n parent,\n opts as ExplodedVisitor,\n scope,\n state,\n parentPath,\n /* skipKeys */ null,\n visitSelf,\n );\n}\n\nexport default traverse;\n\ntraverse.visitors = visitors;\ntraverse.verify = visitors.verify;\ntraverse.explode = visitors.explode;\n\ntraverse.cheap = function (node: t.Node, enter: (node: t.Node) => void) {\n traverseFast(node, enter);\n return;\n};\n\ntraverse.node = function (\n node: t.Node,\n opts: ExplodedTraverseOptions,\n scope?: Scope,\n state?: any,\n path?: NodePath,\n skipKeys?: Record<string, boolean>,\n) {\n traverseNode(node, opts, scope, state, path, skipKeys);\n // traverse.node always returns undefined\n};\n\ntraverse.clearNode = function (node: t.Node, opts?: RemovePropertiesOptions) {\n removeProperties(node, opts);\n};\n\ntraverse.removeProperties = function (\n tree: t.Node,\n opts?: RemovePropertiesOptions,\n) {\n traverseFast(tree, traverse.clearNode, opts);\n return tree;\n};\n\ntype HasDenylistedTypeState = {\n has: boolean;\n type: t.Node[\"type\"];\n};\nfunction hasDenylistedType(path: NodePath, state: HasDenylistedTypeState) {\n if (path.node.type === state.type) {\n state.has = true;\n path.stop();\n }\n}\n\nt
|