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

Useless constructor not removed during minification #3464

Open
NullVoxPopuli opened this issue Oct 24, 2023 · 3 comments
Open

Useless constructor not removed during minification #3464

NullVoxPopuli opened this issue Oct 24, 2023 · 3 comments

Comments

@NullVoxPopuli
Copy link

Playground link: https://esbuild.github.io/try/#dAAwLjE5LjUAewogIG1pbmlmeTogdHJ1ZQp9AGNsYXNzIEJhciB7fQpleHBvcnQgY2xhc3MgRm9vIGV4dGVuZHMgQmFyIHsKICBjb25zdHJ1Y3RvcigpIHsKICAgIHN1cGVyKC4uLmFyZ3VtZW50cykKICB9Cn0

Expected

class r{}export class Foo extends r{}

Actual

class r{}export class Foo extends r{constructor(){super(...arguments)}}

related to: #3463

@bakkot
Copy link

bakkot commented Oct 26, 2023

Those are not semantically equivalent. The latter observably uses ArrayIteratorPrototype; the former does not.

For example, if you run Array.prototype.values().__proto__.next = function(){ throw 'no'; } first, and new Foo after, only the latter will throw.

(In some browsers the former will still throw because they have not yet implemented tc39/ecma262#2216.)

@NullVoxPopuli
Copy link
Author

why would someone do that to all their iterators? 🤔
assuming people aren't trying to run prototype injection attacks against themselves, it's basically the same as

https://esbuild.github.io/try/#dAAwLjE5LjUAewogIG1pbmlmeTogdHJ1ZQp9AGNsYXNzIEJhciB7fQpleHBvcnQgY2xhc3MgRm9vIGV4dGVuZHMgQmFyIHsKICBjb25zdHJ1Y3Rvcihmb28sIGJhcikgewogICAgc3VwZXIoZm9vLCBiYXIpCiAgfQp9

which would be:

code

class Bar {}
export class Foo extends Bar {
  constructor(foo, bar) {
    super(foo, bar)
  }
}

actual

class c{}export class Foo extends c{constructor(o,r){super(o,r)}}

expected

class c{}export class Foo extends c{}

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

No branches or pull requests

3 participants