File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,26 @@ h1 { color: red }
111
111
)
112
112
} )
113
113
114
- test ( 'should keep template nodes with no content' , ( ) => {
114
+ test ( 'should parse correct range for blocks with no content (self closing) ' , ( ) => {
115
115
const { descriptor } = parse ( `<template/>` )
116
116
expect ( descriptor . template ) . toBeTruthy ( )
117
117
expect ( descriptor . template ! . content ) . toBeFalsy ( )
118
+ expect ( descriptor . template ! . loc ) . toMatchObject ( {
119
+ start : { line : 1 , column : 1 , offset : 0 } ,
120
+ end : { line : 1 , column : 1 , offset : 0 } ,
121
+ source : ''
122
+ } )
123
+ } )
124
+
125
+ test ( 'should parse correct range for blocks with no content (explicit)' , ( ) => {
126
+ const { descriptor } = parse ( `<template></template>` )
127
+ expect ( descriptor . template ) . toBeTruthy ( )
128
+ expect ( descriptor . template ! . content ) . toBeFalsy ( )
129
+ expect ( descriptor . template ! . loc ) . toMatchObject ( {
130
+ start : { line : 1 , column : 11 , offset : 10 } ,
131
+ end : { line : 1 , column : 11 , offset : 10 } ,
132
+ source : ''
133
+ } )
118
134
} )
119
135
120
136
test ( 'should ignore other nodes with no content' , ( ) => {
Original file line number Diff line number Diff line change @@ -305,6 +305,16 @@ function createBlock(
305
305
start = node . children [ 0 ] . loc . start
306
306
end = node . children [ node . children . length - 1 ] . loc . end
307
307
content = source . slice ( start . offset , end . offset )
308
+ } else {
309
+ const offset = node . loc . source . indexOf ( `</` )
310
+ if ( offset > - 1 ) {
311
+ start = {
312
+ line : start . line ,
313
+ column : start . column + offset ,
314
+ offset : start . offset + offset
315
+ }
316
+ }
317
+ end = { ...start }
308
318
}
309
319
const loc = {
310
320
source : content ,
You can’t perform that action at this time.
0 commit comments