esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Tree-shaking doesn't work for ES decorators

Open junbao00 opened this issue 3 months ago • 0 comments

A dead simple example:

Source code:

// a.js
/* @__PURE__ */
function dec() {
}

@dec
export class A1 {
}

export class A2 {
}

export class A3 {
}

// b.js
import { A2 } from './a';

export class B extends A2 {
}

Build command:

  esbuild --bundle ./temp/b.js

The output:

// temp/a.js
function dec() {
}
var A1 = @dec class {
};
var A2 = class {
};

// temp/b.js
var B = class extends A2 {
};
export {
  B
};

The expected behavior is dec and A1 are erased.

I'm not sure if I've misunderstood, but I've searched for a long time and haven't found the answer.

Playground

junbao00 avatar Nov 17 '25 07:11 junbao00