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

super() call should return this, not undefined #3538

Closed
cangSDARM opened this issue Dec 12, 2023 · 5 comments
Closed

super() call should return this, not undefined #3538

cangSDARM opened this issue Dec 12, 2023 · 5 comments

Comments

@cangSDARM
Copy link

cangSDARM commented Dec 12, 2023

func (p *parser) insertStmtsAfterSuperCall(body *js_ast.FnBody, stmtsToInsert []js_ast.Stmt, superCtorRef ast.Ref) {

image

It is wrong about what super can really return. It's actually wrong

should be:
image

some materials:

microsoft/TypeScript#37847
microsoft/TypeScript#39758

@cangSDARM cangSDARM changed the title Anonymous Super breached the standard Anonymous super() Call breached the standard Dec 12, 2023
@evanw
Copy link
Owner

evanw commented Dec 12, 2023

Sorry, I'm confused. Please follow the issue reporting instructions. Provide the input to esbuild (as text, not a bitmap) as well as the esbuild options used, and describe what esbuild is doing and what you think it should be doing instead. A link to a test case on https://esbuild.github.io/try/ would be ideal. I'm marking this issue as unactionable because I don't know what to do with it.

@cangSDARM
Copy link
Author

Sorry, I'm confused. Please follow the issue reporting instructions. Provide the input to esbuild (as text, not a bitmap) as well as the esbuild options used, and describe what esbuild is doing and what you think it should be doing instead. A link to a test case on https://esbuild.github.io/try/ would be ideal. I'm marking this issue as unactionable because I don't know what to do with it.

sry, I don't know the internal logic of esbuild, so I can't give a specific configuration trigger.

// Otherwise, inject a generated "__super" helper function at the top of the

image

But for this part of the code, it should be the "__super" implementation error here. Its internal super() call should be returned

@evanw
Copy link
Owner

evanw commented Dec 12, 2023

I don't understand what this is or where it came from or how it relates to esbuild at all:

image

What is o? What is U? Did esbuild transform this? Do you have sample code that fails to run correctly when transformed by esbuild? The issue template that you deleted when you posted this issue said this:

When reporting a bug or requesting a feature, please do the following:

  • Describe what esbuild is doing incorrectly and what it should be doing instead.

  • Provide a way to reproduce the issue. The best way to do this is to demonstrate the issue on the playground (https://esbuild.github.io/try/) and paste the URL here. A link to a minimal code sample with instructions for how to reproduce the issue may also work. Issues without a way to reproduce them may be closed.

@cangSDARM
Copy link
Author

I don't understand what this is or where it came from or how it relates to esbuild at all:

image

What is o? What is U? Did esbuild transform this? Do you have sample code that fails to run correctly when transformed by esbuild? The issue template that you deleted when you posted this issue said this:

When reporting a bug or requesting a feature, please do the following:

  • Describe what esbuild is doing incorrectly and what it should be doing instead.
  • Provide a way to reproduce the issue. The best way to do this is to demonstrate the issue on the playground (https://esbuild.github.io/try/) and paste the URL here. A link to a minimal code sample with instructions for how to reproduce the issue may also work. Issues without a way to reproduce them may be closed.

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

should be:

class X extends Base {
  constructor(...props) {
    var __super = (...args) => {
      const ret = super(...args); // note the ret
      __publicField(this, "desc");
      __publicField(this, "superNames");

      return ret; // should return it
    };
    const base = __super(...props);
    this.desc = Object.getOwnPropertyDescriptors(base);
    this.superNames = Object.getOwnPropertyNames(base);
    console.log(this.superNames, Object.getOwnPropertyDescriptor(base, "any"));
  }
}

@evanw
Copy link
Owner

evanw commented Dec 12, 2023

Thank you for the additional details. I understand what you're saying now. I think it's sufficient to return this instead of needing the intermediate ret variable, so I'm going to try that approach instead.

Edit: In the meantime, I believe you can write code that uses this instead of the return value of super() as they are the same value. That should also have the benefit of working better with the existing TypeScript compiler.

@evanw evanw changed the title Anonymous super() Call breached the standard super() call should return this, not undefined Dec 12, 2023
@evanw evanw closed this as completed in 566b295 Dec 12, 2023
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