@@ -32,15 +32,18 @@ export function parseComponent (
32
32
let depth = 0
33
33
let currentBlock : ?SFCBlock = null
34
34
35
- function start ( tag : string , attrs : Array < Attribute > ) {
36
- depth ++
37
- if ( depth > 1 ) {
38
- return
39
- }
40
- if ( isSpecialTag ( tag ) ) {
35
+ function start (
36
+ tag : string ,
37
+ attrs : Array < Attribute > ,
38
+ unary : boolean ,
39
+ start : number ,
40
+ end : number
41
+ ) {
42
+ if ( isSpecialTag ( tag ) && depth === 0 ) {
41
43
currentBlock = {
42
44
type : tag ,
43
- content : ''
45
+ content : '' ,
46
+ start : end
44
47
}
45
48
checkAttrs ( currentBlock , attrs )
46
49
if ( tag === 'style' ) {
@@ -49,6 +52,7 @@ export function parseComponent (
49
52
sfc [ tag ] = currentBlock
50
53
}
51
54
}
55
+ depth ++
52
56
}
53
57
54
58
function checkAttrs ( block : SFCBlock , attrs : Array < Attribute > ) {
@@ -66,26 +70,22 @@ export function parseComponent (
66
70
}
67
71
}
68
72
69
- function end ( ) {
70
- depth --
71
- if ( options . map && currentBlock && ! currentBlock . src ) {
72
- addSourceMap ( currentBlock )
73
- }
74
- currentBlock = null
75
- }
76
-
77
- function chars ( text : string ) {
78
- if ( currentBlock ) {
79
- currentBlock . start = content . indexOf ( text )
80
- currentBlock . end = currentBlock . start + text . length
81
- text = deindent ( text )
73
+ function end ( tag : string , start : number , end : number ) {
74
+ if ( isSpecialTag ( tag ) && depth === 1 && currentBlock ) {
75
+ currentBlock . end = start
76
+ let text = deindent ( content . slice ( currentBlock . start , currentBlock . end ) )
82
77
// pad content so that linters and pre-processors can output correct
83
78
// line numbers in errors and warnings
84
79
if ( currentBlock . type !== 'template' && options . pad ) {
85
80
text = padContent ( currentBlock ) + text
86
81
}
87
82
currentBlock . content = text
83
+ if ( options . map && ! currentBlock . src ) {
84
+ addSourceMap ( currentBlock )
85
+ }
86
+ currentBlock = null
88
87
}
88
+ depth --
89
89
}
90
90
91
91
function padContent ( block : SFCBlock ) {
@@ -127,10 +127,8 @@ export function parseComponent (
127
127
}
128
128
129
129
parseHTML ( content , {
130
- isSpecialTag,
131
130
start,
132
- end,
133
- chars
131
+ end
134
132
} )
135
133
136
134
return sfc
0 commit comments