From 77145ce47ab66a1dbcbd614fc66886bfbec5f4f7 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Tue, 5 Dec 2023 04:14:44 +0800 Subject: [PATCH] refactor(html/minifier): Support stable rust (#8380) **Related issue:** - #8316 --- crates/swc_html_minifier/src/lib.rs | 36 +++++++++++++---------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 472e0df30da5..7a851f99b758 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -1,5 +1,4 @@ #![deny(clippy::all)] -#![feature(box_patterns)] use std::{borrow::Cow, cmp::Ordering, mem::take}; @@ -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(); } }