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

Returning Object from constructor minification #1208

Closed
MatthewAnstey opened this issue Apr 27, 2021 · 1 comment
Closed

Returning Object from constructor minification #1208

MatthewAnstey opened this issue Apr 27, 2021 · 1 comment

Comments

@MatthewAnstey
Copy link

Hello, thanks for creating such a great tool!

Was having a play around with proxies and noticed this issue with the minified code.

class A {
  constructor(opts: any) {
    console.log(opts);
  }
}

export class B extends A {
  version = 5;
  hello = () => {
    alert("Hello");
  };
  constructor(opts: any) {
    super(opts);
    return new Proxy(this, {
      set() {
        return true;
      },
    });
  }
}

When I run

esbuild foo.ts --outfile=bar.js --target=es2019 --minify

Super is not called at the top of the constructor resulting in "Uncaught ReferenceError: must call super constructor before using 'this' in derived class constructor." error. TBH I'm really not sure if this is the correct use of proxy in a constructor, but thought I'd flag.

class o {
  constructor(e) {
    console.log(e);
  }
}
export class B extends o {
  constructor(e) {
    this.version = 5;
    this.hello = () => {
      alert("Hello");
    };
    return (
      super(e),
      new Proxy(this, {
        set() {
          return !0;
        },
      })
    );
  }
}
@evanw evanw closed this as completed in 083fe24 Apr 28, 2021
@evanw
Copy link
Owner

evanw commented Apr 28, 2021

Thanks for the report. This should definitely work. The minifier bug will be fixed in the next release.

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