babel / babel

🐠 Babel is a compiler for writing next generation JavaScript.
https://babel.dev
MIT License
43.22k stars 5.64k forks source link

[Bug]: Babel does not emit a names alias #15362

Open Omcsesz opened 1 year ago

Omcsesz commented 1 year ago

💻

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

class Foo {
  async bar() {
    return this.asdf;
  }
}

Configuration file name

.babelrc

Configuration

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "chrome": "50"
                }
            }
        ]
    ]
}

Current and expected behavior

Current behavior: Babel does not rename this to _this in the compiled file (see attachment). test.zip I compiled the js file with the following command: npx babel script.js --out-file script-compiled.js --source-maps --presets=@babel/preset-env

Environment

System: OS: Windows 10 10.0.19045 Binaries: Node: 18.12.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 9.3.0 - C:\Program Files\nodejs\npm.CMD

Possible solution

The proper thing to do would be for Babel to emit a sourcemap names alias to tell the debugger this should be named _this instead.

Additional context

Hello, Team!

I'm opening this ticket, because in the repo of Visual Studio Code I was told this is the right place (see bug ticket https://github.com/microsoft/vscode/issues/171672). Can you please fix this?

babel-bot commented 1 year ago

Hey @Omcsesz! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

liuxingbaoyu commented 1 year ago

sourcemap _this does not exist in the sample and I cannot reproduce it.

Omcsesz commented 1 year ago

sourcemap _this does not exist in the sample and I cannot reproduce it.

@liuxingbaoyu What is your output for npx babel script.js --out-file script-compiled.js --source-maps --presets=@babel/preset-env ?

liuxingbaoyu commented 1 year ago

What I checked was the test.zip you uploaded.

connor4312 commented 1 year ago

Missed following up on the original VS Code issue. The .babelrc for me needs some tweaks for this to reproduce for me. Please npm i in this zip, then npm run compile to see the output (which is also included in the zip)

babel-this-rename.zip

liuxingbaoyu commented 1 year ago

@connor4312 Thank you for your help!