@@ -123,20 +123,23 @@ const tokenizer = new Tokenizer(stack, {
123
123
124
124
onopentagname ( start , end ) {
125
125
const name = getSlice ( start , end )
126
- // in SFC mode, root-level tags locations are for its inner content.
127
- const startIndex = tokenizer . inSFCRoot
128
- ? end + fastForward ( end , CharCodes . Gt ) + 1
129
- : start - 1
130
126
currentOpenTag = {
131
127
type : NodeTypes . ELEMENT ,
132
128
tag : name ,
133
129
ns : currentOptions . getNamespace ( name , stack [ 0 ] , currentOptions . ns ) ,
134
130
tagType : ElementTypes . ELEMENT , // will be refined on tag close
135
131
props : [ ] ,
136
132
children : [ ] ,
137
- loc : getLoc ( startIndex , end ) ,
133
+ loc : getLoc ( start - 1 , end ) ,
138
134
codegenNode : undefined
139
135
}
136
+ if ( tokenizer . inSFCRoot ) {
137
+ // in SFC mode, generate locations for root-level tags' inner content.
138
+ currentOpenTag . innerLoc = getLoc (
139
+ end + fastForward ( end , CharCodes . Gt ) + 1 ,
140
+ end
141
+ )
142
+ }
140
143
} ,
141
144
142
145
onopentagend ( end ) {
@@ -571,20 +574,22 @@ function onText(content: string, start: number, end: number) {
571
574
572
575
function onCloseTag ( el : ElementNode , end : number , isImplied = false ) {
573
576
// attach end position
574
- if ( tokenizer . inSFCRoot ) {
575
- // SFC root tag, end position should be inner end
576
- if ( el . children . length ) {
577
- el . loc . end = extend ( { } , el . children [ el . children . length - 1 ] . loc . end )
578
- } else {
579
- el . loc . end = extend ( { } , el . loc . start )
580
- }
581
- } else if ( isImplied ) {
577
+ if ( isImplied ) {
582
578
// implied close, end should be backtracked to close
583
579
el . loc . end = tokenizer . getPos ( backTrack ( end , CharCodes . Lt ) )
584
580
} else {
585
581
el . loc . end = tokenizer . getPos ( end + fastForward ( end , CharCodes . Gt ) + 1 )
586
582
}
587
583
584
+ if ( tokenizer . inSFCRoot ) {
585
+ // SFC root tag, resolve inner end
586
+ if ( el . children . length ) {
587
+ el . innerLoc ! . end = extend ( { } , el . children [ el . children . length - 1 ] . loc . end )
588
+ } else {
589
+ el . innerLoc ! . end = extend ( { } , el . innerLoc ! . start )
590
+ }
591
+ }
592
+
588
593
// refine element type
589
594
const { tag, ns } = el
590
595
if ( ! inVPre ) {
0 commit comments