Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ST-DDT opened this issue May 14, 2024 · 1 comment
Open

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

ST-DDT opened this issue May 14, 2024 · 1 comment

Comments

@ST-DDT
Copy link

ST-DDT commented May 14, 2024

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

// 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

  • Download and unpack super-bug.zip
  • pnpm install
  • pnpm run build
  • Open dist/index.js

Context

I found this bug while working on faker-js/faker#2838

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@gregnr
Copy link

gregnr commented Dec 23, 2024

Also experiencing this one, though for us this occurs even when there is no code before super() (but there is code after). Temporary work around is moving class field initialization to inside the constructor (see supabase-community/pg-gateway#24).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants