Bug when bundling commonjs when there is code before super()
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
I encountered a bug where I get a bug under very specific circumstances:
- Only applies to CJS
- when minify is enabled
- when spliting is enabled
- when there is code before and after calling `super()` in the constructor
- when there is a field that is initialized on declaration (and not in the constructor)
**Source**
````ts
// 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**
````js
constructor(){console.log("before"),super();_class.prototype.__init.call(this);,console.log("after")}
^
````
**Error (when using the built code)**
````txt
SyntaxError: Unexpected token ','
````
**Reproduction**
- Download and unpack [super-bug.zip](https://github.com/egoist/tsup/files/15313304/super-bug.zip)
- pnpm install
- pnpm run build
- Open dist/index.js
**Context**
I found this bug while working on https://github.com/faker-js/faker/pull/2838
- https://github.com/faker-js/faker/pull/2838
Contributor guide
Assessment
This issue has not been assessed yet.