Repository: swc-project/swc (rust)

Issue:
Different code removed after compression depending on formatting
### Describe the bug

After compilation some code is missing. If I change formatting (e.g. add whitespace) everything works well

### Input code

```typescript
const init = () => {
  var e = window.parcelRequire;
  e.register('module1', function () {
    class Hello {
      world() {}
    }
}), e.register('module2', function () {
      console.log('test')
    });
};

init();
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "dynamicImport": true,
      "tsx": true,
      "jsx": true
    },
    "minify": {
      "compress": true,
      "mangle": false
    },
    "loose": false
  },
  "env": {
    "targets": "> 0.25%, not dead, Safari >=8",
    "mode": "entry",
    "coreJs": "3.27",
    "loose": false,
    "bugfixes": true
  },
  "minify": true
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.101&code=H4sIAAAAAAAAA23PMQ7CMAwF0D2n%2BFsSqaoEa1VmZm5QpaaKZGJI0nZAuTsJMHazvr%2BebCchZfjgM0YYi%2FGCtwK2KYJqsvswy94%2Fp%2BiIb%2FRafaSh7qmPtPiUKRr9kHllOukO9zW47CU0qCmA4yklXIlZ%2FgmwS%2BS5Nco3KKrY7gA8H4KVrBcLU8%2ByGJ0pZW1%2Fjh1UGZRqv5g6fwBCS3yK2gAAAA%3D%3D&config=H4sIAAAAAAAAA22Py4oCQQxF935FEXDXiCgyw8C41%2B18QaY63ZR0PUji0IX471O2dvvAXeXc4iT3NDMGDmLhy5zKswwJWYinuRDJQbEvBDQnEssuKVRjWueA3tmdT5G1fFI%2B0hSq9K%2FoMKGBnK8BeBdckx%2FX2ugTk8irwGNoOyq0wU6eJV2M8pgMHCj83espckt6kcLWLBerzbwyIaqpCevK%2FGCD7Mz2%2BxPGu2J9MRaJch6hjUz7wbFerD7g3fYb%2Bz22jetJ7pWvN011B3r%2BB3YL95yHAQAA

### SWC Info output

_No response_

### Expected behavior

```javascript
var e;(e=window.parcelRequire).register("module1",function(){}),e.register("module2",function(){console.log("test")});
```

If I add whitespace at the beginning of line 7 output becomes correct


### Actual behavior

```javascript
window.parcelRequire.register("module1",function(){});
```

### Version

1.3.101

### Additional context

_No response_

Pull request:
fix(es/compat): Correct span lo for class transform
<!-- 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):**
Closes #8435 

Patch:
diff --git a/crates/swc/Cargo.toml b/crates/swc/Cargo.toml
index 1ab339482e..816a74cf9c 100644
--- a/crates/swc/Cargo.toml
+++ b/crates/swc/Cargo.toml
@@ -24,7 +24,7 @@ concurrent = [
   "swc_ecma_minifier/concurrent",
 ]
 
-debug = ["swc_ecma_visit/debug"]
+debug = ["swc_ecma_visit/debug", "swc_ecma_minifier/debug"]
 default = ["es3"]
 es3 = []
 node = ["napi", "napi-derive", "swc_compiler_base/node"]
diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs
index 50a846f4d9..de2204de99 100644
--- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs
+++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs
@@ -381,7 +381,7 @@ where
         if let Expr::Call(call) = &mut rhs {
             let mut span = Span {
                 // after class
-                lo: span.hi + BytePos(5),
+                lo: span.lo + BytePos(5),
                 ..span
             };
             self.add_pure_comments(&mut span.lo);


Test patch:
diff --git a/crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map b/crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
index 926b19ade3..75ce485e23 100644
--- a/crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
+++ b/crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
@@ -1,5 +1,5 @@
 {
-  "mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
+  "mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAD,AAAL;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
   "names": [
     "Foo",
     "bar",
diff --git a/crates/swc/tests/fixture/issues-8xxx/8435/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8435/input/.swcrc
new file mode 100644
index 0000000000..3bcda37f72
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8435/input/.swcrc
@@ -0,0 +1,20 @@
+{
+  "jsc": {
+    "parser": {
+      "syntax": "typescript",
+      "dynamicImport": true,
+      "tsx": true,
+      "jsx": true
+    },
+    "minify": {
+      "compress": true,
+      "mangle": false
+    },
+    "loose": false
+  },
+  "env": {
+    "targets": "> 0.25%, not dead, Safari >=8",
+    "mode": "entry",
+    "coreJs": "3.27"
+  }
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8435/input/index.js b/crates/swc/tests/fixture/issues-8xxx/8435/input/index.js
new file mode 100644
index 0000000000..949175b2c5
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8435/input/index.js
@@ -0,0 +1,12 @@
+const init = () => {
+  var e = window.parcelRequire;
+  e.register('module1', function () {
+    class Hello {
+      world() {}
+    }
+}), e.register('module2', function () {
+      console.log('test')
+    });
+};
+
+init();
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8435/output/index.js b/crates/swc/tests/fixture/issues-8xxx/8435/output/index.js
new file mode 100644
index 0000000000..c58a5ee491
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8435/output/index.js
@@ -0,0 +1,6 @@
+var e;
+import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
+import { _ as _create_class } from "@swc/helpers/_/_create_class";
+(e = window.parcelRequire).register("module1", function() {}), e.register("module2", function() {
+    console.log("test");
+});