babel / babel/babel

[Bug]: Babel does not emit a names alias

Open
#15,362 6 comments 0 reactions 0 assignees View on GitHub
area: sourcemaps
Dominant language
TypeScript
Stars
44k
Forks
6k
Avg merge
5d 15h
Merged PRs (30d)
23

Description

### 💻

- [ ] Would you like to work on a fix?

### How are you using Babel?

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

### Input code

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

### Configuration file name

.babelrc

### Configuration

```json
{
"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](https://github.com/babel/babel/files/10488121/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?

Contributor guide

Open the contributing guide

Research direction

Reproduce the report with script.js, .babelrc, and the provided npx babel command, then inspect the generated source map and the attached output. The fix is complete when the compiled async method preserves a source-map names alias indicating that this corresponds to _this, with the behavior verified against this reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.