@@ -641,6 +641,16 @@ export class XParser {
641
641
}
642
642
}
643
643
644
+ // This validates a specific case where we need to reject “template” elements
645
+ // which have “declarative shadow roots” via a “shadowrootmode” attribute.
646
+ static #validateNoDeclarativeShadowRoots( tagName , attributeName ) {
647
+ if ( tagName === 'template' && attributeName === 'shadowrootmode' ) {
648
+ const errorMessagesKey = XParser . #namedErrorsToErrorMessagesKey. get ( 'declarative-shadow-root' ) ;
649
+ const errorMessage = XParser . #errorMessages. get ( errorMessagesKey ) ;
650
+ throw new Error ( `[${ errorMessagesKey } ] ${ errorMessage } ` ) ;
651
+ }
652
+ }
653
+
644
654
// This can only happen with a “textarea” element, currently. Note that the
645
655
// subscriber is notified about this as a “text” binding not a “content”
646
656
// binding so that it correctly bind _any_ interpolated value to the
@@ -715,13 +725,7 @@ export class XParser {
715
725
static #sendBooleanTokens( onToken , tagName , stringsIndex , string , stringIndex , nextStringIndex ) {
716
726
// A boolean attribute in a start tag — “data-has-flag”
717
727
const attributeName = string . slice ( stringIndex , nextStringIndex ) ;
718
- if ( tagName === 'template' ) {
719
- if ( attributeName === 'shadowrootmode' ) {
720
- const errorMessagesKey = XParser . #namedErrorsToErrorMessagesKey. get ( 'declarative-shadow-root' ) ;
721
- const errorMessage = XParser . #errorMessages. get ( errorMessagesKey ) ;
722
- throw new Error ( `[${ errorMessagesKey } ] ${ errorMessage } ` ) ;
723
- }
724
- }
728
+ XParser . #validateNoDeclarativeShadowRoots( tagName , attributeName ) ;
725
729
onToken ( XParser . tokenTypes . booleanName , stringsIndex , stringIndex , nextStringIndex , attributeName ) ;
726
730
}
727
731
@@ -731,13 +735,7 @@ export class XParser {
731
735
// An attribute in a start tag — “data-foo="bar"”
732
736
const equalsStart = string . indexOf ( '=' , stringIndex ) ;
733
737
const attributeName = string . slice ( stringIndex , equalsStart ) ;
734
- if ( tagName === 'template' ) {
735
- if ( attributeName === 'shadowrootmode' ) {
736
- const errorMessagesKey = XParser . #namedErrorsToErrorMessagesKey. get ( 'declarative-shadow-root' ) ;
737
- const errorMessage = XParser . #errorMessages. get ( errorMessagesKey ) ;
738
- throw new Error ( `[${ errorMessagesKey } ] ${ errorMessage } ` ) ;
739
- }
740
- }
738
+ XParser . #validateNoDeclarativeShadowRoots( tagName , attributeName ) ;
741
739
const equalsEnd = equalsStart + 1 ;
742
740
const valueStart = equalsEnd + 1 ;
743
741
const valueEnd = nextStringIndex - 1 ;
0 commit comments