@@ -256,12 +256,12 @@ function parseMediaQuery(params) {
256256const DEFAULT_SCSS_DIRECTIVE = / ( \s * ?) ( ! d e f a u l t ) .* $ / ;
257257const GLOBAL_SCSS_DIRECTIVE = / ( \s * ?) ( ! g l o b a l ) .* $ / ;
258258
259- function parseNestedCSS ( node ) {
259+ function parseNestedCSS ( node , options ) {
260260 if ( node && typeof node === "object" ) {
261261 delete node . parent ;
262262
263263 for ( const key in node ) {
264- parseNestedCSS ( node [ key ] ) ;
264+ parseNestedCSS ( node [ key ] , options ) ;
265265 }
266266
267267 if ( ! node . type ) {
@@ -288,6 +288,16 @@ function parseNestedCSS(node) {
288288 node . raws . selector = selector ;
289289 }
290290
291+ // [email protected] parse `custom-selector` as `css-decl` 292+ if (
293+ options . parser === "css" &&
294+ node . type === "css-decl" &&
295+ node . prop === "@custom-selector"
296+ ) {
297+ selector = node . value ;
298+ node . raws . value = selector ;
299+ }
300+
291301 let value = "" ;
292302
293303 if ( typeof node . value === "string" ) {
@@ -478,7 +488,7 @@ function parseNestedCSS(node) {
478488 return node ;
479489}
480490
481- function parseWithParser ( parser , text ) {
491+ function parseWithParser ( parser , text , options ) {
482492 const parsed = parseFrontMatter ( text ) ;
483493 const { frontMatter } = parsed ;
484494 text = parsed . content ;
@@ -494,7 +504,7 @@ function parseWithParser(parser, text) {
494504 throw createError ( "(postcss) " + e . name + " " + e . reason , { start : e } ) ;
495505 }
496506
497- result = parseNestedCSS ( addTypePrefix ( result , "css-" ) ) ;
507+ result = parseNestedCSS ( addTypePrefix ( result , "css-" ) , options ) ;
498508
499509 if ( frontMatter ) {
500510 result . nodes . unshift ( frontMatter ) ;
@@ -521,20 +531,20 @@ function requireParser(isSCSSParser) {
521531 return require ( "postcss-less" ) ;
522532}
523533
524- function parse ( text , parsers , opts ) {
534+ function parse ( text , parsers , options ) {
525535 const hasExplicitParserChoice =
526- opts . parser === "less" || opts . parser === "scss" ;
527- const isSCSSParser = isSCSS ( opts . parser , text ) ;
536+ options . parser === "less" || options . parser === "scss" ;
537+ const isSCSSParser = isSCSS ( options . parser , text ) ;
528538
529539 try {
530- return parseWithParser ( requireParser ( isSCSSParser ) , text ) ;
540+ return parseWithParser ( requireParser ( isSCSSParser ) , text , options ) ;
531541 } catch ( originalError ) {
532542 if ( hasExplicitParserChoice ) {
533543 throw originalError ;
534544 }
535545
536546 try {
537- return parseWithParser ( requireParser ( ! isSCSSParser ) , text ) ;
547+ return parseWithParser ( requireParser ( ! isSCSSParser ) , text , options ) ;
538548 } catch ( _secondError ) {
539549 throw originalError ;
540550 }
0 commit comments