astro-ghostcms/.pnpm-store/v3/files/8f/43d1c011832995db02946ec3762...

1 line
9.7 KiB
Plaintext
Raw Permalink Normal View History

2024-02-14 14:10:47 +00:00
{"version":3,"names":["_helperSplitExportDeclaration","require","t","_helperEnvironmentVisitor","_traverseNode","_visitors","renameVisitor","ReferencedIdentifier","node","state","name","oldName","newName","Scope","path","scope","bindingIdentifierEquals","binding","identifier","skip","isMethod","requeueComputedKeyAndDecorators","ObjectProperty","key","shorthand","getBindingIdentifier","_node$extra","extra","AssignmentExpression|Declaration|VariableDeclarator","isVariableDeclaration","ids","getOuterBindingIdentifiers","Renamer","constructor","maybeConvertFromExportDeclaration","parentDeclar","maybeExportDeclar","parentPath","isExportDeclaration","isExportDefaultDeclaration","declaration","isDeclaration","id","isExportAllDeclaration","splitExportDeclaration","maybeConvertFromClassFunctionDeclaration","maybeConvertFromClassFunctionExpression","rename","find","isFunctionExpression","isClassExpression","bindingIds","blockToTraverse","arguments","block","traverseNode","explode","discriminant","removeOwnBinding","bindings","exports","default"],"sources":["../../../src/scope/lib/renamer.ts"],"sourcesContent":["import type Binding from \"../binding.ts\";\nimport splitExportDeclaration from \"@babel/helper-split-export-declaration\";\nimport * as t from \"@babel/types\";\nimport type { NodePath, Visitor } from \"../../index.ts\";\nimport { requeueComputedKeyAndDecorators } from \"@babel/helper-environment-visitor\";\nimport { traverseNode } from \"../../traverse-node.ts\";\nimport { explode } from \"../../visitors.ts\";\nimport type { Identifier } from \"@babel/types\";\n\nconst renameVisitor: Visitor<Renamer> = {\n ReferencedIdentifier({ node }, state) {\n if (node.name === state.oldName) {\n node.name = state.newName;\n }\n },\n\n Scope(path, state) {\n if (\n !path.scope.bindingIdentifierEquals(\n state.oldName,\n state.binding.identifier,\n )\n ) {\n path.skip();\n if (path.isMethod()) {\n requeueComputedKeyAndDecorators(path);\n }\n }\n },\n\n ObjectProperty({ node, scope }, state) {\n const { name } = node.key as Identifier;\n if (\n node.shorthand &&\n // In destructuring the identifier is already renamed by the\n // AssignmentExpression|Declaration|VariableDeclarator visitor,\n // while in object literals it's renamed later by the\n // ReferencedIdentifier visitor.\n (name === state.oldName || name === state.newName) &&\n // Ignore shadowed bindings\n scope.getBindingIdentifier(name) === state.binding.identifier\n ) {\n node.shorthand = false;\n if (node.extra?.shorthand) node.extra.shorthand = false;\n }\n },\n\n \"AssignmentExpression|Declaration|VariableDeclarator\"(\n path: NodePath<t.AssignmentPattern | t.Declaration | t.VariableDeclarator>,\n state,\n ) {\n if (path.isVariableDeclaration()) return;\n const ids = path.getOuterBindingIdentifiers();\n\n for (const name in ids) {\n if (name === state.oldName) ids[name].name = state.newName;\n }\n },\n};\n\nexport default class Renamer {\n constructor(binding: Binding, oldName: string, newName: string) {\n this.newName = newName;\n this.oldName = oldName;\n this.binding = binding;\n }\n\n declare oldName: string;\n declare newName: string;\n declare binding: Binding;\n\n maybeConvertFromExportDeclaration(parentDeclar: NodePath) {\n const maybeExportDeclar = parentDeclar.parentPath;\n\n if (!maybeExportDeclar.isExportDeclaration()) {\n return;\n }\n\n if (maybeExportDeclar.isExportDefaultDeclaration()) {\n const { declaration } = maybeExportDeclar.node;\n if (t.isDeclaration(declaration) && !declaration.id) {\n return;\n }\n }\n\n if (maybeExportDeclar.isExportAllDeclaration()) {\n return;\n }\n\n splitExportDeclaration(\n maybeExportDeclar as NodePath<\n Exclude<t.ExportDeclaration, t.ExportAllDeclaration>\n >,\n );\n }\n\n maybeConvertFromClassFunctionDeclaration(path: NodePath) {\n return path; // TODO\n\n // // ret