Skip to content

JSX: the default factory, an element that prints as HTML - #133

Merged
ASDAlexander77 merged 1 commit into
mainfrom
jsx-default-factory
Dec 3, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
jsx-default-factory

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

The default library's JSX factory, which the compiler calls where a .tsx program declares no h of its own (compiler PR: JSX h default factory).

  • __jsx_h(tag, props, ...children) (lib.generics.ts). It is generic, so a component is called as it is typed: with no parameters, with the attributes, or with the attributes and the children. A component's element is returned as it is; anything else it returns becomes a fragment
  • JsxElement (lib.ts): tag, props, children. Its toString() is the element as HTML: text and attribute values are escaped, a true attribute is written bare, false/null/undefined attributes are left out, className and htmlFor become class and for, and void elements get no end tag. Children are flattened, and null, undefined and booleans are left out
  • __jsx_Fragment for <>...</>
  • -mm=own: the compiler refuses the factory, and toString() throws on attributes rather than leaving them out without a word
  • Not named h: a program's own h would merge with a library declaration of that name. That merge is an existing compiler bug; a program's own sleep hits it too
  • New test tests/jsx_default_factory.ts (// not own) calls the factory directly, since tests are .ts files

Checked locally: the release libraries build for gc, rc, none and own, and the new test passes under gc, rc and none. The full tests.ps1 matrix has not been run locally.

🤖 Generated with Claude Code

- `__jsx_h(tag, props, ...children)` (lib.generics.ts): what a .tsx element calls where the program
  declares no `h` of its own (the compiler names it; under the name `h` a program's own would merge
  with it). Generic, so a component is called as it is typed: with no parameters, the attributes, or
  the attributes and the children. What a component returns is the element; anything else a fragment
- `JsxElement` (lib.ts): tag, props, children; `toString()` is the HTML: text and attribute values
  escaped, `true` attributes bare, false/null/undefined left out, className/htmlFor as class/for, void
  elements without an end tag. Children flattened, null/undefined/booleans left out, as React does
- `__jsx_Fragment`: `<>...</>`, the children alone
- -mm=own: the compiler refuses the factory (an element keeps its children); toString throws on
  attributes there rather than leaving them out
- tests/jsx_default_factory.ts calls the factory directly (tests are .ts): not own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant