Commit 2c2996ed authored by Tobias Koppers's avatar Tobias Koppers

turbopack-css: report recoverable CSS parse warnings with Warning severity

Previously, UnsupportedPseudoClass and UnsupportedPseudoElement selector
errors were silently ignored, and all other unrecognized parse warnings
were also dropped. Hard structural errors (UnexpectedToken, SelectorError,
etc.) were emitted as IssueSeverity::Error.

Now:
- UnsupportedPseudoClass and UnsupportedPseudoElement emit as Warning since
  these are common in real-world CSS (vendor prefixes, custom frameworks)
  and do not prevent the stylesheet from being used.
- All previously-ignored parser warnings are surfaced as Warning instead of
  being silently discarded.
- Hard parse/transform errors remain as IssueSeverity::Error.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 6f669f1a
...@@ -3,7 +3,6 @@ use std::sync::{Arc, RwLock}; ...@@ -3,7 +3,6 @@ use std::sync::{Arc, RwLock};
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use lightningcss::{ use lightningcss::{
css_modules::{CssModuleExport, Pattern, Segment}, css_modules::{CssModuleExport, Pattern, Segment},
error::SelectorError,
stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet, ToCssResult}, stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet, ToCssResult},
targets::{BrowserslistConfig, Features, Targets}, targets::{BrowserslistConfig, Features, Targets},
traits::ToCss, traits::ToCss,
...@@ -489,49 +488,44 @@ async fn process_content( ...@@ -489,49 +488,44 @@ async fn process_content(
) { ) {
Ok(mut ss) => { Ok(mut ss) => {
for err in warnings.read().unwrap().iter() { for err in warnings.read().unwrap().iter() {
match err.kind { // Unsupported pseudo-classes/elements are common in real-world CSS
// (vendor prefixes, custom frameworks) and do not prevent the
// stylesheet from being used — treat them as recoverable warnings.
// All other previously-ignored parser warnings are also surfaced.
let severity = match err.kind {
lightningcss::error::ParserError::SelectorError(
lightningcss::error::SelectorError::UnsupportedPseudoClass(_)
| lightningcss::error::SelectorError::UnsupportedPseudoElement(_),
) => IssueSeverity::Warning,
lightningcss::error::ParserError::UnexpectedToken(_) lightningcss::error::ParserError::UnexpectedToken(_)
| lightningcss::error::ParserError::UnexpectedImportRule | lightningcss::error::ParserError::UnexpectedImportRule
| lightningcss::error::ParserError::SelectorError(..) | lightningcss::error::ParserError::SelectorError(..)
| lightningcss::error::ParserError::EndOfInput => { | lightningcss::error::ParserError::EndOfInput => IssueSeverity::Error,
let issue_source = match &err.loc {
Some(loc) => IssueSource::from_single_line_col(
source,
SourcePos {
// lightningcss::ErrorLocation is 1-based for column only
line: loc.line,
column: loc.column - 1,
},
),
None => IssueSource::from_source_only(source),
};
let severity = match &err.kind {
lightningcss::error::ParserError::SelectorError(
SelectorError::UnsupportedPseudoClass(_)
| SelectorError::UnsupportedPseudoElement(_),
) => {
// In most cases, these are new selectors not yet
// implemented in LightningCSS.
IssueSeverity::Warning
}
_ => IssueSeverity::Error,
};
ParsingIssue {
msg: err.kind.to_string().into(),
stage: IssueStage::Parse,
source: issue_source,
severity,
}
.resolved_cell()
.emit();
}
_ => { _ => IssueSeverity::Warning,
// Ignore };
}
let issue_source = match &err.loc {
Some(loc) => IssueSource::from_single_line_col(
source,
SourcePos {
// lightningcss::ErrorLocation is 1-based for column only
line: loc.line,
column: loc.column - 1,
},
),
None => IssueSource::from_source_only(source),
};
ParsingIssue {
severity,
msg: err.kind.to_string().into(),
stage: IssueStage::Parse,
source: issue_source,
} }
.resolved_cell()
.emit();
} }
let targets = *get_lightningcss_browser_targets( let targets = *get_lightningcss_browser_targets(
...@@ -561,10 +555,10 @@ async fn process_content( ...@@ -561,10 +555,10 @@ async fn process_content(
None => IssueSource::from_source_only(source), None => IssueSource::from_source_only(source),
}; };
ParsingIssue { ParsingIssue {
severity: IssueSeverity::Error,
msg: e.kind.to_string().into(), msg: e.kind.to_string().into(),
stage: IssueStage::Transform, stage: IssueStage::Transform,
source: issue_source, source: issue_source,
severity: IssueSeverity::Error,
} }
.resolved_cell() .resolved_cell()
.emit(); .emit();
...@@ -601,10 +595,10 @@ async fn process_content( ...@@ -601,10 +595,10 @@ async fn process_content(
None => IssueSource::from_source_only(source), None => IssueSource::from_source_only(source),
}; };
ParsingIssue { ParsingIssue {
severity: IssueSeverity::Error,
msg: e.kind.to_string().into(), msg: e.kind.to_string().into(),
stage: IssueStage::Parse, stage: IssueStage::Parse,
source: issue_source, source: issue_source,
severity: IssueSeverity::Error,
} }
.resolved_cell() .resolved_cell()
.emit(); .emit();
...@@ -651,6 +645,7 @@ impl CssError { ...@@ -651,6 +645,7 @@ impl CssError {
match self { match self {
CssError::CssSelectorInModuleNotPure { selector } => { CssError::CssSelectorInModuleNotPure { selector } => {
ParsingIssue { ParsingIssue {
severity: IssueSeverity::Error,
msg: format!( msg: format!(
"Selector \"{selector}\" is not pure. Pure selectors must contain at \ "Selector \"{selector}\" is not pure. Pure selectors must contain at \
least one local class or id." least one local class or id."
...@@ -659,7 +654,6 @@ impl CssError { ...@@ -659,7 +654,6 @@ impl CssError {
stage: IssueStage::Transform, stage: IssueStage::Transform,
// TODO: This should include the location of the selector in the file. // TODO: This should include the location of the selector in the file.
source: IssueSource::from_source_only(source), source: IssueSource::from_source_only(source),
severity: IssueSeverity::Error,
} }
.resolved_cell() .resolved_cell()
.emit(); .emit();
...@@ -756,10 +750,10 @@ fn generate_css_source_map(source_map: &parcel_sourcemap::SourceMap) -> Result<R ...@@ -756,10 +750,10 @@ fn generate_css_source_map(source_map: &parcel_sourcemap::SourceMap) -> Result<R
#[turbo_tasks::value] #[turbo_tasks::value]
struct ParsingIssue { struct ParsingIssue {
severity: IssueSeverity,
msg: RcStr, msg: RcStr,
stage: IssueStage, stage: IssueStage,
source: IssueSource, source: IssueSource,
severity: IssueSeverity,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment