Unverified Commit 892f7df0 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: treat unknown CSS selectors as warnings (#91513)

In many cases, these are just modern selectors that aren't supported yet.
parent 512d7e81
...@@ -3,6 +3,7 @@ use std::sync::{Arc, RwLock}; ...@@ -3,6 +3,7 @@ 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,
...@@ -23,8 +24,8 @@ use turbopack_core::{ ...@@ -23,8 +24,8 @@ use turbopack_core::{
chunk::{ChunkingContext, MinifyType}, chunk::{ChunkingContext, MinifyType},
environment::Environment, environment::Environment,
issue::{ issue::{
AdditionalIssueSources, Issue, IssueExt, IssueSource, IssueStage, OptionIssueSource, AdditionalIssueSources, Issue, IssueExt, IssueSeverity, IssueSource, IssueStage,
OptionStyledString, StyledString, OptionIssueSource, OptionStyledString, StyledString,
}, },
reference::ModuleReferences, reference::ModuleReferences,
reference_type::ImportContext, reference_type::ImportContext,
...@@ -505,10 +506,23 @@ async fn process_content( ...@@ -505,10 +506,23 @@ async fn process_content(
None => IssueSource::from_source_only(source), 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 { ParsingIssue {
msg: err.kind.to_string().into(), msg: err.kind.to_string().into(),
stage: IssueStage::Parse, stage: IssueStage::Parse,
source: issue_source, source: issue_source,
severity,
} }
.resolved_cell() .resolved_cell()
.emit(); .emit();
...@@ -550,6 +564,7 @@ async fn process_content( ...@@ -550,6 +564,7 @@ async fn process_content(
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();
...@@ -589,6 +604,7 @@ async fn process_content( ...@@ -589,6 +604,7 @@ async fn process_content(
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();
...@@ -643,6 +659,7 @@ impl CssError { ...@@ -643,6 +659,7 @@ 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();
...@@ -742,10 +759,15 @@ struct ParsingIssue { ...@@ -742,10 +759,15 @@ struct ParsingIssue {
msg: RcStr, msg: RcStr,
stage: IssueStage, stage: IssueStage,
source: IssueSource, source: IssueSource,
severity: IssueSeverity,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Issue for ParsingIssue { impl Issue for ParsingIssue {
fn severity(&self) -> IssueSeverity {
self.severity
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> { fn file_path(&self) -> Vc<FileSystemPath> {
self.source.file_path() self.source.file_path()
......
error - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:25:14 Parsing CSS source code failed warning - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:25:14 Parsing CSS source code failed
21 | .carousel > *::scroll-marker { 21 | .carousel > *::scroll-marker {
22 | content: ""; 22 | content: "";
23 | } 23 | }
......
error - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:13:12 Parsing CSS source code failed warning - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:13:12 Parsing CSS source code failed
9 | .after { 9 | .after {
10 | color: green; 10 | color: green;
11 | } 11 | }
......
error - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:25:29 Parsing CSS source code failed warning - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:25:29 Parsing CSS source code failed
21 | .carousel > *::scroll-marker { 21 | .carousel > *::scroll-marker {
22 | content: ""; 22 | content: "";
23 | } 23 | }
......
error - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:21:14 Parsing CSS source code failed warning - [parse] /turbopack/crates/turbopack-tests/tests/snapshot/css/css-parse-error/input/style.css:21:14 Parsing CSS source code failed
17 | .carousel { 17 | .carousel {
18 | scroll-marker-group: after; 18 | scroll-marker-group: after;
19 | } 19 | }
......
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