PrimeIntellect/SWE-rebench-V2 huggingface dataset:
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:
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",
Repository: babel/minify (js)

Issue:
Wrong code generated for while statement, edgecase
**Describe the bug**

The falsy while statement should not remove variable declarations.

**To Reproduce**

Minimal code to reproduce the bug

```js
function a() {
  ++i;
  while (false) {
    var i = meow();
  }
}
```

**Actual Output**

If there is no Error thrown,

```js
function a(){
  ++i;
}
```

**Expected Output**

```js
function a(){
  ++i;
  var i;
}
```

**Configuration**

How are you using babel-minify?

`babel-minify CLI`

babel-minify version: `0.5.0`

babel version : `7.0.0-beta.49`

babel-minify-config: default

**Possible solution**

Looks like path should not be removed but instead replaced with extracted variables.


Pull request:
Fixes #922, extractVars instead of path removal
Discussion started here #898 

Patch:
diff --git a/packages/babel-plugin-minify-dead-code-elimination/src/index.js b/packages/babel-plugin-minify-dead-code-elimination/src/index.js
index 0eb1d74..8c26ed8 100644
--- a/packages/babel-plugin-minify-dead-code-elimination/src/index.js
+++ b/packages/babel-plugin-minify-dead-code-elimination/src/index.js
@@ -707,7 +707,7 @@ module.exports = ({ types: t, traverse }) => {
       const test = path.get("test");
       const result = evaluate(test, { tdz: this.tdz });
       if (result.confident && test.isPure() && !result.value) {
-        path.remove();
+        path.replaceWithMultiple(extractVars(path.get("body")));
       }
     },
 


Test patch:
diff --git a/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/actual.js b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/actual.js
new file mode 100644
index 0000000..e37e281
--- /dev/null
+++ b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/actual.js
@@ -0,0 +1,6 @@
+function a() {
+  ++i;
+  while (false) {
+    var i = meow();
+  }
+}
\ No newline at end of file
diff --git a/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/expected.js b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/expected.js
new file mode 100644
index 0000000..64f8e39
--- /dev/null
+++ b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/issue-922/expected.js
@@ -0,0 +1,4 @@
+function a() {
+  ++i;
+  var i;
+}
\ No newline at end of file
diff --git a/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/loops/expected.js b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/loops/expected.js
index 4215535..981027f 100644
--- a/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/loops/expected.js
+++ b/packages/babel-plugin-minify-dead-code-elimination/__tests__/fixtures/loops/expected.js
@@ -1,4 +1,3 @@
-// while
 while (true) {
   bar();
 }