@@ -213,6 +213,8 @@ export const raw =
213
213
214
214
one ( tree )
215
215
216
+ resetTokenizer ( )
217
+
216
218
parser . _adoptNodes ( mock . childNodes [ 0 ] , doc )
217
219
218
220
return doc
@@ -235,6 +237,8 @@ export const raw =
235
237
236
238
one ( tree )
237
239
240
+ resetTokenizer ( )
241
+
238
242
return doc
239
243
}
240
244
@@ -336,7 +340,7 @@ export const raw =
336
340
if ( ! locationTracker ) throw new Error ( 'Expected `locationTracker`' )
337
341
338
342
// Reset preprocessor:
339
- // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/tokenizer/preprocessor.js>.
343
+ // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/tokenizer/preprocessor.js#L17 >.
340
344
preprocessor . html = undefined
341
345
preprocessor . pos = - 1
342
346
preprocessor . lastGapPos = - 1
@@ -377,18 +381,6 @@ export const raw =
377
381
preprocessor . lastChunkWritten = true
378
382
tokenizer [ tokenizer . state ] ( tokenizer . _consume ( ) )
379
383
}
380
-
381
- // Process final characters if they’re still there after hibernating.
382
- // Similar to:
383
- // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js#L95>.
384
- const token = tokenizer . currentCharacterToken
385
-
386
- if ( token ) {
387
- token . location . endLine = posTracker . line
388
- token . location . endCol = posTracker . col + 1
389
- token . location . endOffset = posTracker . offset + 1
390
- parser . _processToken ( token )
391
- }
392
384
}
393
385
394
386
/**
@@ -423,8 +415,21 @@ export const raw =
423
415
}
424
416
425
417
function resetTokenizer ( ) {
426
- /* c8 ignore next */
418
+ /* c8 ignore next 2 */
427
419
if ( ! tokenizer ) throw new Error ( 'Expected `tokenizer`' )
420
+ if ( ! posTracker ) throw new Error ( 'Expected `posTracker`' )
421
+
422
+ // Process final characters if they’re still there after hibernating.
423
+ // Similar to:
424
+ // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js#L95>.
425
+ const token = tokenizer . currentCharacterToken
426
+
427
+ if ( token ) {
428
+ token . location . endLine = posTracker . line
429
+ token . location . endCol = posTracker . col + 1
430
+ token . location . endOffset = posTracker . offset + 1
431
+ parser . _processToken ( token )
432
+ }
428
433
429
434
// Reset tokenizer:
430
435
// See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/tokenizer/index.js#L218-L234>.
0 commit comments