swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.28k stars 1.23k forks source link

`super(...args)` from transpilation not sourcemapped #9742

Closed eps1lon closed 6 days ago

eps1lon commented 1 week ago

Describe the bug

When SWC adds a super(...args) call, it doesn't sourcemap it back to original code. Since super(...args) could throw, resulting stacks would not be sourcemapped fully.

Input code

class Parent {
    constructor() {
        throw new Error('foo')
    }
}

class Child extends Parent {
  handleScroll = () => {}
}

new Child()

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "loose": true,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "node >= 8"
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.9.2&code=H4sIAAAAAAAAA1WMQQqEMAxF9z1FdtpD6GZwL8wJSpqhAyGBNIOCeHdrcTNv%2BT%2FvIadaYU1G4nAEaKBKdfuhq43x2W68mG4gtMFi1r7hozrEfp%2FhDAF76lW%2BnIF2J8l%2F4ZIkM73RlBkmaOlphqObd7N7Y7wAs2IpXpAAAAA%3D&config=H4sIAAAAAAAAA1WOTQ7CIBBG95yCzNq1MSZ6Aw9B6LSh4S8MNZKmdy9FwLqb%2BR7z%2BFbGOcwk4c7XPObFi0AY%2Bp4TSjaKT04ApREkg%2FIRLo3OdKBRaMISbV8C2jnCTGJYsEZGWTWms1o64wMSNUO3GmEnjf9iVuVg3LAUWCvH5LHUoyv8HrXPuhgUvdplawVo3yeRCBPGow1YNyB%2FPvitGNm2A%2FOWcNspAQAA

SWC Info output

No response

Expected behavior

Transpiled code produces stacks that can be sourcemapped to the original stack:

Uncaught Error: foo
    at constructor (class-frame-without-super:3:15)
    at new Child (class-frame-without-super:7:1)
    at class-frame-without-super:11:1

The super(...args) call should be sourcemapped to right before the class keyword in class Child extends Parent {}

Actual behavior

Transpiled code produces stacks that are not sourcemapped

Version

1.9.2

Additional context

No response