File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
21
* [ Python] ` importSideEffects ` shouldn't generate identifier (#3965 ) (by @alfonsogarciacaro )
22
22
* [ JS/TS] Fix #4031 : Hoist vars locally in for and while loops (@alfonsogarciacaro )
23
23
24
+ ### Changed
25
+
26
+ * [ JS/TS] In ` JSX ` , generate self closing element when element has no children (#4037 ) (by @shayanhabibi )
27
+
24
28
## 5.0.0-alpha.9 - 2025-01-28
25
29
26
30
### Fixed
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
21
* [ Python] ` importSideEffects ` shouldn't generate identifier (#3965 ) (by @alfonsogarciacaro )
22
22
* [ JS/TS] Fix #4031 : Hoist vars locally in for and while loops (@alfonsogarciacaro )
23
23
24
+ ### Changed
25
+
26
+ * [ JS/TS] In ` JSX ` , generate self closing element when element has no children (#4037 ) (by @shayanhabibi )
27
+
24
28
## 5.0.0-alpha.9 - 2025-01-28
25
29
26
30
### Fixed
Original file line number Diff line number Diff line change @@ -454,9 +454,14 @@ module PrinterExtensions =
454
454
455
455
printer.PopIndentation()
456
456
457
- printer.Print( " >" )
458
-
459
- if not ( List.isEmpty children) then
457
+ if List.isEmpty children then
458
+ // Self closing tag if el has no children. Matches expected behaviour of JSX with React/Solid etc
459
+ // https://react-cn.github.io/react/tips/self-closing-tag.html
460
+ // Self closing tag is invalid in HTML5 spec
461
+ // https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5
462
+ printer.Print( " />" )
463
+ else
464
+ printer.Print( " >" )
460
465
printer.PrintNewLine()
461
466
printer.PushIndentation()
462
467
@@ -482,9 +487,9 @@ module PrinterExtensions =
482
487
483
488
printer.PopIndentation()
484
489
485
- printer.Print( " </" )
486
- printTag componentOrTag
487
- printer.Print( " >" )
490
+ printer.Print( " </" )
491
+ printTag componentOrTag
492
+ printer.Print( " >" )
488
493
489
494
member printer.Print ( expr : Expression ) =
490
495
match expr with
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ Jest.describe("React tests", (fun () ->
46
46
Jest.expect( header) .toHaveTextContent( " 6" )
47
47
))
48
48
49
+ Jest.test( " JSX EmptyElem render self-closing tags" , ( fun () ->
50
+ let elem = Counter.CounterJSX( 5 )
51
+ Jest.expect( elem) .toStrictEqual( Fable.Core.JSX.jsx " <CounterJSX init={5} />" )
52
+ ))
53
+
49
54
Jest.test( " SpreadSheet renders correctly" , ( fun () ->
50
55
let elem = RTL.render( SpreadSheet.SpreadSheet() |> unbox)
51
56
Jest.expect( elem.container) .toMatchSnapshot()
@@ -74,4 +79,4 @@ Jest.describe("React tests", (fun () ->
74
79
let text = elem.getByTestId " text"
75
80
Jest.expect( text) .toHaveTextContent( " 3" )
76
81
))
77
- ))
82
+ ))
You can’t perform that action at this time.
0 commit comments