@@ -499,25 +499,26 @@ const HTML_COLGROUP_MODE = 8;
499
499
500
500
type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ;
501
501
502
+ const NO_SCOPE = /* */ 0b00 ;
503
+ const NOSCRIPT_SCOPE = /* */ 0b01 ;
504
+ const PICTURE_SCOPE = /* */ 0b10 ;
505
+
502
506
// Lets us keep track of contextual state and pick it back up after suspending.
503
507
export type FormatContext = {
504
508
insertionMode : InsertionMode , // root/svg/html/mathml/table
505
509
selectedValue : null | string | Array < string > , // the selected value(s) inside a <select>, or null outside <select>
506
- noscriptTagInScope : boolean ,
507
- pictureTagInScope : boolean ,
510
+ tagScope : number ,
508
511
} ;
509
512
510
513
function createFormatContext (
511
514
insertionMode : InsertionMode ,
512
515
selectedValue : null | string ,
513
- noscriptTagInScope : boolean ,
514
- pictureTagInScope : boolean ,
516
+ tagScope : number ,
515
517
) : FormatContext {
516
518
return {
517
519
insertionMode,
518
520
selectedValue,
519
- noscriptTagInScope ,
520
- pictureTagInScope ,
521
+ tagScope,
521
522
} ;
522
523
}
523
524
@@ -528,7 +529,7 @@ export function createRootFormatContext(namespaceURI?: string): FormatContext {
528
529
: namespaceURI === 'http://www.w3.org/1998/Math/MathML'
529
530
? MATHML_MODE
530
531
: ROOT_HTML_MODE ;
531
- return createFormatContext ( insertionMode , null , false , false ) ;
532
+ return createFormatContext ( insertionMode , null , NO_SCOPE ) ;
532
533
}
533
534
534
535
export function getChildFormatContext (
@@ -541,98 +542,67 @@ export function getChildFormatContext(
541
542
return createFormatContext (
542
543
HTML_MODE ,
543
544
null ,
544
- true ,
545
- parentContext . pictureTagInScope ,
545
+ parentContext . tagScope | NOSCRIPT_SCOPE ,
546
546
) ;
547
547
case 'select' :
548
548
return createFormatContext (
549
549
HTML_MODE ,
550
550
props . value != null ? props . value : props . defaultValue ,
551
- parentContext . noscriptTagInScope ,
552
- parentContext . pictureTagInScope ,
551
+ parentContext . tagScope ,
553
552
) ;
554
553
case 'svg' :
555
- return createFormatContext (
556
- SVG_MODE ,
557
- null ,
558
- parentContext . noscriptTagInScope ,
559
- parentContext . pictureTagInScope ,
560
- ) ;
554
+ return createFormatContext ( SVG_MODE , null , parentContext . tagScope ) ;
561
555
case 'picture' :
562
556
return createFormatContext (
563
557
HTML_MODE ,
564
558
null ,
565
- parentContext . noscriptTagInScope ,
566
- true ,
559
+ parentContext . tagScope | PICTURE_SCOPE ,
567
560
) ;
568
561
case 'math' :
569
- return createFormatContext (
570
- MATHML_MODE ,
571
- null ,
572
- parentContext . noscriptTagInScope ,
573
- parentContext . pictureTagInScope ,
574
- ) ;
562
+ return createFormatContext ( MATHML_MODE , null , parentContext . tagScope ) ;
575
563
case 'foreignObject' :
576
- return createFormatContext (
577
- HTML_MODE ,
578
- null ,
579
- parentContext . noscriptTagInScope ,
580
- parentContext . pictureTagInScope ,
581
- ) ;
564
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
582
565
// Table parents are special in that their children can only be created at all if they're
583
566
// wrapped in a table parent. So we need to encode that we're entering this mode.
584
567
case 'table' :
585
- return createFormatContext (
586
- HTML_TABLE_MODE ,
587
- null ,
588
- parentContext . noscriptTagInScope ,
589
- parentContext . pictureTagInScope ,
590
- ) ;
568
+ return createFormatContext ( HTML_TABLE_MODE , null , parentContext . tagScope ) ;
591
569
case 'thead' :
592
570
case 'tbody' :
593
571
case 'tfoot' :
594
572
return createFormatContext (
595
573
HTML_TABLE_BODY_MODE ,
596
574
null ,
597
- parentContext . noscriptTagInScope ,
598
- parentContext . pictureTagInScope ,
575
+ parentContext . tagScope ,
599
576
) ;
600
577
case 'colgroup' :
601
578
return createFormatContext (
602
579
HTML_COLGROUP_MODE ,
603
580
null ,
604
- parentContext . noscriptTagInScope ,
605
- parentContext . pictureTagInScope ,
581
+ parentContext . tagScope ,
606
582
) ;
607
583
case 'tr' :
608
584
return createFormatContext (
609
585
HTML_TABLE_ROW_MODE ,
610
586
null ,
611
- parentContext . noscriptTagInScope ,
612
- parentContext . pictureTagInScope ,
587
+ parentContext . tagScope ,
613
588
) ;
614
589
}
615
590
if ( parentContext . insertionMode >= HTML_TABLE_MODE ) {
616
591
// Whatever tag this was, it wasn't a table parent or other special parent, so we must have
617
592
// entered plain HTML again.
618
- return createFormatContext (
619
- HTML_MODE ,
620
- null ,
621
- parentContext . noscriptTagInScope ,
622
- parentContext . pictureTagInScope ,
623
- ) ;
593
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
624
594
}
625
595
if ( parentContext . insertionMode === ROOT_HTML_MODE ) {
626
596
if ( type === 'html' ) {
627
597
// We've emitted the root and is now in <html> mode.
628
- return createFormatContext ( HTML_HTML_MODE , null , false , false ) ;
598
+ return createFormatContext ( HTML_HTML_MODE , null , parentContext . tagScope ) ;
629
599
} else {
630
600
// We've emitted the root and is now in plain HTML mode.
631
- return createFormatContext ( HTML_MODE , null , false , false ) ;
601
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
632
602
}
633
603
} else if ( parentContext . insertionMode === HTML_HTML_MODE ) {
634
604
// We've emitted the document element and is now in plain HTML mode.
635
- return createFormatContext ( HTML_MODE , null , false , false ) ;
605
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
636
606
}
637
607
return parentContext ;
638
608
}
@@ -3256,7 +3226,7 @@ export function pushStartInstance(
3256
3226
props ,
3257
3227
renderState ,
3258
3228
formatContext . insertionMode ,
3259
- formatContext . noscriptTagInScope ,
3229
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3260
3230
)
3261
3231
: pushStartTitle ( target , props ) ;
3262
3232
case 'link' :
@@ -3267,7 +3237,7 @@ export function pushStartInstance(
3267
3237
renderState ,
3268
3238
textEmbedded ,
3269
3239
formatContext . insertionMode ,
3270
- formatContext . noscriptTagInScope ,
3240
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3271
3241
) ;
3272
3242
case 'script' :
3273
3243
return enableFloat
@@ -3277,7 +3247,7 @@ export function pushStartInstance(
3277
3247
resumableState ,
3278
3248
textEmbedded ,
3279
3249
formatContext . insertionMode ,
3280
- formatContext . noscriptTagInScope ,
3250
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3281
3251
)
3282
3252
: pushStartGenericElement ( target , props , type ) ;
3283
3253
case 'style' :
@@ -3288,7 +3258,7 @@ export function pushStartInstance(
3288
3258
renderState ,
3289
3259
textEmbedded ,
3290
3260
formatContext . insertionMode ,
3291
- formatContext . noscriptTagInScope ,
3261
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3292
3262
) ;
3293
3263
case 'meta' :
3294
3264
return pushMeta (
@@ -3297,7 +3267,7 @@ export function pushStartInstance(
3297
3267
renderState ,
3298
3268
textEmbedded ,
3299
3269
formatContext . insertionMode ,
3300
- formatContext . noscriptTagInScope ,
3270
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3301
3271
) ;
3302
3272
// Newline eating tags
3303
3273
case 'listing' :
@@ -3310,7 +3280,7 @@ export function pushStartInstance(
3310
3280
target ,
3311
3281
props ,
3312
3282
resumableState ,
3313
- formatContext . pictureTagInScope ,
3283
+ ! ! ( formatContext . tagScope & PICTURE_SCOPE ) ,
3314
3284
)
3315
3285
: pushSelfClosing ( target , props , type ) ;
3316
3286
}
0 commit comments