Debian Codegraph @

packages/babel-traverse/src/scope/lib/renamer.ts

raw symbols SCIP
1 import type Bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding# from "../binding"scip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/;
2 import splitExportDeclarationscip-typescript npm @babel/helper-split-export-declaration 7.18.6 src/`index.ts`/splitExportDeclaration(). from "@babel/helper-split-export-declaration"scip-typescript npm @babel/helper-split-export-declaration 7.18.6 src/`index.ts`/;
3 import * as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/;
4 import type { NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor# } from "../.."scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/;
5 import { requeueComputedKeyAndDecoratorsscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/requeueComputedKeyAndDecorators(). } from "@babel/helper-environment-visitor"scip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/;
6 import { traverseNodescip-typescript npm @babel/traverse 7.20.13 src/`traverse-node.ts`/traverseNode(). } from "../../traverse-node"scip-typescript npm @babel/traverse 7.20.13 src/`traverse-node.ts`/;
7 import { explodescip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/explode(). } from "../../visitors"scip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/;
8
9 const renameVisitorscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/renameVisitor.: Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor#<Renamerscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#> = {
10 ReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types.ts`/VirtualTypeAliases#ReferencedIdentifier.({ nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. }, state) {
11 if (node.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. === state.oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName.) {
12 node.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. = state.newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#newName.;
13 }
14 },
15
16 Scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types.ts`/VirtualTypeAliases#Scope.(path, state) {
17 if (
18 !path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..bindingIdentifierEqualsscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#bindingIdentifierEquals().(
19 state.oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName.,
20 state.bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding..identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier.,
21 )
22 ) {
23 path.skipscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/skip().();
24 if (path.isMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMethod().()) {
25 requeueComputedKeyAndDecoratorsscip-typescript npm @babel/helper-environment-visitor 7.18.9 src/`index.ts`/requeueComputedKeyAndDecorators().(path);
26 }
27 }
28 },
29
30 "AssignmentExpression|Declaration|VariableDeclarator"(
31 path: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.AssignmentPatternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentPattern# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Declarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Declaration# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.VariableDeclaratorscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclarator#>,
32 state,
33 ) {
34 if (path.isVariableDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isVariableDeclaration().()) return;
35 const ids = path.getOuterBindingIdentifiers();
36
37 for (const name in ids) {
38 if (name === state.oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName.) ids[name].namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. = state.newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#newName.;
39 }
40 },
41 };
42
43 export default class Renamerscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer# {
44 constructorscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(binding): Bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#, oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(oldName): string, newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(newName): string) {
45 this.newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#newName. = newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(newName);
46 this.oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName. = oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(oldName);
47 this.bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding. = bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#`<constructor>`().(binding);
48 }
49
50 declare oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName.: string;
51 declare newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#newName.: string;
52 declare bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding.: Bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#;
53
54 maybeConvertFromExportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromExportDeclaration().(parentDeclarscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromExportDeclaration().(parentDeclar): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) {
55 const maybeExportDeclar = parentDeclarscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromExportDeclaration().(parentDeclar).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.;
56
57 if (!maybeExportDeclar.isExportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDeclaration().()) {
58 return;
59 }
60
61 if (maybeExportDeclar.isExportDefaultDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDefaultDeclaration().()) {
62 const { declarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExportDefaultDeclaration#declaration. } = maybeExportDeclar.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.;
63 if (tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isDeclarationscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isDeclaration().(declaration) && !declaration.idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ClassDeclaration#id.) {
64 return;
65 }
66 }
67
68 if (maybeExportDeclar.isExportAllDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportAllDeclaration().()) {
69 return;
70 }
71
72 splitExportDeclarationscip-typescript npm @babel/helper-split-export-declaration 7.18.6 src/`index.ts`/splitExportDeclaration().(
73 maybeExportDeclar as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<
74 Excludescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Exclude#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ExportDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExportDeclaration#, tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ExportAllDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExportAllDeclaration#>
75 >,
76 );
77 }
78
79 maybeConvertFromClassFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionDeclaration().(pathscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionDeclaration().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) {
80 return pathscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionDeclaration().(path); // TODO
81
82 // // retain the `name` of a class/function declaration
83
84 // if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
85 // if (this.binding.kind !== "hoisted") return;
86
87 // path.node.id = identifier(this.oldName);
88 // path.node._blockHoist = 3;
89
90 // path.replaceWith(
91 // variableDeclaration("let", [
92 // variableDeclarator(identifier(this.newName), toExpression(path.node)),
93 // ]),
94 // );
95 }
96
97 maybeConvertFromClassFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionExpression().(pathscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionExpression().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) {
98 return pathscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionExpression().(path); // TODO
99
100 // // retain the `name` of a class/function expression
101
102 // if (!path.isFunctionExpression() && !path.isClassExpression()) return;
103 // if (this.binding.kind !== "local") return;
104
105 // path.node.id = identifier(this.oldName);
106
107 // this.binding.scope.parent.push({
108 // id: identifier(this.newName),
109 // });
110
111 // path.replaceWith(
112 // assignmentExpression("=", identifier(this.newName), path.node),
113 // );
114 }
115
116 renamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#rename().(/* Babel 7 - block?: t.Pattern | t.Scopable */) {
117 const { bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding., oldNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#oldName., newNamescip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#newName. } = this;
118 const { scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#scope., pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path. } = binding;
119
120 const parentDeclar = path.findscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/find().(
121 path =>
122 path.isDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isDeclaration().() ||
123 path.isFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionExpression().() ||
124 path.isClassExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isClassExpression().(),
125 );
126 if (parentDeclar) {
127 const bindingIds = parentDeclar.getOuterBindingIdentifiers();
128 if (bindingIds[oldName] === binding.identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier.) {
129 // When we are renaming an exported identifier, we need to ensure that
130 // the exported binding keeps the old name.
131 this.maybeConvertFromExportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromExportDeclaration().(parentDeclar);
132 }
133 }
134
135 const blockToTraverse = process.env.BABEL_8_BREAKING
136 ? scope.blockscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#block.
137 : (arguments[0] as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Patternscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Pattern# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Scopablescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Scopable#) || scope.blockscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#block.;
138 traverseNodescip-typescript npm @babel/traverse 7.20.13 src/`traverse-node.ts`/traverseNode().(
139 blockToTraverse,
140 explodescip-typescript npm @babel/traverse 7.20.13 src/`visitors.ts`/explode().(renameVisitorscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/renameVisitor.),
141 scope,
142 this,
143 scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path.,
144 // When blockToTraverse is a SwitchStatement, the discriminant
145 // is not part of the current scope and thus should be skipped.
146 { discriminantscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/discriminant0:: true },
147 );
148
149 if (process.env.BABEL_8_BREAKING) {
150 scope.removeOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#removeOwnBinding().(oldName);
151 scope.bindingsscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#bindings.[newName] = binding;
152 this.bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding..identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. = newName;
153 } else if (!arguments[0]) {
154 scope.removeOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#removeOwnBinding().(oldName);
155 scope.bindingsscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#bindings.[newName] = binding;
156 this.bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#binding..identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. = newName;
157 }
158
159 if (parentDeclar) {
160 this.maybeConvertFromClassFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionDeclaration().(path);
161 this.maybeConvertFromClassFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/scope/lib/`renamer.ts`/Renamer#maybeConvertFromClassFunctionExpression().(path);
162 }
163 }
164 }