@@ -3,6 +3,8 @@ import splitExportDeclaration from "@babel/helper-split-export-declaration";
33import * as t from "@babel/types" ;
44import type { NodePath , Visitor } from "../.." ;
55import { requeueComputedKeyAndDecorators } from "@babel/helper-environment-visitor" ;
6+ import { traverseNode } from "../../traverse-node" ;
7+ import { explode } from "../../visitors" ;
68
79const renameVisitor : Visitor < Renamer > = {
810 ReferencedIdentifier ( { node } , state ) {
@@ -111,6 +113,7 @@ export default class Renamer {
111113 // );
112114 }
113115
116+ // TODO(Babel 8): Remove this `block` parameter. It's not needed anywhere.
114117 rename ( block ?: t . Pattern | t . Scopable ) {
115118 const { binding, oldName, newName } = this ;
116119 const { scope, path } = binding ;
@@ -130,15 +133,16 @@ export default class Renamer {
130133 }
131134 }
132135
133- const blockToTraverse = block || scope . block ;
134- if ( blockToTraverse ?. type === "SwitchStatement" ) {
135- // discriminant is not part of current scope, should be skipped.
136- blockToTraverse . cases . forEach ( c => {
137- scope . traverse ( c , renameVisitor , this ) ;
138- } ) ;
139- } else {
140- scope . traverse ( blockToTraverse , renameVisitor , this ) ;
141- }
136+ traverseNode (
137+ block || scope . block ,
138+ explode ( renameVisitor ) ,
139+ scope ,
140+ this ,
141+ scope . path ,
142+ // When blockToTraverse is a SwitchStatement, the discriminant
143+ // is not part of the current scope and thus should be skipped.
144+ { discriminant : true } ,
145+ ) ;
142146
143147 if ( ! block ) {
144148 scope . removeOwnBinding ( oldName ) ;
0 commit comments