@@ -1033,39 +1033,71 @@ test('Setting CSSRule.cssText does nothing', () => {
10331033} )
10341034
10351035describe ( 'CSS grammar - syntax' , ( ) => {
1036- test ( 'top-level - malformed structure' , ( ) => {
1037- // Only rules are consumed
1036+ test ( 'top-level - nothing between the start and end of a rule breaks consuming' , ( ) => {
10381037 const { cssRules } = createStyleSheet ( `
1039- color; {}
1040- color: red; {}
1041- --custom: hover {} style {}
1042- ` )
1043- expect ( cssRules ) . toHaveLength ( 1 )
1044- expect ( cssRules [ 0 ] . cssText ) . toBe ( 'style {}' )
1045- } )
1046- test ( 'top-level - orphan } in a rule prelude' , ( ) => {
1047- // It does not stop consuming a top-level rule
1048- const { cssRules } = createStyleSheet ( `
1049- @invalid } style {}
1038+ color; style {}
1039+ color: red; style {}
1040+ @invalid;
10501041 style-1 {}
1051- @invalid } @layer name;
1042+ @invalid } style {}
10521043 style-2 {}
1053- invalid } style {}
1044+ @ invalid } @layer name;
10541045 style-3 {}
1046+ invalid } style {}
1047+ style-4 {}
10551048 ` )
1056- expect ( cssRules ) . toHaveLength ( 3 )
1049+ expect ( cssRules ) . toHaveLength ( 4 )
10571050 expect ( cssRules [ 0 ] . cssText ) . toBe ( 'style-1 {}' )
10581051 expect ( cssRules [ 1 ] . cssText ) . toBe ( 'style-2 {}' )
10591052 expect ( cssRules [ 2 ] . cssText ) . toBe ( 'style-3 {}' )
1053+ expect ( cssRules [ 3 ] . cssText ) . toBe ( 'style-4 {}' )
1054+ } )
1055+ test ( 'top-level - rule starting like a custom property declaration' , ( ) => {
1056+ const { cssRules } = createStyleSheet ( `
1057+ --custom:hover {}
1058+ --custom: hover {}
1059+ --custom :hover {}
1060+ --custom a:hover {}
1061+ ` )
1062+ expect ( cssRules ) . toHaveLength ( 1 )
1063+ expect ( cssRules [ 0 ] . cssText ) . toBe ( '--custom a:hover {}' )
10601064 } )
10611065 test ( 'top-level - unclosed rule' , ( ) => {
1062- const { cssRules } = createStyleSheet ( 'style { --custom: } ' )
1066+ const { cssRules } = createStyleSheet ( 'style { --custom:' )
10631067 expect ( cssRules ) . toHaveLength ( 1 )
10641068 expect ( cssRules [ 0 ] . cssText ) . toBe ( 'style { --custom: ; }' )
10651069 } )
1066- test ( 'nested - malformed structure' , ( ) => {
1067- const styleSheet = createStyleSheet ( 'style { color; }' )
1068- expect ( styleSheet . cssRules [ 0 ] . cssText ) . toBe ( 'style {}' )
1070+ test ( 'nested - top-level ; breaks consuming a declaration and a rule' , ( ) => {
1071+ const styleSheet = createStyleSheet ( `
1072+ style {
1073+ color;
1074+ color: orange;
1075+ style: ; color: green; {}
1076+ style (; color: red;) {}
1077+ --custom: (;) 1;
1078+ }
1079+ ` )
1080+ expect ( styleSheet . cssRules [ 0 ] . cssText ) . toBe ( 'style { color: green; --custom: (;) 1; }' )
1081+ } )
1082+ test ( 'nested - top-level } breaks consuming block contents' , ( ) => {
1083+ const { cssRules } = createStyleSheet ( `
1084+ style-1 {
1085+ --custom: };
1086+ } {}
1087+ style-2 {
1088+ style } {}
1089+ style-3 {
1090+ style (}) {};
1091+ color: green;
1092+ }
1093+ style-4 {}
1094+ }
1095+ ` )
1096+ expect ( cssRules ) . toHaveLength ( 4 )
1097+ expect ( cssRules [ 0 ] . cssText ) . toBe ( 'style-1 { --custom: ; }' )
1098+ expect ( cssRules [ 1 ] . cssText ) . toBe ( 'style-2 {}' )
1099+ expect ( cssRules [ 2 ] . cssText ) . toBe ( 'style-3 { color: green; }' )
1100+ expect ( cssRules [ 3 ] . cssText ) . toBe ( 'style-4 {}' )
10691101 } )
10701102 test ( 'nested - declaration with a value containing a bad token' , ( ) => {
10711103 // It is always invalid... except with forgiving grammar?
0 commit comments