@@ -20,16 +20,24 @@ let prettyFormatOpts = {
20
20
} ;
21
21
22
22
23
- function attributeHook ( name , value , context , opts ) {
24
- if ( value == null ) return '' ;
23
+ function attributeHook ( name , value , context , opts , isComponent ) {
24
+ let type = typeof value ;
25
+
26
+ // always skip null & undefined values, skip false DOM attributes, skip functions if told to
27
+ if ( value == null || ( ! isComponent && value === false ) || ( type === 'function' && ! opts . functions ) ) return '' ;
25
28
26
29
let indentChar = typeof opts . pretty === 'string' ? opts . pretty : '\t' ;
27
- if ( typeof value !== 'string' ) {
28
- preactPlugin . context = context ;
29
- preactPlugin . opts = opts ;
30
- value = prettyFormat ( value , prettyFormatOpts ) ;
31
- if ( ~ value . indexOf ( '\n' ) ) {
32
- value = `${ indent ( '\n' + value , indentChar ) } \n` ;
30
+ if ( type !== 'string' ) {
31
+ if ( type === 'function' && ! opts . functionNames ) {
32
+ value = 'Function' ;
33
+ }
34
+ else {
35
+ preactPlugin . context = context ;
36
+ preactPlugin . opts = opts ;
37
+ value = prettyFormat ( value , prettyFormatOpts ) ;
38
+ if ( ~ value . indexOf ( '\n' ) ) {
39
+ value = `${ indent ( '\n' + value , indentChar ) } \n` ;
40
+ }
33
41
}
34
42
return indent ( `\n${ name } ={${ value } }` , indentChar ) ;
35
43
}
@@ -41,6 +49,8 @@ let defaultOpts = {
41
49
attributeHook,
42
50
jsx : true ,
43
51
xml : false ,
52
+ functions : true ,
53
+ functionNames : true ,
44
54
pretty : ' '
45
55
} ;
46
56
0 commit comments