Repository: next.js
Issue: Incorrect optimisation in production compile of variable in Next.js 13.5.x
Labels: bug

### Link to the code that reproduces this issue

https://github.com/matmannion/compile-opt-repro

### To Reproduce

1. Start the application in production (`npm run build`, `npm run start`)
2. Visit http://localhost:3000
3. Click on 'change me'
4. The result shows up as `State is {"name":{"val":"","autoFocus":true}}` - this shows that the passed key (`'buh'`) has been incorrectly optimised to `'name'`

### Current vs. Expected behavior

If you run the application in development mode with `npm run dev` you see the expected behaviour, `State is {"buh":{"val":"","autoFocus":true}}`

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Binaries:
  Node: 18.11.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.3-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

Not sure

### Additional context

We had this a bug report with our app after upgrading to 13.5.1 and verified in 13.5.2 also, so please excuse the legacy-looking code - I'm sure I could re-work it to not trigger the incorrect "optimisation" but as we're not able to fully verify all of the code from our existing app I wanted to make sure the cause was identified before upgrading.

I've tried adding a `.babelrc` to see if this was SWC related, but I get the same behaviour.

From the actual legacy app, this is the source where this was triggered:

```js
<Select
  value=""
  label="Add new key"
  options={sortBy(newKeyOptions, ['value'])}
  onChange={key => {
    if (!this.validate()) {
      return
    }

    let val = availableKeys[key].defaultValue || ''
    let newKey
    if (key === 'name-with-position') {
      newKey = 'name'
      val = { position: '', suffix: '_name' }
    } else if (key === '$ref') {
      val = `#${Object.keys(configForForm.definitions)[0]}` || ''
    } else if (key === 'bulkUploadV2') {
      val = {
        ENTER_COLUMN_TITLE_HERE: {},
      }
    }
    val = typeof val === 'object' ? JSON.stringify(val, 2, 2) : val
    this.editConfigState[newKey || key] = { val, autoFocus: true }
    this.forceUpdate()
  }}
/>
```

And the minified output (with SWC) in Next 13.4.19 (good):

```js
children: (0, s.jsx)(J.Z, {
    value: "",
    label: "Add new key",
    options: a()(f, ["value"]),
    onChange: e => {
        let t;
        if (!this.validate()) return;
        let i = m[e].defaultValue || "";
        "name-with-position" === e ? (t = "name", i = {
            position: "",
            suffix: "_name"
        }) : "$ref" === e ? i = `#${Object.keys(n.definitions)[0]}` || "" : "bulkUploadV2" === e && (i = {ENTER_COLUMN_TITLE_HERE: {}}), i = "object" == typeof i ? JSON.stringify(i, 2, 2) : i, this.editConfigState[t || e] = {
            val: i,
            autoFocus: !0
        }, this.forceUpdate()
    }
})
```

and 13.5.2 (bad):

```js
children: (0, s.jsx)(J.Z, {
    value: "",
    label: "Add new key",
    options: a()(f, ["value"]),
    onChange: e => {
        if (!this.validate()) return;
        let t = m[e].defaultValue || "";
        "name-with-position" === e ? t = {
            position: "",
            suffix: "_name"
        } : "$ref" === e ? t = `#${Object.keys(n.definitions)[0]}` || "" : "bulkUploadV2" === e && (t = {ENTER_COLUMN_TITLE_HERE: {}}), t = "object" == typeof t ? JSON.stringify(t, 2, 2) : t, this.editConfigState.name = {
            val: t,
            autoFocus: !0
        }, this.forceUpdate()
    }
})
```

Note the call to `this.editConfigState[t || e]` in 13.4.19 which is now being optimised incorrectly to `this.editConfigState.name`, it seems like the compiler is incorrectly thinking it can follow the first if() branch when optimising the `newKey` var in the original source.