Skip to content

Tree-shaking doesn't work for ES decorators #4334

@junbao00

Description

@junbao00

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions