File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -771,15 +771,20 @@ module.exports = (options = {}) => {
771771 }
772772 }
773773
774- atRule . nodes . forEach ( ( declaration ) => {
775- if ( declaration . type === "decl" ) {
776- localizeDeclaration ( declaration , {
777- localAliasMap,
778- options : options ,
779- global : globalMode ,
780- } ) ;
781- }
782- } ) ;
774+ // Guard matches the non-scope branch below — body-less @scope
775+ // at-rules (or postcss-misparsed inputs) have undefined .nodes;
776+ // unconditional forEach crashes.
777+ if ( atRule . nodes ) {
778+ atRule . nodes . forEach ( ( declaration ) => {
779+ if ( declaration . type === "decl" ) {
780+ localizeDeclaration ( declaration , {
781+ localAliasMap,
782+ options : options ,
783+ global : globalMode ,
784+ } ) ;
785+ }
786+ } ) ;
787+ }
783788 } else if ( atRule . nodes ) {
784789 atRule . nodes . forEach ( ( declaration ) => {
785790 if ( declaration . type === "decl" ) {
Original file line number Diff line number Diff line change @@ -2168,6 +2168,15 @@ html {
21682168}
21692169` ,
21702170 } ,
2171+ // Body-less @scope at-rules (e.g. `@scope (.foo);`) have `atRule.nodes`
2172+ // === undefined; the unconditional `atRule.nodes.forEach(...)` in the
2173+ // @scope branch threw `Cannot read properties of undefined`. The
2174+ // non-scope at-rule branch has the same guard.
2175+ {
2176+ name : "@scope at-rule — body-less @scope no longer crashes" ,
2177+ input : `@scope (.foo);` ,
2178+ expected : `@scope (:local(.foo));` ,
2179+ } ,
21712180 // The `to` keyword is case-insensitive per CSS keyword rules.
21722181 {
21732182 name : "@scope at-rule — uppercase TO keyword (#90)" ,
You can’t perform that action at this time.
0 commit comments