@@ -9,6 +9,7 @@ import parseObjectStyles from '../util/parseObjectStyles'
99import prefixSelector from '../util/prefixSelector'
1010import wrapWithVariants from '../util/wrapWithVariants'
1111import increaseSpecificity from '../util/increaseSpecificity'
12+ import selectorParser from 'postcss-selector-parser'
1213
1314function parseStyles ( styles ) {
1415 if ( ! Array . isArray ( styles ) ) {
@@ -18,6 +19,14 @@ function parseStyles(styles) {
1819 return _ . flatMap ( styles , style => ( style instanceof Node ? style : parseObjectStyles ( style ) ) )
1920}
2021
22+ function containsClass ( value ) {
23+ return selectorParser ( selectors => {
24+ let classFound = false
25+ selectors . walkClasses ( ( ) => ( classFound = true ) )
26+ return classFound
27+ } ) . transformSync ( value )
28+ }
29+
2130export default function ( plugins , config ) {
2231 const pluginBaseStyles = [ ]
2332 const pluginComponents = [ ]
@@ -86,6 +95,12 @@ export default function(plugins, config) {
8695 if ( config . important === true ) {
8796 rule . walkDecls ( decl => ( decl . important = true ) )
8897 } else if ( typeof config . important === 'string' ) {
98+ if ( containsClass ( config . important ) ) {
99+ throw rule . error (
100+ `Classes are not allowed when using the \`important\` option with a string argument. Please use an ID instead.`
101+ )
102+ }
103+
89104 rule . selectors = rule . selectors . map ( selector => {
90105 return increaseSpecificity ( config . important , selector )
91106 } )
0 commit comments