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

Allow using JSX before calling super when using --jsx-dev #3454

Closed
skovhus opened this issue Oct 17, 2023 · 3 comments
Closed

Allow using JSX before calling super when using --jsx-dev #3454

skovhus opened this issue Oct 17, 2023 · 3 comments

Comments

@skovhus
Copy link

skovhus commented Oct 17, 2023

esbuild does not support using JSX inside a constructor before calling super when using the --jsx-dev flag . This seems like a bug. Note that Babel supports this.

When --jsx-dev the compiled version includes this as the last argument of the JSX function, which is problematic if you have some JSX defined inside a class constructor before calling super because you cannot access this before that point.

  // Compiled code from the reproduction link
class ChildComponent extends ParentComponent {
  constructor() {
    super(/* @__PURE__ */ jsxDEV("div", { children: "Content" }, void 0, false, {
      fileName: "<stdin>",
      lineNumber: 22,
      columnNumber: 11
    }, this));
  }
}

Reproduction

Related

vitejs/vite-plugin-react#231
babel/babel#14271

@skovhus
Copy link
Author

skovhus commented Nov 14, 2023

@evanw is this something you would want esbuild to support? I might be able to help implementing this if I get a few pointers.

@evanw
Copy link
Owner

evanw commented Nov 19, 2023

FWIW TypeScript doesn't seem to handle this case either. It's too bad that there doesn't seem to be a specification for the new React JSX transform, or at least not one that adequately describes it. I can only find this which links to this which doesn't describe what __self is at all. Given how loose Babel is with this (just omit it within the entire constructor), I'm taking it that the value of __self doesn't really matter that much. It sounds like maybe the React team was using this for a migration warning at some point in the past, but now the value is perhaps irrelevant? I can have esbuild do what Babel does to fix this case. Hopefully I'm not breaking anything since I don't understand how it's supposed to be used.

@evanw evanw closed this as completed in 6c4aa2c Nov 19, 2023
@skovhus
Copy link
Author

skovhus commented Nov 19, 2023

Thanks for fixing this and adding the detailed explanation and changelog entry!

Frustrating that there isn’t a specification for this.

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