hexo/node_modules/@babel/traverse/lib/scope/binding.js.map

1 line
5.9 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"names":["Binding","constructor","identifier","scope","path","kind","constantViolations","constant","referencePaths","referenced","references","isDeclaredInLoop","Error","reassign","clearValue","deoptValue","hasDeoptedValue","setValue","value","hasValue","indexOf","push","reference","dereference","exports","default","parentPath","key","isFunctionParent","isWhile","isForXStatement","isForStatement"],"sources":["../../src/scope/binding.ts"],"sourcesContent":["import type NodePath from \"../path\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"./index\";\n\nexport type BindingKind =\n | \"var\" /* var declarator */\n | \"let\" /* let declarator, class declaration id, catch clause parameters */\n | \"const\" /* const/using declarator */\n | \"module\" /* import specifiers */\n | \"hoisted\" /* function declaration id */\n | \"param\" /* function declaration parameters */\n | \"local\" /* function expression id, class expression id */\n | \"unknown\"; /* export specifiers */\n/**\n * This class is responsible for a binding inside of a scope.\n *\n * It tracks the following:\n *\n * * Node path.\n * * Amount of times referenced by other nodes.\n * * Paths to nodes that reassign or modify this binding.\n * * The kind of binding. (Is it a parameter, declaration etc)\n */\n\nexport default class Binding {\n identifier: t.Identifier;\n scope: Scope;\n path: NodePath;\n kind: BindingKind;\n\n constructor({\n identifier,\n scope,\n path,\n kind,\n }: {\n identifier: t.Identifier;\n scope: Scope;\n path: NodePath;\n kind: BindingKind;\n }) {\n this.identifier = identifier;\n this.scope = scope;\n this.path = path;\n this.kind = kind;\n\n if (\n (kind === \"var\" || kind === \"hoisted\") &&\n // https://github.com/rollup/rollup/issues/4654\n // Rollup removes the path argument from this call. Add an\n // unreachable IIFE (that rollup doesn't know is unreachable)\n // with side effects, to prevent it from messing up with arguments.\n // You can reproduce this with\n // BABEL_8_BREAKING=true make prepublish-build\n isDeclaredInLoop(\n path ||\n (() => {\n throw new Error(\"Internal Babel error: unreachable \");\n })(),\n )\n ) {\n this.reassign(path);\n }\n\n this.clearValue();\n }\n\n constantViolations: Array<NodePath> = [];\n constant: boolean = true;\n\n referencePaths: Array<NodePath> = [];\n referenced: boolean = false;\n references: number = 0;\n\n declare hasDeoptedValue: boolean;\n declare hasValue: boolean;\n declare value: any;\n\n deoptValue() {\n this.clearValue();\n this.hasDeoptedValue = true;\n }\n\n setValue(value: any) {\n if (this.hasDeoptedValue) return;\n this.hasValue = true;\n this.value = value;\n }\n\n clearValue() {\n this.hasDeoptedValue = false;\n this.hasValue = false;\n this.value = null;\n }\n\n /**\n * Register a constant violation with the provided `path`.\n */\n\n reassign(path: NodePath) {\n this.constant = false;\n if (this.constantViolations.indexOf(path) !== -1) {\n return;\n }\n this.constantViolations.push(path);\n }\n\n /**\n * Increment the amount of references to this binding.\n */\n\n reference(path: NodePath) {\n if (this.referencePaths.indexOf(path) !== -1) {\n return;\n }\n this.referenced = true;\n this.references++;\n this.referencePaths.push(path);\n }\n\n /**\n * Decrement the amount of references to this binding.\n */\n\n dereference() {\n this.references--;\n this.referenced = !!this.references;\n }\n}\n\nfunction isDeclaredInLoop(path: NodePath) {\n for (\n let { parentPath, key } = path;\n parentPath;\n { parentPath, key } = parentPath\n ) {\n if (parentPath.isFunctionParent()) return false;\n if (\n parentPath.isWhile() ||\n parentPath.isForXStatement() ||\n (parentPath.isForStatement() && key === \"body\")\n ) {\n return true;\n }\n }\n return fal