node-ejs-renderer/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js.map

1 line
12 KiB
Plaintext
Raw Normal View History

2024-06-09 13:55:01 -04:00
{"version":3,"names":["_core","require","_helperEnvironmentVisitor","findBareSupers","traverse","visitors","merge","Super","path","node","parentPath","isCallExpression","callee","push","environmentVisitor","referenceVisitor","TSTypeAnnotation|TypeAnnotation","skip","ReferencedIdentifier","scope","hasOwnBinding","name","rename","handleClassTDZ","state","classBinding","getBinding","classNameTDZError","file","addHelper","throwNode","t","callExpression","stringLiteral","replaceWith","sequenceExpression","classFieldDefinitionEvaluationTDZVisitor","injectInitialization","constructor","nodes","renamer","lastReturnsThis","length","isDerived","superClass","newConstructor","classMethod","identifier","blockStatement","params","restElement","body","template","statement","ast","get","unshiftContainer","bareSupers","isFirst","bareSuper","map","n","cloneNode","isExpressionStatement","allNodes","toExpression","thisExpression","insertAfter","memoiseComputedKey","keyNode","hint","isUidReference","isIdentifier","hasUid","isMemoiseAssignment","isAssignmentExpression","operator","left","ident","id","kind","assignmentExpression","extractComputedKeys","computedPaths","declarations","computedPath","computedKey","isReferencedIdentifier","computedNode","isConstantExpression","assignment","generateUidBasedOnNode","expressionStatement","key"],"sources":["../src/misc.ts"],"sourcesContent":["import { template, traverse, types as t } from \"@babel/core\";\nimport type { File } from \"@babel/core\";\nimport type { NodePath, Scope, Visitor, Binding } from \"@babel/traverse\";\nimport environmentVisitor from \"@babel/helper-environment-visitor\";\n\nconst findBareSupers = traverse.visitors.merge<NodePath<t.CallExpression>[]>([\n {\n Super(path) {\n const { node, parentPath } = path;\n if (parentPath.isCallExpression({ callee: node })) {\n this.push(parentPath);\n }\n },\n },\n environmentVisitor,\n]);\n\nconst referenceVisitor: Visitor<{ scope: Scope }> = {\n \"TSTypeAnnotation|TypeAnnotation\"(\n path: NodePath<t.TSTypeAnnotation | t.TypeAnnotation>,\n ) {\n path.skip();\n },\n\n ReferencedIdentifier(path: NodePath<t.Identifier>, { scope }) {\n if (scope.hasOwnBinding(path.node.name)) {\n scope.rename(path.node.name);\n path.skip();\n }\n },\n};\n\ntype HandleClassTDZState = {\n classBinding: Binding;\n file: File;\n};\n\nfunction handleClassTDZ(\n path: NodePath<t.Identifier>,\n state: HandleClassTDZState,\n) {\n if (\n state.classBinding &&\n state.classBinding === path.scope.getBinding(path.node.name)\n ) {\n const classNameTDZError = state.file.addHelper(\"classNameTDZError\");\n const throwNode = t.callExpression(classNameTDZError, [\n t.stringLiteral(path.node.name),\n ]);\n\n path.replaceWith(t.sequenceExpression([throwNode, path.node]));\n path.skip();\n }\n}\n\nconst classFieldDefinitionEvaluationTDZVisitor: Visitor<HandleClassTDZState> = {\n ReferencedIdentifier: handleClassTDZ,\n};\n\ninterface RenamerState {\n scope: Scope;\n}\n\nexport function injectInitialization(\n path: NodePath<t.Class>,\n constructor: NodePath<t.ClassMethod> | undefined,\n nodes: t.ExpressionStatement[],\n renamer?: (visitor: Visitor<RenamerState>, state: RenamerState) => void,\n lastReturnsThis?: boolean,\n) {\n if (!nodes.length) return;\n\n const isDerived = !!path.node.superClass;\n\n if (!constructor) {\n const newConstructor = t.classMethod(\n \"constructor\",\n t.identifier(\"constructor\"),\n [],\n t.blockStatement([]),\n );\n\n if (isDerived) {\n newConstructor.params = [t.restElement(t.identifier(\"args\"))];\n newConstructor.body.body.push(template.statement.ast`super(...args)`);\n }\n\n [constructor] = path\n .get(\"body\")\n .unshiftContainer(\"body\", newConstructor) as NodePath<t.ClassMethod>[];\n }\n\n if (renamer) {\n renamer(referenceVisitor, { scope: constructor.scope });\n }\n\n if (isDerived) {\n const bareSupers: NodePath<t.CallExpression>[] = [];\n constructor.traverse(findBareS