@@ -417,21 +417,35 @@ export class ShadowCss {
417417 return scopedP ;
418418 } ;
419419
420- const sep = / ( | > | \+ | ~ (? ! = ) ) \s * / g;
420+ const sep = / ( | > | \+ | ~ (? ! = ) | \[ | \] ) \s * / g;
421421 const scopeAfter = selector . indexOf ( _polyfillHostNoCombinator ) ;
422422
423423 let scoped = '' ;
424424 let startIndex = 0 ;
425425 let res : RegExpExecArray ;
426+ let inAttributeSelector : boolean = false ;
426427
427428 while ( ( res = sep . exec ( selector ) ) !== null ) {
428429 const separator = res [ 1 ] ;
429- const part = selector . slice ( startIndex , res . index ) . trim ( ) ;
430- // if a selector appears before :host-context it should not be shimmed as it
431- // matches on ancestor elements and not on elements in the host's shadow
432- const scopedPart = startIndex >= scopeAfter ? _scopeSelectorPart ( part ) : part ;
433- scoped += `${ scopedPart } ${ separator } ` ;
434- startIndex = sep . lastIndex ;
430+ if ( separator === '[' ) {
431+ inAttributeSelector = true ;
432+ scoped += selector . slice ( startIndex , res . index ) . trim ( ) + '[' ;
433+ startIndex = sep . lastIndex ;
434+ }
435+ if ( ! inAttributeSelector ) {
436+ const part = selector . slice ( startIndex , res . index ) . trim ( ) ;
437+ // if a selector appears before :host-context it should not be shimmed as it
438+ // matches on ancestor elements and not on elements in the host's shadow
439+ const scopedPart = startIndex >= scopeAfter ? _scopeSelectorPart ( part ) : part ;
440+ scoped += `${ scopedPart } ${ separator } ` ;
441+ startIndex = sep . lastIndex ;
442+ } else if ( separator === ']' ) {
443+ const part = selector . slice ( startIndex , res . index ) . trim ( ) + ']' ;
444+ const scopedPart = startIndex >= scopeAfter ? _scopeSelectorPart ( part ) : part ;
445+ scoped += `${ scopedPart } ` ;
446+ startIndex = sep . lastIndex ;
447+ inAttributeSelector = false ;
448+ }
435449 }
436450 return scoped + _scopeSelectorPart ( selector . substring ( startIndex ) ) ;
437451 }
0 commit comments