Skip to content

Commit

Permalink
refactor(html/minifier): Support stable rust (#8380)
Browse files Browse the repository at this point in the history
**Related issue:**
- #8316
  • Loading branch information
magic-akari authored Dec 4, 2023
1 parent 9b7a22c commit 77145ce
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions crates/swc_html_minifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(clippy::all)]
#![feature(box_patterns)]

use std::{borrow::Cow, cmp::Ordering, mem::take};

Expand Down Expand Up @@ -2271,32 +2270,29 @@ impl Minifier<'_> {
let swc_css_ast::Stylesheet { rules, .. } = &stylesheet;

// Because CSS is grammar free, protect for fails
if let Some(swc_css_ast::Rule::QualifiedRule(box swc_css_ast::QualifiedRule {
block,
..
})) = rules.first()
{
swc_css_codegen::Emit::emit(&mut gen, &block).unwrap();

minified = minified[1..minified.len() - 1].to_string();
} else {
let Some(swc_css_ast::Rule::QualifiedRule(qualified_rule)) = rules.first() else {
return None;
}
};

let swc_css_ast::QualifiedRule { block, .. } = &**qualified_rule;

swc_css_codegen::Emit::emit(&mut gen, &block).unwrap();

minified = minified[1..minified.len() - 1].to_string();
}
CssMinificationMode::MediaQueryList => {
let swc_css_ast::Stylesheet { rules, .. } = &stylesheet;

// Because CSS is grammar free, protect for fails
if let Some(swc_css_ast::Rule::AtRule(box swc_css_ast::AtRule {
prelude, ..
})) = rules.first()
{
swc_css_codegen::Emit::emit(&mut gen, &prelude).unwrap();

minified = minified.trim().to_string();
} else {
let Some(swc_css_ast::Rule::AtRule(at_rule)) = rules.first() else {
return None;
}
};

let swc_css_ast::AtRule { prelude, .. } = &**at_rule;

swc_css_codegen::Emit::emit(&mut gen, &prelude).unwrap();

minified = minified.trim().to_string();
}
}

Expand Down

0 comments on commit 77145ce

Please sign in to comment.