@@ -95,18 +95,14 @@ export function getStartTagEndOffset(node: TagLikeNode, ctx: Context): number {
9595/**
9696 * Get end offset of tag
9797 */
98- export function getTagEndOffset (
99- node : TagLikeNode ,
100- parents : ParentNode [ ] ,
101- ctx : Context ,
102- ) : number {
98+ export function getTagEndOffset ( node : TagLikeNode , ctx : Context ) : number {
10399 if ( node . position ! . end ?. offset != null ) {
104100 return node . position ! . end . offset
105101 }
106102 let beforeIndex : number
107103 if ( node . children . length ) {
108104 const lastChild = node . children [ node . children . length - 1 ]
109- beforeIndex = getEndOffset ( lastChild , [ node , ... parents ] , ctx )
105+ beforeIndex = getEndOffset ( lastChild , ctx )
110106 } else {
111107 beforeIndex = getStartTagEndOffset ( node , ctx )
112108 }
@@ -125,15 +121,14 @@ export function getTagEndOffset(
125121 */
126122export function getExpressionEndOffset (
127123 node : ExpressionNode ,
128- parents : ParentNode [ ] ,
129124 ctx : Context ,
130125) : number {
131126 if ( node . position ! . end ?. offset != null ) {
132127 return node . position ! . end . offset
133128 }
134129 if ( node . children . length ) {
135130 const lastChild = node . children [ node . children . length - 1 ]
136- const beforeIndex = getEndOffset ( lastChild , [ node , ... parents ] , ctx )
131+ const beforeIndex = getEndOffset ( lastChild , ctx )
137132 const info = getTokenInfo ( ctx , [ "}" ] , beforeIndex )
138133 return info . index + info . match . length
139134 }
@@ -242,24 +237,23 @@ export function getCommentEndOffset(node: CommentNode, ctx: Context): number {
242237/**
243238 * Get content end offset
244239 */
245- export function getContentEndOffset (
246- parent : ParentNode ,
247- parents : ParentNode [ ] ,
248- ctx : Context ,
249- ) : number {
240+ export function getContentEndOffset ( parent : ParentNode , ctx : Context ) : number {
250241 const code = ctx . code
251242 if ( isTag ( parent ) ) {
252- const end = getTagEndOffset ( parent , parents , ctx )
243+ const end = getTagEndOffset ( parent , ctx )
253244 if ( code [ end - 1 ] !== ">" ) {
254245 return end
255246 }
256- const index = code . lastIndexOf ( "</" , end )
257- if ( index >= 0 && code . slice ( index , end ) . trim ( ) === parent . name ) {
247+ const index = code . lastIndexOf ( "</" , end - 1 )
248+ if (
249+ index >= 0 &&
250+ code . slice ( index + 2 , end - 1 ) . trim ( ) === parent . name
251+ ) {
258252 return index
259253 }
260254 return end
261255 } else if ( parent . type === "expression" ) {
262- const end = getExpressionEndOffset ( parent , parents , ctx )
256+ const end = getExpressionEndOffset ( parent , ctx )
263257 return code . lastIndexOf ( "}" , end )
264258 } else if ( parent . type === "root" ) {
265259 return code . length
@@ -272,25 +266,21 @@ export function getContentEndOffset(
272266 */
273267export function getSelfClosingTag (
274268 node : TagLikeNode ,
275- parents : ParentNode [ ] ,
269+ parent : ParentNode ,
276270 ctx : Context ,
277271) : null | {
278272 offset : number
279273 end : "/>" | ">"
280274} {
281- const children = node . children . filter (
282- ( c ) => c . type !== "text" || c . value . trim ( ) ,
283- )
284- if ( children . length > 0 ) {
275+ if ( node . children . length > 0 ) {
285276 return null
286277 }
287- const parent = parents [ 0 ]
288278 const code = ctx . code
289279 let nextElementIndex = code . length
290280 const childIndex = parent . children . indexOf ( node )
291281 if ( childIndex === parent . children . length - 1 ) {
292282 // last
293- nextElementIndex = getContentEndOffset ( parent , parents . slice ( 1 ) , ctx )
283+ nextElementIndex = getContentEndOffset ( parent , ctx )
294284 } else {
295285 const next = parent . children [ childIndex + 1 ]
296286 nextElementIndex = next . position ! . start . offset
@@ -310,7 +300,6 @@ export function getSelfClosingTag(
310300 */
311301export function getEndTag (
312302 node : TagLikeNode ,
313- parents : ParentNode [ ] ,
314303 ctx : Context ,
315304) : null | {
316305 offset : number
@@ -319,7 +308,7 @@ export function getEndTag(
319308 let beforeIndex : number
320309 if ( node . children . length ) {
321310 const lastChild = node . children [ node . children . length - 1 ]
322- beforeIndex = getEndOffset ( lastChild , [ node , ... parents ] , ctx )
311+ beforeIndex = getEndOffset ( lastChild , ctx )
323312 } else {
324313 beforeIndex = getStartTagEndOffset ( node , ctx )
325314 }
@@ -341,13 +330,12 @@ export function getEndTag(
341330/**
342331 * Get end offset of tag
343332 */
344- function getEndOffset ( node : Node , parents : ParentNode [ ] , ctx : Context ) : number {
333+ function getEndOffset ( node : Node , ctx : Context ) : number {
345334 if ( node . position ! . end ?. offset != null ) {
346335 return node . position ! . end . offset
347336 }
348- if ( isTag ( node ) ) return getTagEndOffset ( node , parents , ctx )
349- if ( node . type === "expression" )
350- return getExpressionEndOffset ( node , parents , ctx )
337+ if ( isTag ( node ) ) return getTagEndOffset ( node , ctx )
338+ if ( node . type === "expression" ) return getExpressionEndOffset ( node , ctx )
351339 if ( node . type === "comment" ) return getCommentEndOffset ( node , ctx )
352340 if ( node . type === "frontmatter" ) {
353341 const start = node . position ! . start . offset
0 commit comments