File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -35,19 +35,17 @@ function defaultOnerror(error: Error) {
35
35
throw error ;
36
36
}
37
37
38
- function parseAttributeValue ( value : string | boolean ) {
39
- const curated = ( < string > value ) . replace ( / " / ig, '' ) ;
40
- if ( curated === 'true' || curated === 'false' ) {
41
- return curated === 'true' ;
42
- }
43
- return curated ;
38
+ function parseAttributeValue ( value : string ) {
39
+ return / ^ [ ' " ] / . test ( value ) ?
40
+ value . slice ( 1 , - 1 ) :
41
+ value ;
44
42
}
45
43
46
44
function parseAttributes ( str : string ) {
47
45
const attrs = { } ;
48
46
str . split ( / \s + / ) . filter ( Boolean ) . forEach ( attr => {
49
47
const [ name , value ] = attr . split ( '=' ) ;
50
- attrs [ name ] = parseAttributeValue ( value ) ;
48
+ attrs [ name ] = value ? parseAttributeValue ( value ) : true ;
51
49
} ) ;
52
50
return attrs ;
53
51
}
Original file line number Diff line number Diff line change @@ -112,13 +112,14 @@ describe.only('preprocess', () => {
112
112
113
113
it ( 'parses attributes' , ( ) => {
114
114
const source = `
115
- <style type='text/scss' bool></style>
115
+ <style type='text/scss' data-foo="bar" bool></style>
116
116
` ;
117
117
118
118
return svelte . preprocess ( source , {
119
119
style : ( { attributes } ) => {
120
120
assert . deepEqual ( attributes , {
121
121
type : 'text/scss' ,
122
+ 'data-foo' : 'bar' ,
122
123
bool : true
123
124
} ) ;
124
125
}
You can’t perform that action at this time.
0 commit comments