Repository: nicoespeon/abracadabra (ts)

Issue:
Inline variable overwrites unrelated parameter
## Describe the bug

Inlining a variable doesn't only replace the references, but also parameters that shadow it.
Seems to only happen for methods/functions/setters inside an object.

## How to reproduce

Move the cursor to the first foo and execute `Inline variable`.

```js
var foo = 1;
console.log(foo);
fn({
  set(foo) {
    return foo;
  },
});

```

## Expected behavior

Only inline references of the variable.

```js
console.log(1);
fn({
  set(foo) {
    return foo;
  },
});

```

## Current behavior

It also replaces the `foo` parameter.

```js
console.log(1);
fn({
  set(1) {
    return 1;
  },
});
```

## Additional information

- Version of the extension impacted: _v9.3.0_
- Related: #316


Pull request description:
Fix inline variable with shadowed parameter
Closes #1037

Patch:
diff --git a/src/ast/scope.ts b/src/ast/scope.ts
index cf2333b9..dd077334 100644
--- a/src/ast/scope.ts
+++ b/src/ast/scope.ts
@@ -2,10 +2,7 @@ import { Binding, NodePath } from "@babel/traverse";
 import * as t from "@babel/types";
 import { first } from "../array";
 import { getImportDeclarations, TypeDeclaration } from "./domain";
-import {
-  areEquivalent,
-  isFunctionDeclarationOrArrowFunction
-} from "./identity";
+import { areEquivalent } from "./identity";
 import { isSelectablePath, SelectablePath } from "./selection";
 
 export function findScopePath(path: NodePath<t.Node | null>): NodePath | null {
@@ -52,8 +49,7 @@ export function isShadowIn(
 
   function isDeclaredInFunction(node: t.Node): boolean {
     return (
-      isFunctionDeclarationOrArrowFunction(node) &&
-      node.params.some((node) => areEquivalent(id, node))
+      t.isFunction(node) && node.params.some((node) => areEquivalent(id, node))
     );
   }
 


Test patch:
diff --git a/src/refactorings/inline/inline-variable/inline-variable.test.ts b/src/refactorings/inline/inline-variable/inline-variable.test.ts
index 12dcf430..6ed21b92 100644
--- a/src/refactorings/inline/inline-variable/inline-variable.test.ts
+++ b/src/refactorings/inline/inline-variable/inline-variable.test.ts
@@ -165,6 +165,16 @@ return {title: title};`,
         expected: `const lambda = (title: string) => title.length > 0;
 
 return {title: document.title};`
+      },
+      {
+        description: "shadowed variable in a method",
+        code: `const hello[cursor] = "Hello!";
+console.log(hello);
+
+fn({ set(hello) {} });`,
+        expected: `console.log("Hello!");
+
+fn({ set(hello) {} });`
       },
       {
         description: "export outside of declaration scope",