File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ export function getAST(cssText: string) {
31
31
return parse ( cssText , {
32
32
parseAtrulePrelude : false ,
33
33
parseCustomProperty : true ,
34
+ onParseError : ( err ) => {
35
+ const errorPrelude =
36
+ 'Invalid CSS could not be parsed. CSS Anchor Positioning Polyfill was not applied.\n\n' ;
37
+ throw new Error ( errorPrelude + err . formattedMessage , { cause : err } ) ;
38
+ } ,
34
39
} ) ;
35
40
}
36
41
Original file line number Diff line number Diff line change @@ -20,3 +20,23 @@ describe('splitCommaList', () => {
20
20
] ) ;
21
21
} ) ;
22
22
} ) ;
23
+ describe ( 'getAST' , ( ) => {
24
+ it ( 'parses valid CSS' , ( ) => {
25
+ const cssText = 'a { color: red; }' ;
26
+ const ast = getAST ( cssText ) ;
27
+ expect ( ast . type ) . toBe ( 'StyleSheet' ) ;
28
+ } ) ;
29
+
30
+ it ( 'throws on invalid declaration' , ( ) => {
31
+ const cssText = 'a { color; red; } ' ;
32
+ expect ( ( ) => getAST ( cssText ) ) . toThrowError (
33
+ / I n v a l i d C S S c o u l d n o t b e p a r s e d / ,
34
+ ) ;
35
+ } ) ;
36
+ it ( 'throws on invalid selector' , ( ) => {
37
+ const cssText = 'a-[1] { color: red; } ' ;
38
+ expect ( ( ) => getAST ( cssText ) ) . toThrowError (
39
+ / I n v a l i d C S S c o u l d n o t b e p a r s e d / ,
40
+ ) ;
41
+ } ) ;
42
+ } ) ;
You can’t perform that action at this time.
0 commit comments