Repository: babel/babel
File: packages/babel-traverse/src/scope/lib/renamer.ts (TypeScript)

Code before:
        path.isClassExpression(),
    );
    if (parentDeclar) {
      const bindingIds = parentDeclar.getOuterBindingIdentifiers();
      if (bindingIds[oldName] === binding.identifier) {
        // When we are renaming an exported identifier, we need to ensure that
        // the exported binding keeps the old name.
        this.maybeConvertFromExportDeclaration(parentDeclar);
      }
    }

    const blockToTraverse = process.env.BABEL_8_BREAKING
      ? scope.block
      : (arguments[0] as t.Pattern | t.Scopable) || scope.block;

    // When blockToTraverse is a SwitchStatement, the discriminant
    // is not part of the current scope and thus should be skipped.

    // const foo = {
    //   get [x]() {
    //     return x;
    //   },
    // };
    const skipKeys: Record<string, true> = { discriminant: true };
    if (t.isMethod(blockToTraverse) && blockToTraverse.computed) {
      skipKeys.key = true;
    }

    traverseNode(
      blockToTraverse,
      explode(renameVisitor),
      scope,
      this,
      scope.path,
      skipKeys,
    );

    if (process.env.BABEL_8_BREAKING) {
      scope.removeOwnBinding(oldName);
      scope.bindings[newName] = binding;
      this.binding.identifier.name = newName;
    } else if (!arguments[0]) {
      scope.removeOwnBinding(oldName);
      scope.bindings[newName] = binding;
      this.binding.identifier.name = newName;
    }

    if (parentDeclar) {
      this.maybeConvertFromClassFunctionDeclaration(path);
      this.maybeConvertFromClassFunctionExpression(path);
    }

Review comment (suggestion):
If `blockToTraverse` is a class method, we should also skip its decorators.

Code after:
        path.isClassExpression(),
    );
    if (parentDeclar) {
      const bindingIds = parentDeclar.getOuterBindingIdentifiers();
      if (bindingIds[oldName] === binding.identifier) {
        // When we are renaming an exported identifier, we need to ensure that
        // the exported binding keeps the old name.
        this.maybeConvertFromExportDeclaration(parentDeclar);
      }
    }

    const blockToTraverse = process.env.BABEL_8_BREAKING
      ? scope.block
      : (arguments[0] as t.Pattern | t.Scopable) || scope.block;

    // When blockToTraverse is a SwitchStatement, the discriminant
    // is not part of the current scope and thus should be skipped.

    // const foo = {
    //   get [x]() {
    //     return x;
    //   },
    // };
    const skipKeys: Record<string, true> = { discriminant: true };
    if (t.isMethod(blockToTraverse)) {
      if (blockToTraverse.computed) {
        skipKeys.key = true;
      }
      if (!t.isObjectMethod(blockToTraverse)) {
        skipKeys.decorators = true;
      }
    }

    traverseNode(
      blockToTraverse,
      explode(renameVisitor),
      scope,
      this,
      scope.path,
      skipKeys,
    );

    if (process.env.BABEL_8_BREAKING) {
      scope.removeOwnBinding(oldName);
      scope.bindings[newName] = binding;
      this.binding.identifier.name = newName;
    } else if (!arguments[0]) {
      scope.removeOwnBinding(oldName);
      scope.bindings[newName] = binding;
      this.binding.identifier.name = newName;
    }