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', () => {
1258
1258
} )
1259
1259
1260
1260
describe ( '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
+
1261
1299
test ( 'addVariant with string selector' , ( ) => {
1262
1300
let compiled = compile (
1263
1301
css `
Original file line number Diff line number Diff line change @@ -78,7 +78,15 @@ export function compile(
78
78
if ( node . kind !== 'rule' ) return
79
79
80
80
// 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
+
82
90
plugins . push ( loadPlugin ( node . selector . slice ( 9 , - 1 ) ) )
83
91
replaceWith ( [ ] )
84
92
return
You can’t perform that action at this time.
0 commit comments