Skip to content

Pass undefined for jsxDEV self inside super arguments - #65539

Closed
Josué Barros (joshbarros) wants to merge 2 commits into
microsoft:mainfrom
joshbarros:fix/65415-jsxdev-self-before-super
Closed

Josué Barros (joshbarros) wants to merge 2 commits into
microsoft:mainfrom
joshbarros:fix/65415-jsxdev-self-before-super

Conversation

@joshbarros

Copy link
Copy Markdown

Fixes #65415

The react-jsxdev transform always passed this as the __self argument. In a derived constructor, JSX in the arguments of super() is evaluated before this is available, so the emitted code threw ReferenceError: Must call super constructor ... before accessing 'this' at runtime.

This tracks when the JSX visitor is inside a super() call and passes void 0 for __self there.

The new compiler test uses a local jsx-dev-runtime and the report's derived constructor. On the unfixed compiler the emitted __self is this; with the change it is void 0.

Validation:

  • go test ./tsc/internal/testrunner -run TestLocal/jsxDevSelfInSuperArguments -count=1: fails without the change, passes with it.
  • go test ./tsc/internal/testrunner -run TestLocal -count=1: pass (full compiler suite).
  • gofmt: clean.

Drafted with assistance from an AI assistant. I reviewed the diff and ran the tests above.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:16
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 16, 2026
@typescript-automation typescript-automation Bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Nov 16, 2026
@jakebailey

Copy link
Copy Markdown
Member

If you're willing, this would be much easier to review if it were two commits, one that adds the test and baselines showing bad behavior, then one commit with the fix and baseline update showing it works.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The super-call flag mishandles nested classes and independent this scopes, causing a pre-super ReferenceError in one case and incorrect JSX __self values in others.

2 open issues
What changed in this PR

Addresses #65415 by changing the JSX development transform to avoid accessing this when JSX is evaluated inside super() arguments.

Changes:

  • Tracks traversal inside super() calls and emits void 0 for the jsxDEV self argument.
  • Adds a derived-constructor regression test with a local JSX runtime declaration and expected baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​jsxDevSelfInSuperArguments.tsx Adds the JSX-in-super() regression case.
tsc/​testdata/​baselines/​reference/​compiler/​jsxDevSelfInSuperArguments.types Records expected type information.
tsc/​testdata/​baselines/​reference/​compiler/​jsxDevSelfInSuperArguments.symbols Records expected symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​jsxDevSelfInSuperArguments.js Records emitted jsxDEV with void 0 as self.
tsc/​internal/​transformers/​jsxtransforms/​jsx.go Tracks super-call context and adjusts development JSX emission.

Review effort: Balanced

Josue Barros added 2 commits November 16, 2026 16:23
The test covers JSX in a super call, in a method inside the super arguments, and in a nested class expression. The baselines show the current behavior, which passes this before super() returns.
A super call's arguments are evaluated before this is available. Track that context and pass void 0 for __self, while restoring the enclosing state around nested super calls and resetting it in functions, methods and class bodies that have their own this.
@joshbarros
Josué Barros (joshbarros) force-pushed the fix/65415-jsxdev-self-before-super branch from eb2885b to ca757d3 Compare November 16, 2026 19:24
@joshbarros

Copy link
Copy Markdown
Author

Split into two commits as suggested: bb34a9e adds the test and baselines showing the current (bad) emit, and ca757d3 contains the fix plus the updated baseline. The nested super and nested this-scope cases now have coverage. Full compiler suite passes.

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

jsx: react-jsxdev passes this to jsxDEV before super() returns

4 participants