@@ -32,6 +32,7 @@ import {
32
32
type SizingProperty ,
33
33
} from './syntax.js' ;
34
34
import { transformCSS } from './transform.js' ;
35
+ import { cssParseErrors } from './utils.js' ;
35
36
36
37
const platformWithCache = { ...platform , _c : new Map ( ) } ;
37
38
@@ -590,14 +591,37 @@ export async function polyfill(
590
591
591
592
// fetch CSS from stylesheet and inline style
592
593
let styleData = await fetchCSS ( options . elements , options . excludeInlineStyles ) ;
593
-
594
- // pre parse CSS styles that we need to cascade
595
- const cascadeCausedChanges = cascadeCSS ( styleData ) ;
596
- if ( cascadeCausedChanges ) {
597
- styleData = transformCSS ( styleData ) ;
594
+ let rules : AnchorPositions = { } ;
595
+ let inlineStyles : Map < HTMLElement , Record < string , string > > | undefined ;
596
+ try {
597
+ // pre parse CSS styles that we need to cascade
598
+ const cascadeCausedChanges = cascadeCSS ( styleData ) ;
599
+ if ( cascadeCausedChanges ) {
600
+ styleData = transformCSS ( styleData ) ;
601
+ }
602
+ // parse CSS
603
+ const parsedCSS = await parseCSS ( styleData ) ;
604
+ rules = parsedCSS . rules ;
605
+ inlineStyles = parsedCSS . inlineStyles ;
606
+ } catch ( error ) {
607
+ if ( cssParseErrors . length > 0 ) {
608
+ // eslint-disable-next-line no-console
609
+ console . group (
610
+ `The CSS anchor positioning polyfill was not applied due to ${
611
+ cssParseErrors . length === 1
612
+ ? 'a CSS parse error.'
613
+ : 'CSS parse errors'
614
+ } .`,
615
+ ) ;
616
+ cssParseErrors . forEach ( ( err ) => {
617
+ // eslint-disable-next-line no-console
618
+ console . warn ( err . formattedMessage ) ;
619
+ } ) ;
620
+ // eslint-disable-next-line no-console
621
+ console . groupEnd ( ) ;
622
+ }
623
+ throw error ;
598
624
}
599
- // parse CSS
600
- const { rules, inlineStyles } = await parseCSS ( styleData ) ;
601
625
602
626
if ( Object . values ( rules ) . length ) {
603
627
// update source code
0 commit comments