{"record":{"id":"4da420586fde51bb","repo":"swc-project/swc","slug":"boolean-logic-in-custom-media-at-rules-is-not-sup","errorCode":null,"errorMessage":"Boolean logic in @custom-media at-rules is not supported by swc","messagePattern":"Boolean logic in @custom-media at-rules is not supported by swc","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_css_compat/src/compiler/custom_media.rs","lineNumber":242,"sourceCode":"        }\n    }\n\n    pub(crate) fn process_media_in_parens(&mut self, n: &MediaInParens) -> Option<MediaInParens> {\n        if let Some(MediaFeatureBoolean {\n            name: MediaFeatureName::ExtensionName(name),\n            ..\n        }) = n.as_feature().and_then(|feature| feature.as_boolean())\n        {\n            if let Some(custom_media) = self.medias.iter().find(|m| m.name.value == name.value) {\n                let mut new_media_condition = MediaCondition {\n                    span: DUMMY_SP,\n                    conditions: Vec::new(),\n                };\n\n                let queries = match &custom_media.media {\n                    CustomMediaQueryMediaType::Ident(_) => {\n                        // TODO make me warning, we should keep code as is in such cases\n                        unimplemented!(\n                            \"Boolean logic in @custom-media at-rules is not supported by swc\"\n                        );\n                    }\n                    CustomMediaQueryMediaType::MediaQueryList(media_query_list) => {\n                        &media_query_list.queries\n                    }\n                };\n\n                for query in queries {\n                    if query.media_type.is_some() || query.modifier.is_some() {\n                        // TODO throw a warning on multiple media types\n                        self.modifier_and_media_type =\n                            Some((query.modifier.clone(), query.media_type.clone()));\n                    }\n\n                    if let Some(condition) = &query.condition {\n                        match &**condition {\n                            MediaConditionType::All(media_condition) => {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_css_compat/src/compiler/custom_media.rs#L224-L260","documentation":"swc_css_compat lowers the Media Queries Level 5 `@custom-media` extension when the custom-media compat option is enabled. A custom media rule whose value is a bare custom-media identifier (boolean composition such as `@custom-media --a --b;`) instead of a parenthesized media query list reaches the `CustomMediaQueryMediaType::Ident` arm and panics via `unimplemented!`, because swc cannot expand ident-to-ident references.","triggerScenarios":"Enable the custom media compat pass and feed it CSS like `@custom-media --a --b;` or `@custom-media --a not --b;` — the definition body is a custom-media ident, not a media query list such as `(min-width: 100px)`.","commonSituations":"Porting stylesheets that used postcss-custom-media (which supports boolean logic); CSS written against the custom-media spec draft; enabling processCustomMedia on a large pre-existing codebase without scanning for ident-valued definitions.","solutions":["Rewrite `@custom-media --a --b;` so each rule inlines a real media query, e.g. `@custom-media --a (min-width: 1024px);`","Preprocess the stylesheet with postcss-custom-media, which fully supports boolean logic, before handing CSS to swc","Disable the `processCustomMedia` option and lower custom media in your own pipeline","File an issue or extend the `Ident` arm in crates/swc_css_compat/src/compiler/custom_media.rs upstream"],"exampleFix":"/* before */\n@custom-media --wide-screen --desktop;\n\n/* after */\n@custom-media --desktop (min-width: 1024px);\n@custom-media --wide-screen (min-width: 1024px);","handlingStrategy":"validation","validationCode":"// Scan CSS for ident-valued @custom-media definitions before enabling the pass\nconst bad = /@custom-media\\s+--[\\w-]+\\s+(--[\\w-]+)(?:\\s+(?:and|or|not)\\s+--[\\w-]+)*\\s*;/g;\nif (bad.test(css)) throw new Error('boolean logic in @custom-media is unsupported by swc');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit stylesheets for `@custom-media` rules whose body is a bare `--ident` before enabling processCustomMedia","Run postcss-custom-media in a pre-step if you rely on boolean composition","Add a CI lint that rejects ident-valued custom media definitions"],"tags":["css","custom-media","compat","unimplemented"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}