Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e553f4

Browse files
committed
consolidate tag scopes into a bitmask
1 parent c760130 commit 7e553f4

File tree

1 file changed

+28
-58
lines changed

1 file changed

+28
-58
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -499,25 +499,26 @@ const HTML_COLGROUP_MODE = 8;
499499

500500
type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
501501

502+
const NO_SCOPE = /* */ 0b00;
503+
const NOSCRIPT_SCOPE = /* */ 0b01;
504+
const PICTURE_SCOPE = /* */ 0b10;
505+
502506
// Lets us keep track of contextual state and pick it back up after suspending.
503507
export type FormatContext = {
504508
insertionMode: InsertionMode, // root/svg/html/mathml/table
505509
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,
508511
};
509512

510513
function createFormatContext(
511514
insertionMode: InsertionMode,
512515
selectedValue: null | string,
513-
noscriptTagInScope: boolean,
514-
pictureTagInScope: boolean,
516+
tagScope: number,
515517
): FormatContext {
516518
return {
517519
insertionMode,
518520
selectedValue,
519-
noscriptTagInScope,
520-
pictureTagInScope,
521+
tagScope,
521522
};
522523
}
523524

@@ -528,7 +529,7 @@ export function createRootFormatContext(namespaceURI?: string): FormatContext {
528529
: namespaceURI === 'http://www.w3.org/1998/Math/MathML'
529530
? MATHML_MODE
530531
: ROOT_HTML_MODE;
531-
return createFormatContext(insertionMode, null, false, false);
532+
return createFormatContext(insertionMode, null, NO_SCOPE);
532533
}
533534

534535
export function getChildFormatContext(
@@ -541,98 +542,67 @@ export function getChildFormatContext(
541542
return createFormatContext(
542543
HTML_MODE,
543544
null,
544-
true,
545-
parentContext.pictureTagInScope,
545+
parentContext.tagScope | NOSCRIPT_SCOPE,
546546
);
547547
case 'select':
548548
return createFormatContext(
549549
HTML_MODE,
550550
props.value != null ? props.value : props.defaultValue,
551-
parentContext.noscriptTagInScope,
552-
parentContext.pictureTagInScope,
551+
parentContext.tagScope,
553552
);
554553
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);
561555
case 'picture':
562556
return createFormatContext(
563557
HTML_MODE,
564558
null,
565-
parentContext.noscriptTagInScope,
566-
true,
559+
parentContext.tagScope | PICTURE_SCOPE,
567560
);
568561
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);
575563
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);
582565
// Table parents are special in that their children can only be created at all if they're
583566
// wrapped in a table parent. So we need to encode that we're entering this mode.
584567
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);
591569
case 'thead':
592570
case 'tbody':
593571
case 'tfoot':
594572
return createFormatContext(
595573
HTML_TABLE_BODY_MODE,
596574
null,
597-
parentContext.noscriptTagInScope,
598-
parentContext.pictureTagInScope,
575+
parentContext.tagScope,
599576
);
600577
case 'colgroup':
601578
return createFormatContext(
602579
HTML_COLGROUP_MODE,
603580
null,
604-
parentContext.noscriptTagInScope,
605-
parentContext.pictureTagInScope,
581+
parentContext.tagScope,
606582
);
607583
case 'tr':
608584
return createFormatContext(
609585
HTML_TABLE_ROW_MODE,
610586
null,
611-
parentContext.noscriptTagInScope,
612-
parentContext.pictureTagInScope,
587+
parentContext.tagScope,
613588
);
614589
}
615590
if (parentContext.insertionMode >= HTML_TABLE_MODE) {
616591
// Whatever tag this was, it wasn't a table parent or other special parent, so we must have
617592
// 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);
624594
}
625595
if (parentContext.insertionMode === ROOT_HTML_MODE) {
626596
if (type === 'html') {
627597
// 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);
629599
} else {
630600
// 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);
632602
}
633603
} else if (parentContext.insertionMode === HTML_HTML_MODE) {
634604
// 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);
636606
}
637607
return parentContext;
638608
}
@@ -3256,7 +3226,7 @@ export function pushStartInstance(
32563226
props,
32573227
renderState,
32583228
formatContext.insertionMode,
3259-
formatContext.noscriptTagInScope,
3229+
!!(formatContext.tagScope & NOSCRIPT_SCOPE),
32603230
)
32613231
: pushStartTitle(target, props);
32623232
case 'link':
@@ -3267,7 +3237,7 @@ export function pushStartInstance(
32673237
renderState,
32683238
textEmbedded,
32693239
formatContext.insertionMode,
3270-
formatContext.noscriptTagInScope,
3240+
!!(formatContext.tagScope & NOSCRIPT_SCOPE),
32713241
);
32723242
case 'script':
32733243
return enableFloat
@@ -3277,7 +3247,7 @@ export function pushStartInstance(
32773247
resumableState,
32783248
textEmbedded,
32793249
formatContext.insertionMode,
3280-
formatContext.noscriptTagInScope,
3250+
!!(formatContext.tagScope & NOSCRIPT_SCOPE),
32813251
)
32823252
: pushStartGenericElement(target, props, type);
32833253
case 'style':
@@ -3288,7 +3258,7 @@ export function pushStartInstance(
32883258
renderState,
32893259
textEmbedded,
32903260
formatContext.insertionMode,
3291-
formatContext.noscriptTagInScope,
3261+
!!(formatContext.tagScope & NOSCRIPT_SCOPE),
32923262
);
32933263
case 'meta':
32943264
return pushMeta(
@@ -3297,7 +3267,7 @@ export function pushStartInstance(
32973267
renderState,
32983268
textEmbedded,
32993269
formatContext.insertionMode,
3300-
formatContext.noscriptTagInScope,
3270+
!!(formatContext.tagScope & NOSCRIPT_SCOPE),
33013271
);
33023272
// Newline eating tags
33033273
case 'listing':
@@ -3310,7 +3280,7 @@ export function pushStartInstance(
33103280
target,
33113281
props,
33123282
resumableState,
3313-
formatContext.pictureTagInScope,
3283+
!!(formatContext.tagScope & PICTURE_SCOPE),
33143284
)
33153285
: pushSelfClosing(target, props, type);
33163286
}

0 commit comments

Comments
 (0)