Repository navigation
JSX: the default factory, an element that prints as HTML - #133
Merged
Merged
Conversation
- `__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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default library's JSX factory, which the compiler calls where a .tsx program declares no
hof its own (compiler PR: JSXhdefault 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 fragmentJsxElement(lib.ts):tag,props,children. ItstoString()is the element as HTML: text and attribute values are escaped, atrueattribute is written bare,false/null/undefinedattributes are left out,classNameandhtmlForbecomeclassandfor, and void elements get no end tag. Children are flattened, and null, undefined and booleans are left out__jsx_Fragmentfor<>...</>-mm=own: the compiler refuses the factory, andtoString()throws on attributes rather than leaving them out without a wordh: a program's ownhwould merge with a library declaration of that name. That merge is an existing compiler bug; a program's ownsleephits it tootests/jsx_default_factory.ts(// not own) calls the factory directly, since tests are .ts filesChecked 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