Repository: swc-project/swc (rust)

Issue:
jsc.target is ignored when env is specified
### Describe the bug

When I specify `mode` & `coreJs` in `env` swc ignores `jsc.target`. You can test it my removing/adding `env` in config in playground

### Input code

```typescript
const foo = {};
foo?.bar.baz?.()
```


### Config


```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "importMeta": true
    },
    "transform": {
      "react": {
        "refresh": true
      }
    },
    "target": "es2019",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "mode": "entry"
  }
}
```


### Playground link

https://play.swc.rs/?version=1.3.31&code=H4sIAAAAAAAAA0vOzysuUUjLz1ewVaiuteYCsuz1khKLgLjKXk9DEwBsEhSNIAAAAA%3D%3D&config=H4sIAAAAAAAAA0WOSw7CMAxE7%2BJ1F8ACid6hh7CCC0HNR7aLiKrcnbi0dGd55j3NAi9x0C%2BQkYXYLilR8QM9aMkkjn1W6EClvUachDrwISfWgRShV56ptpgxypg4mIEJnf6OkUmeW8tqyA9qEZBcTudb804pCf3NwUc%2FFkNdCrmxckQYH9PeNFdI99keyzp0dV6hHo59rAxb0UZ0QPFtTKNXJioXqPULJiXVeAgBAAA%3D

### Expected behavior

Output should be

```
var _foo_bar, _foo_bar_baz, _ref;
const foo = {};
(_foo_bar_baz = (_ref = _foo_bar = foo === null || foo === void 0 ? void 0 : foo.bar) === null || _ref === void 0 ? void 0 : _ref.baz) === null || _foo_bar_baz === void 0 ? void 0 : _foo_bar_baz.call(_foo_bar);
```

### Actual behavior

Output

```
const foo = {};
foo?.bar.baz?.()
```

### Version

1.3.31

Pull request:
feat(es): Add a validation for a wrong config
**Description:**

**Related issue:**

 - Closes #6956.

Patch:
diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs
index ca247448a5..bdcc591e41 100644
--- a/crates/swc/src/config/mod.rs
+++ b/crates/swc/src/config/mod.rs
@@ -373,6 +373,10 @@ impl Options {
         let unresolved_mark = self.unresolved_mark.unwrap_or_else(Mark::new);
         let top_level_mark = self.top_level_mark.unwrap_or_else(Mark::new);
 
+        if target.is_some() && cfg.env.is_some() {
+            bail!("`jsc.env` and `jsc.target` cannot be used together");
+        }
+
         let es_version = target.unwrap_or_default();
 
         let syntax = syntax.unwrap_or_default();


Test patch:
diff --git a/crates/swc/tests/fixture/issues-1xxx/1525/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1525/case1/input/.swcrc
index 23c54c97d8..bb6114eb9e 100644
--- a/crates/swc/tests/fixture/issues-1xxx/1525/case1/input/.swcrc
+++ b/crates/swc/tests/fixture/issues-1xxx/1525/case1/input/.swcrc
@@ -5,7 +5,6 @@
         }
     },
     "jsc": {
-        "target": "es2019",
         "parser": {
             "syntax": "typescript",
             "tsx": true
@@ -14,4 +13,4 @@
     "module": {
         "type": "commonjs"
     }
-}
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-1xxx/1568/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1568/case1/input/.swcrc
index 9d2643edee..28eac38943 100644
--- a/crates/swc/tests/fixture/issues-1xxx/1568/case1/input/.swcrc
+++ b/crates/swc/tests/fixture/issues-1xxx/1568/case1/input/.swcrc
@@ -6,7 +6,6 @@
             "decorators": false,
             "dynamicImport": true
         },
-        "target": "es5",
         "loose": true,
         "externalHelpers": false
     },
@@ -18,4 +17,4 @@
     "module": {
         "type": "commonjs"
     }
-}
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-2xxx/2372/input/.swcrc b/crates/swc/tests/fixture/issues-2xxx/2372/input/.swcrc
index b6c1968cd1..c22cc7a121 100644
--- a/crates/swc/tests/fixture/issues-2xxx/2372/input/.swcrc
+++ b/crates/swc/tests/fixture/issues-2xxx/2372/input/.swcrc
@@ -10,8 +10,7 @@
                 "dynamicImport": true,
                 "syntax": "typescript",
                 "tsx": false
-            },
-            "target": "es2015"
+            }
         },
         "module": {
             "type": "commonjs"
@@ -29,12 +28,11 @@
             "parser": {
                 "dynamicImport": true,
                 "syntax": "ecmascript"
-            },
-            "target": "es2015"
+            }
         },
         "module": {
             "type": "commonjs"
         },
         "test": ".*.js$"
     }
-]
+]
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7629/input/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7629/input/.swcrc
index 07acb0d9ec..77cb9ecc3a 100644
--- a/crates/swc/tests/fixture/issues-7xxx/7629/input/.swcrc
+++ b/crates/swc/tests/fixture/issues-7xxx/7629/input/.swcrc
@@ -4,7 +4,6 @@
             "syntax": "typescript",
             "tsx": false
         },
-        "target": "es2018",
         "loose": false,
         "minify": {
             "compress": false,
diff --git a/crates/swc/tests/projects/issue-779-1/.swcrc b/crates/swc/tests/projects/issue-779-1/.swcrc
index 685da2339d..b760748eac 100644
--- a/crates/swc/tests/projects/issue-779-1/.swcrc
+++ b/crates/swc/tests/projects/issue-779-1/.swcrc
@@ -1,5 +1,9 @@
 {
-    "test": [".*.tsx$", ".*.ts$", ".*.js$"],
+    "test": [
+        ".*.tsx$",
+        ".*.ts$",
+        ".*.js$"
+    ],
     "module": {
         "type": "commonjs"
     },
@@ -19,7 +23,6 @@
             "decorators": true,
             "dynamicImport": true
         },
-        "target": "es2016",
         "loose": true,
         "transform": {
             "optimizer": {
@@ -31,4 +34,4 @@
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/crates/swc/tests/projects/issue-783/.swcrc b/crates/swc/tests/projects/issue-783/.swcrc
index 4ab12b946b..7656ac04ab 100644
--- a/crates/swc/tests/projects/issue-783/.swcrc
+++ b/crates/swc/tests/projects/issue-783/.swcrc
@@ -18,7 +18,6 @@
             "decorators": true,
             "dynamicImport": true
         },
-        "target": "es2019",
         "loose": true,
         "transform": {
             "optimizer": {
@@ -30,4 +29,4 @@
             }
         }
     }
-}
+}
\ No newline at end of file