File tree 2 files changed +13
-15
lines changed
2 files changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -36,28 +36,23 @@ export function parseComponent (
36
36
end : number
37
37
) {
38
38
if ( depth === 0 ) {
39
+ currentBlock = {
40
+ type : tag ,
41
+ content : '' ,
42
+ start : end ,
43
+ attrs : attrs . reduce ( ( cumulated , { name, value } ) => {
44
+ cumulated [ name ] = value || true
45
+ return cumulated
46
+ } , Object . create ( null ) )
47
+ }
39
48
if ( isSpecialTag ( tag ) ) {
40
- currentBlock = {
41
- type : tag ,
42
- content : '' ,
43
- start : end
44
- }
45
49
checkAttrs ( currentBlock , attrs )
46
50
if ( tag === 'style' ) {
47
51
sfc . styles . push ( currentBlock )
48
52
} else {
49
53
sfc [ tag ] = currentBlock
50
54
}
51
55
} else { // custom blocks
52
- currentBlock = {
53
- type : tag ,
54
- content : '' ,
55
- start : end ,
56
- attrs : attrs . reduce ( ( cumulated , { name, value } ) => {
57
- cumulated [ name ] = value
58
- return cumulated
59
- } , Object . create ( null ) )
60
- }
61
56
sfc . customBlocks . push ( currentBlock )
62
57
}
63
58
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ describe('Single File Component parser', () => {
16
16
<style module>
17
17
h1 { font-weight: bold }
18
18
</style>
19
+ <style bool-attr val-attr="test"></style>
19
20
<script>
20
21
export default {}
21
22
</script>
@@ -24,12 +25,14 @@ describe('Single File Component parser', () => {
24
25
</div>
25
26
` )
26
27
expect ( res . template . content . trim ( ) ) . toBe ( '<div>hi</div>' )
27
- expect ( res . styles . length ) . toBe ( 3 )
28
+ expect ( res . styles . length ) . toBe ( 4 )
28
29
expect ( res . styles [ 0 ] . src ) . toBe ( './test.css' )
29
30
expect ( res . styles [ 1 ] . lang ) . toBe ( 'stylus' )
30
31
expect ( res . styles [ 1 ] . scoped ) . toBe ( true )
31
32
expect ( res . styles [ 1 ] . content . trim ( ) ) . toBe ( 'h1\n color red\nh2\n color green' )
32
33
expect ( res . styles [ 2 ] . module ) . toBe ( true )
34
+ expect ( res . styles [ 3 ] . attrs [ 'bool-attr' ] ) . toBe ( true )
35
+ expect ( res . styles [ 3 ] . attrs [ 'val-attr' ] ) . toBe ( 'test' )
33
36
expect ( res . script . content . trim ( ) ) . toBe ( 'export default {}' )
34
37
} )
35
38
You can’t perform that action at this time.
0 commit comments