evanw / evanw/esbuild

mangleProps doesn't mangle TypeScript parameter property class field declaration

Open
#4,528 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

When using a TypeScript parameter property together with `mangleProps`, esbuild 0.28.2 can rename the property access generated for the parameter property without renaming the corresponding class field declaration.

This results in two different property names being used for what should be the same property.

Is this expected behavior, or should the generated class field declaration participate in property mangling together with the corresponding property access?

## Reproduction

### Input

```ts
class MyClass {
constructor(public foo: null) {}
}

new MyClass(null);
```

### Building

```js
{
mangleProps: /^/
}
```

### Output

```js
class MyClass {
constructor(foo) {
this.a = foo;
}
foo;
}
new MyClass(null);
```

The `foo` parameter property is represented as a class field. However, `this.foo` is mangled to `this.a`, while the corresponding class field declaration remains `foo`. The generated code effectively contains two different properties, `a` and `foo`.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the TypeScript reproduction with mangleProps /^/ and compare the generated class field declaration with its property access. Done means the corresponding declaration and access use one consistent mangled property name, with behavior verified against the shown output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.