egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.46k stars 209 forks source link

Bug when bundling commonjs when there is code before super() #1124

Open ST-DDT opened 1 month ago

ST-DDT commented 1 month ago

I encountered a bug where I get a bug under very specific circumstances:

Source

// src/index.ts
class Parent {
  constructor() {}
}

class Feature {
  constructor() {}
}

export class Child extends Parent {
  feature = new Feature();

  constructor() {
    console.log("before");

    super();

    console.log("after");
  }
}

Result

constructor(){console.log("before"),super();_class.prototype.__init.call(this);,console.log("after")}
                                                                               ^

Error (when using the built code)

SyntaxError: Unexpected token ','

Reproduction

Context

I found this bug while working on https://github.com/faker-js/faker/pull/2838

Upvote & Fund

Fund with Polar