Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error stackframes in class constructors have the wrong name #9748

Open
eps1lon opened this issue Nov 19, 2024 · 0 comments
Open

error stackframes in class constructors have the wrong name #9748

eps1lon opened this issue Nov 19, 2024 · 0 comments
Labels

Comments

@eps1lon
Copy link

eps1lon commented Nov 19, 2024

Describe the bug

When an error is thrown from a class constructor, the name in the stack frame should read "new NameOfTheClass". SWC is not able to restore these names with sourcemaps. Constructor-less classes will have no mapped name as well. Classes with constructors will use the generic constructor name instead.

Input code

class ReactComponent {
  constructor() {
    throw new Error("Boom");
  }
}

class Component extends ReactComponent {}

new Component();

Config

{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "minify": {
      "mangle": true
    }
  },
  "minify": true,
  "sourceMaps": true,
  "env": {
    "targets": "node >= 20.14.0"
  }
}

Playground link (or link to the minimal reproduction)

https://github.com/eps1lon/sourcemapped-stackframes-playground#-class-component

SWC Info output

Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done
/Users/sebbie/.nvm/versions/node/v20.14.0/lib/node_modules/corepack/dist/lib/corepack.cjs:23512
              throw new UsageError(`This project is configured to use ${result.spec.name} because ${result.target} has a "packageManager" field`);
                    ^

UsageError: This project is configured to use pnpm because /Users/sebbie/repos/sourcemapped-stackframes-playground/package.json has a "packageManager" field
    at Engine.findProjectSpec (/Users/sebbie/.nvm/versions/node/v20.14.0/lib/node_modules/corepack/dist/lib/corepack.cjs:23512:21)
    at async Engine.executePackageManagerRequest (/Users/sebbie/.nvm/versions/node/v20.14.0/lib/node_modules/corepack/dist/lib/corepack.cjs:23542:24)
    at async Object.runMain (/Users/sebbie/.nvm/versions/node/v20.14.0/lib/node_modules/corepack/dist/lib/corepack.cjs:24235:5) {
  clipanion: { type: 'usage' }
}

Node.js v20.14.0

    Operating System:
        Platform: darwin
        Arch: arm64
        Machine Type: arm64
        Version: Darwin Kernel Version 23.6.0: Thu Sep 12 23:35:10 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6030
        CPU: (11 cores)
            Models: Apple M3 Pro

    Binaries:
        Node: 20.14.0
        npm: 10.7.0
        Yarn: N/A
        pnpm: 8.15.7

    Relevant Packages:
        @swc/core: 1.9.2-nightly-20241111.1
        @swc/helpers: N/A
        @swc/types: N/A
        

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A

Expected behavior

Stack of the original code

~/src/class-component.js:3
[...]
    at new ReactComponent (~/src/class-component.js:3:11)
    at new Component (~/src/class-component.js:7:1)

Actual behavior

Stack when the generated code is run with --enable-source-maps

~/src/class-component.js:3
    throw new Error("Boom");
    ^
[...]
    at constructor (~/src/class-component.js:3:11)
    at r (~/src/class-component.js:7:1)

Version

1.9.2-nightly-20241111.1

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant