-
Notifications
You must be signed in to change notification settings - Fork 471
Improve jsx preserve output #7439
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
Changes from 4 commits
831eaa9
6ce7b1d
5715bc2
a3d4125
331765c
c0fef48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,31 +16,41 @@ let Icon = { | |
| }; | ||
|
|
||
| let _single_element_child = <div> | ||
| <h1> | ||
| {"Hello, world!"} | ||
| </h1> | ||
| <h1> | ||
| {"Hello, world!"} | ||
| </h1> | ||
| </div>; | ||
|
|
||
| let _multiple_element_children = <div> | ||
| <h1> | ||
| {"Hello, world!"} | ||
| </h1> | ||
| <Preserve_jsx_test$Icon/> | ||
| <h1> | ||
| {"Hello, world!"} | ||
| </h1> | ||
| <Preserve_jsx_test$Icon/> | ||
| </div>; | ||
|
|
||
| let _single_element_fragment = <> | ||
| {Primitive_option.some(<input/>)} | ||
| {Primitive_option.some(<input/>)} | ||
| </>; | ||
|
|
||
| let _multiple_element_fragment = <> | ||
| <input type={"text"}/> | ||
| <input type={"number"}/> | ||
| <input | ||
| type={"text"} | ||
| /> | ||
| <input | ||
| type={"number"} | ||
| /> | ||
| </>; | ||
|
|
||
| let _unary_element_with_props = <input className={"foo"} type={"text"}/>; | ||
| let _unary_element_with_props = <input | ||
| className={"foo"} | ||
| type={"text"} | ||
| />; | ||
|
|
||
| let _container_element_with_props_and_children = <div className={"foo"} title={"foo"}> | ||
| {"Hello, world!"} | ||
| let _container_element_with_props_and_children = <div | ||
| className={"foo"} | ||
| title={"foo"} | ||
| > | ||
| {"Hello, world!"} | ||
| </div>; | ||
|
|
||
| let baseProps = { | ||
|
|
@@ -50,43 +60,63 @@ let baseProps = { | |
|
|
||
| let newrecord = {...baseProps}; | ||
|
|
||
| let _unary_element_with_spread_props = <input {...newrecord} type={"text"}/>; | ||
| let _unary_element_with_spread_props = <input {...newrecord} | ||
| type={"text"} | ||
| />; | ||
|
|
||
| let newrecord$1 = {...baseProps}; | ||
|
|
||
| let _container_with_spread_props = <div {...newrecord$1} title={"barry"} className={"barry"}> | ||
| {"Hello, world!"} | ||
| <input type={"text"}/> | ||
| let _container_with_spread_props = <div {...newrecord$1} | ||
| title={"barry"} | ||
| className={"barry"} | ||
| > | ||
| {"Hello, world!"} | ||
| <input | ||
cknitt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type={"text"} | ||
| /> | ||
| </div>; | ||
|
|
||
| let baseChildren = [ | ||
| <span> | ||
| {"Hello, world!"} | ||
| {"Hello, world!"} | ||
| </span>, | ||
| <span> | ||
| {"Hello, world!"} | ||
| {"Hello, world!"} | ||
| </span> | ||
| ]; | ||
|
|
||
| let _container_with_spread_children = <div className={"barry"} title={"barry"}> | ||
| {baseChildren} | ||
| let _container_with_spread_children = <div | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could/should add a line break (+ indent) before the opening tag, too?
cknitt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| className={"barry"} | ||
| title={"barry"} | ||
| > | ||
| {baseChildren} | ||
| </div>; | ||
|
|
||
| let newrecord$2 = {...baseProps}; | ||
|
|
||
| let _container_with_spread_props_and_children = <div {...newrecord$2} title={"barry"} className={"barry"}> | ||
| {baseChildren} | ||
| let _container_with_spread_props_and_children = <div {...newrecord$2} | ||
| title={"barry"} | ||
| className={"barry"} | ||
| > | ||
| {baseChildren} | ||
| </div>; | ||
|
|
||
| let newrecord$3 = {...baseProps}; | ||
|
|
||
| let _unary_element_with_spread_props_keyed = <input key={"barry-key"} {...newrecord$3} type={"text"}/>; | ||
| let _unary_element_with_spread_props_keyed = <input key={"barry-key"} {...newrecord$3} | ||
| type={"text"} | ||
| />; | ||
|
|
||
| let newrecord$4 = {...baseProps}; | ||
|
|
||
| let _container_with_spread_props_keyed = <div key={"barry-key"} {...newrecord$4} title={"barry"} className={"barry"}> | ||
| {"Hello, world!"} | ||
| <input type={"text"}/> | ||
| let _container_with_spread_props_keyed = <div key={"barry-key"} {...newrecord$4} | ||
|
||
| title={"barry"} | ||
| className={"barry"} | ||
| > | ||
| {"Hello, world!"} | ||
| <input | ||
| type={"text"} | ||
| /> | ||
| </div>; | ||
|
|
||
| let _unary_element_with_only_spread_props = <input {...baseProps} />; | ||
|
|
@@ -98,7 +128,7 @@ let A = {}; | |
|
|
||
| function Preserve_jsx_test$B(props) { | ||
| return <p> | ||
| {"Hello, world!"} | ||
| {"Hello, world!"} | ||
| </p>; | ||
| } | ||
|
|
||
|
|
@@ -107,22 +137,54 @@ let B = { | |
| }; | ||
|
|
||
| let _external_component_with_children = <QueryClientProvider> | ||
| <strong/> | ||
| <Preserve_jsx_test$B/> | ||
| <strong/> | ||
| <Preserve_jsx_test$B/> | ||
| </QueryClientProvider>; | ||
|
|
||
| function make(props) { | ||
| return <p> | ||
| {"foo"} | ||
| {props["\\\"MyWeirdProp\""]} | ||
| {"foo"} | ||
| {props["\\\"MyWeirdProp\""]} | ||
| </p>; | ||
| } | ||
|
|
||
| let MyWeirdComponent = { | ||
| make: make | ||
| }; | ||
|
|
||
| let _escaped_jsx_prop = <make MyWeirdProp={"bar"}/>; | ||
| let _escaped_jsx_prop = <make | ||
| MyWeirdProp={"bar"} | ||
| />; | ||
|
|
||
| let _large_component = <div | ||
| className={"bar"} | ||
| tabIndex={1} | ||
| title={"foo"} | ||
| onClick={param => {}} | ||
| onMouseDown={param => {}} | ||
| > | ||
| <p | ||
| className={"bar"} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible improvement: Do not add braces for string props. |
||
| tabIndex={1} | ||
| title={"foo"} | ||
| onClick={param => {}} | ||
| onMouseDown={param => {}} | ||
| > | ||
| {"Hello, world!"} | ||
| </p> | ||
| <strong | ||
| className={"bar"} | ||
| tabIndex={1} | ||
| title={"foo"} | ||
| onClick={param => {}} | ||
| onMouseDown={param => {}} | ||
| > | ||
| {"Hello, world!"} | ||
| </strong> | ||
| <p> | ||
| {5} | ||
| </p> | ||
| </div>; | ||
|
|
||
| export { | ||
| React, | ||
|
|
@@ -148,5 +210,6 @@ export { | |
| _external_component_with_children, | ||
| MyWeirdComponent, | ||
| _escaped_jsx_prop, | ||
| _large_component, | ||
| } | ||
| /* _single_element_child Not a pure module */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a further improvement, maybe we could break only if there is more than one prop?