File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -1258,6 +1258,44 @@ describe('Parsing themes values from CSS', () => {
12581258} )
12591259
12601260describe ( 'plugins' , ( ) => {
1261+ test ( '@plugin can not have a body.' , ( ) => {
1262+ expect ( ( ) =>
1263+ compile (
1264+ css `
1265+ @plugin {
1266+ color : red;
1267+ }
1268+ ` ,
1269+ {
1270+ loadPlugin : ( ) => {
1271+ return ( { addVariant } ) => {
1272+ addVariant ( 'hocus' , '&:hover, &:focus' )
1273+ }
1274+ } ,
1275+ } ,
1276+ ) . build ( [ 'hocus:underline' ] ) ,
1277+ ) . toThrowErrorMatchingInlineSnapshot ( `[Error: \`@plugin\` cannot have a body.]` )
1278+ } )
1279+
1280+ test ( '@plugin cannot be nested.' , ( ) => {
1281+ expect ( ( ) =>
1282+ compile (
1283+ css `
1284+ div {
1285+ @plugin "my-plugin" ;
1286+ }
1287+ ` ,
1288+ {
1289+ loadPlugin : ( ) => {
1290+ return ( { addVariant } ) => {
1291+ addVariant ( 'hocus' , '&:hover, &:focus' )
1292+ }
1293+ } ,
1294+ } ,
1295+ ) . build ( [ 'hocus:underline' ] ) ,
1296+ ) . toThrowErrorMatchingInlineSnapshot ( `[Error: \`@plugin\` cannot be nested.]` )
1297+ } )
1298+
12611299 test ( 'addVariant with string selector' , ( ) => {
12621300 let compiled = compile (
12631301 css `
Original file line number Diff line number Diff line change @@ -78,7 +78,15 @@ export function compile(
7878 if ( node . kind !== 'rule' ) return
7979
8080 // Collect paths from `@plugin` at-rules
81- if ( node . selector . startsWith ( '@plugin ' ) ) {
81+ if ( node . selector === '@plugin' || node . selector . startsWith ( '@plugin ' ) ) {
82+ if ( node . nodes . length > 0 ) {
83+ throw new Error ( '`@plugin` cannot have a body.' )
84+ }
85+
86+ if ( parent !== null ) {
87+ throw new Error ( '`@plugin` cannot be nested.' )
88+ }
89+
8290 plugins . push ( loadPlugin ( node . selector . slice ( 9 , - 1 ) ) )
8391 replaceWith ( [ ] )
8492 return
You can’t perform that action at this time.
0 commit comments