Repository: swc-project/swc (rust)

Issue:
props key of window is transformed
### Describe the bug

Object has a key of `window` is been transformed to _$window. when window is used outside of a function.

### Input code

```typescript
const isBrowser = typeof window !== "undefined";

function test({
  window
}) {
  create({ window })
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "chrome 44"
  }
}
```


### Playground link

https://play.swc.rs/?version=1.3.44&code=H4sIAAAAAAAAAzXMQQqAIBBG4f2c4s%2BVnSHcdJPQEdzMhI5IhHePoJYPPl5UaYbS9qqjcUWAXSdrxiiSdGAJAa5L4lyEk9uIcpdoRQXGzfxN%2BCjNFW%2FFyoexv%2F%2FDXGnSA6wxs91nAAAA&config=H4sIAAAAAAAAA1WOSw6DMAxE9zlF5HWXqIveoYeIUkNT5Sc7VEWIu5NAQmFnz4yfZxZSwoc1POScx7xERYx07FnhySf1ywqkKSJrMjHBrbmJi9Ury7hJy%2B6ADYGxOVVzxpt%2BOrN1cJGQ%2BRosUeUHi1eyqHRw4TVuZu1cepV%2ByHf4h9qzAwyGn%2B0y0bhr6L8nkKIBU2kD%2Bk3Boey6jSiWFRxKM0YqAQAA

### Expected behavior

The property key should not be transformed

### Actual behavior

_No response_

### Version

1.3.44

### Additional context

_No response_

Pull request:
fix(es/compat): Handle shorthand object prop when rename
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
- fix #7174 

Patch:
diff --git a/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/operator.rs b/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/operator.rs
index ce1f8b7d4a..906e53805b 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/operator.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/block_scoping/operator.rs
@@ -26,6 +26,22 @@ impl VisitMut for Rename {
         }
     }
 
+    fn visit_mut_prop(&mut self, n: &mut Prop) {
+        if let Prop::Shorthand(ident) = n {
+            if let Some(id) = self.map.get(&ident.to_id()) {
+                *n = KeyValueProp {
+                    key: PropName::Ident(ident.clone()),
+                    value: Box::new(Ident::new(id.0.clone(), ident.span.with_ctxt(id.1)).into()),
+                }
+                .into();
+            }
+
+            return;
+        }
+
+        n.visit_mut_children_with(self);
+    }
+
     fn visit_mut_member_prop(&mut self, n: &mut MemberProp) {
         if let MemberProp::Computed(n) = n {
             n.visit_mut_with(self);


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7174/input/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7174/input/.swcrc
new file mode 100644
index 0000000000..7ce3c0f5db
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7174/input/.swcrc
@@ -0,0 +1,21 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": false
+        },
+        "loose": false,
+        "minify": {
+            "compress": false,
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false,
+    "isModule": true,
+    "env": {
+        "targets": "chrome 44"
+    }
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7174/input/index.js b/crates/swc/tests/fixture/issues-7xxx/7174/input/index.js
new file mode 100644
index 0000000000..9882e90c16
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7174/input/index.js
@@ -0,0 +1,7 @@
+const isBrowser = typeof window !== "undefined";
+
+function test({
+  window
+}) {
+  create({ window })
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7174/output/index.js b/crates/swc/tests/fixture/issues-7xxx/7174/output/index.js
new file mode 100644
index 0000000000..5db731bdad
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7174/output/index.js
@@ -0,0 +1,7 @@
+var isBrowser = typeof window !== "undefined";
+function test(param) {
+    var _$window = param.window;
+    create({
+        window: _$window
+    });
+}