File tree 3 files changed +36
-48
lines changed
compiler/compile/render_ssr/handlers
3 files changed +36
-48
lines changed Original file line number Diff line number Diff line change 1
1
import { is_void } from '../../../utils/names' ;
2
2
import { get_attribute_value , get_class_attribute_value } from './shared/get_attribute_value' ;
3
3
import { get_slot_scope } from './shared/get_slot_scope' ;
4
+ import { boolean_attributes } from './shared/boolean_attributes' ;
4
5
import Renderer , { RenderOptions } from '../Renderer' ;
5
6
import Element from '../../nodes/Element' ;
6
7
import { x } from 'code-red' ;
7
8
import Expression from '../../nodes/shared/Expression' ;
8
9
9
- // source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7
10
- const boolean_attributes = new Set ( [
11
- 'async' ,
12
- 'autocomplete' ,
13
- 'autofocus' ,
14
- 'autoplay' ,
15
- 'border' ,
16
- 'challenge' ,
17
- 'checked' ,
18
- 'compact' ,
19
- 'contenteditable' ,
20
- 'controls' ,
21
- 'default' ,
22
- 'defer' ,
23
- 'disabled' ,
24
- 'formnovalidate' ,
25
- 'frameborder' ,
26
- 'hidden' ,
27
- 'indeterminate' ,
28
- 'ismap' ,
29
- 'loop' ,
30
- 'multiple' ,
31
- 'muted' ,
32
- 'nohref' ,
33
- 'noresize' ,
34
- 'noshade' ,
35
- 'novalidate' ,
36
- 'nowrap' ,
37
- 'open' ,
38
- 'readonly' ,
39
- 'required' ,
40
- 'reversed' ,
41
- 'scoped' ,
42
- 'scrolling' ,
43
- 'seamless' ,
44
- 'selected' ,
45
- 'sortable' ,
46
- 'spellcheck' ,
47
- 'translate'
48
- ] ) ;
49
-
50
10
export default function ( node : Element , renderer : Renderer , options : RenderOptions & {
51
11
slot_scopes : Map < any , any > ;
52
12
} ) {
Original file line number Diff line number Diff line change
1
+ // source: https://html.spec.whatwg.org/multipage/indices.html
2
+ export const boolean_attributes = new Set ( [
3
+ 'allowfullscreen' ,
4
+ 'allowpaymentrequest' ,
5
+ 'async' ,
6
+ 'autofocus' ,
7
+ 'autoplay' ,
8
+ 'checked' ,
9
+ 'controls' ,
10
+ 'default' ,
11
+ 'defer' ,
12
+ 'disabled' ,
13
+ 'formnovalidate' ,
14
+ 'hidden' ,
15
+ 'ismap' ,
16
+ 'loop' ,
17
+ 'multiple' ,
18
+ 'muted' ,
19
+ 'nomodule' ,
20
+ 'novalidate' ,
21
+ 'open' ,
22
+ 'playsinline' ,
23
+ 'readonly' ,
24
+ 'required' ,
25
+ 'reversed' ,
26
+ 'selected'
27
+ ] ) ;
Original file line number Diff line number Diff line change 1
1
import { set_current_component , current_component } from './lifecycle' ;
2
2
import { run_all , blank_object } from './utils' ;
3
+ import { boolean_attributes } from '../../compiler/compile/render_ssr/handlers/shared/boolean_attributes' ;
3
4
4
5
export const invalid_attribute_name_character = / [ \s ' " > / = \u{FDD0} - \u{FDEF} \u{FFFE} \u{FFFF} \u{1FFFE} \u{1FFFF} \u{2FFFE} \u{2FFFF} \u{3FFFE} \u{3FFFF} \u{4FFFE} \u{4FFFF} \u{5FFFE} \u{5FFFF} \u{6FFFE} \u{6FFFF} \u{7FFFE} \u{7FFFF} \u{8FFFE} \u{8FFFF} \u{9FFFE} \u{9FFFF} \u{AFFFE} \u{AFFFF} \u{BFFFE} \u{BFFFF} \u{CFFFE} \u{CFFFF} \u{DFFFE} \u{DFFFF} \u{EFFFE} \u{EFFFF} \u{FFFFE} \u{FFFFF} \u{10FFFE} \u{10FFFF} ] / u;
5
6
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
@@ -20,14 +21,14 @@ export function spread(args, classes_to_add) {
20
21
if ( invalid_attribute_name_character . test ( name ) ) return ;
21
22
22
23
const value = attributes [ name ] ;
23
- if ( value == null ) return ;
24
24
if ( value === true ) str += " " + name ;
25
-
26
- const escaped = String ( value )
27
- . replace ( / " / g, '"' )
28
- . replace ( / ' / g, ''' ) ;
29
-
30
- str += " " + name + "=" + JSON . stringify ( escaped ) ;
25
+ else if ( boolean_attributes . has ( name . toLowerCase ( ) ) ) {
26
+ if ( value ) str += " " + name ;
27
+ } else if ( value != null ) {
28
+ str += " " + name + "=" + JSON . stringify ( String ( value )
29
+ . replace ( / " / g, '"' )
30
+ . replace ( / ' / g, ''' ) ) ;
31
+ }
31
32
} ) ;
32
33
33
34
return str ;
You can’t perform that action at this time.
0 commit comments