1- const props = require ( ' react-html-attributes' ) ;
2- const voids = [ ' area' , ' base' , 'br' , ' col' , ' embed' , 'hr' , ' img' , ' input' , ' link' , ' meta' , ' param' , ' source' , ' track' , ' wbr' ] ;
1+ const props = require ( " react-html-attributes" ) ;
2+ const voids = [ " area" , " base" , "br" , " col" , " embed" , "hr" , " img" , " input" , " link" , " meta" , " param" , " source" , " track" , " wbr" ] ;
33const types = {
44 "allowFullScreen" : "Boolean" ,
55 "async" : "Boolean" ,
66 "autoPlay" : "Boolean" ,
77 "capture" : "Boolean" ,
88 "checked" : "Boolean" ,
9+ "children" : "Array JSX" ,
910 "cols" : "Number" ,
1011 "controls" : "Boolean" ,
1112 "default" : "Boolean" ,
@@ -30,29 +31,35 @@ const types = {
3031 "selected" : "Boolean" ,
3132 "size" : "Number" ,
3233 "span" : "Number" ,
33- "start" : "Number" ,
34- "zoomAndPan" : "String"
34+ "start" : "Number"
3535} ;
36+ const reserved = [ "module" , "data" , "type" , "newtype" , "class" , "instance" , "where" , "derive" , "if" , "then" , "else" , "case" , "of" ] ;
3637
37- printRecord = ( elProps ) => `
38+ printRecord = ( elProps ) => elProps . length ? `
3839 ( ${ elProps . map ( ( p ) =>
39- `${ p } :: ${ types [ p ] || ' String' } ` ) . join ( ' \n , ' )
40+ `${ p } :: ${ types [ p ] || " String" } ` ) . join ( " \n , " )
4041 }
41- )`
42+ )` : "()"
4243
4344props . elements . html
44- . map ( ( e ) => `
45- type Props_${ e } = ${
46- props [ e ]
47- ? printRecord ( props [ e ] )
48- : '()'
49- }
45+ . map ( ( e ) => {
46+ const noChildren = voids . includes ( e ) ;
47+ const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
48+ return `
49+ type Props_${ e } = ${ printRecord (
50+ ( noChildren ? [ ] : [ "children" ] ) . concat ( props [ e ] || [ ] ) . sort ( )
51+ ) }
5052
51- ${ e }
53+ ${ symbol }
5254 :: forall attrs attrs_
53- . Union attrs attrs_ (SharedProps Props_${ e } ))
55+ . Union attrs attrs_ (SharedProps Props_${ e } )
5456 => Record attrs
55- -> Array JSX
5657 -> JSX
57- ${ e } = ${ voids . indexOf ( e ) >= 0 ? 'createElementNoChildren' : 'createElement' } "${ e } "
58- ` ) . forEach ( ( x ) => console . log ( x . replace ( / ^ \n \ { 4 } / , '' ) . replace ( / \n \ { 4 } / g, '\n' ) ) )
58+ ${ symbol } = createElement (unsafeCreateDOMComponent "${ e } ")${
59+ noChildren ? "" : `
60+
61+ ${ e } _ :: Array JSX -> JSX
62+ ${ e } _ children = ${ symbol } { children }`
63+ }
64+ ` ;
65+ } ) . forEach ( ( x ) => console . log ( x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) ) )
0 commit comments