mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +03:00
feat(css/minifier): Compress @import
at-rule (#3850)
This commit is contained in:
parent
c5ef673921
commit
ccfb4bfc0b
39
crates/swc_css_minifier/src/compress/at_rule.rs
Normal file
39
crates/swc_css_minifier/src/compress/at_rule.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use swc_css_ast::*;
|
||||
use swc_css_visit::{VisitMut, VisitMutWith};
|
||||
|
||||
pub fn compress_at_rule() -> impl VisitMut {
|
||||
CompressAtRule {}
|
||||
}
|
||||
|
||||
struct CompressAtRule {}
|
||||
|
||||
impl VisitMut for CompressAtRule {
|
||||
fn visit_mut_import_href(&mut self, import_href: &mut ImportHref) {
|
||||
import_href.visit_mut_children_with(self);
|
||||
|
||||
if let ImportHref::Url(Url {
|
||||
value: Some(value),
|
||||
modifiers,
|
||||
span,
|
||||
..
|
||||
}) = import_href
|
||||
{
|
||||
if let Some(modifiers) = modifiers {
|
||||
if !modifiers.is_empty() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let new_value = match value {
|
||||
UrlValue::Str(Str { value, .. }) => value,
|
||||
UrlValue::Raw(UrlValueRaw { value, .. }) => value,
|
||||
};
|
||||
|
||||
*import_href = ImportHref::Str(Str {
|
||||
span: *span,
|
||||
value: (&*new_value).into(),
|
||||
raw: (&*new_value).into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
pub mod alpha_value;
|
||||
pub mod angle;
|
||||
pub mod at_rule;
|
||||
pub mod declaration;
|
||||
pub mod easing_function;
|
||||
pub mod empty;
|
||||
|
@ -4,10 +4,10 @@ use swc_css_ast::*;
|
||||
use swc_css_visit::VisitMutWith;
|
||||
|
||||
use self::compress::{
|
||||
alpha_value::compress_alpha_value, angle::compress_angle, declaration::compress_declaration,
|
||||
easing_function::compress_easing_function, empty::compress_empty,
|
||||
frequency::compress_frequency, keyframes::compress_keyframes, length::compress_length,
|
||||
selector::compress_selector, time::compress_time,
|
||||
alpha_value::compress_alpha_value, angle::compress_angle, at_rule::compress_at_rule,
|
||||
declaration::compress_declaration, easing_function::compress_easing_function,
|
||||
empty::compress_empty, frequency::compress_frequency, keyframes::compress_keyframes,
|
||||
length::compress_length, selector::compress_selector, time::compress_time,
|
||||
transform_function::compress_transform_function, unicore_range::compress_unicode_range,
|
||||
url::compress_url,
|
||||
};
|
||||
@ -28,5 +28,5 @@ pub fn minify(stylesheet: &mut Stylesheet) {
|
||||
stylesheet.visit_mut_with(&mut compress_declaration());
|
||||
stylesheet.visit_mut_with(&mut compress_selector());
|
||||
stylesheet.visit_mut_with(&mut compress_keyframes());
|
||||
stylesheet.visit_mut_with(&mut compress_selector());
|
||||
stylesheet.visit_mut_with(&mut compress_at_rule());
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
@import 'custom.css';
|
||||
@import url(custom.css);
|
||||
@import url( custom.css );
|
||||
@import url('custom.css');
|
||||
@import url("custom.css");
|
||||
@import url('custo(m.css');
|
||||
@import url('custom.css') screen and (orientation:landscape);
|
||||
@import url("fallback-layout.css") supports(not (display: flex));
|
||||
@import "mystyle.css" supports(display: flex);
|
||||
@import "mystyle.css" supports((display: flex));
|
1
crates/swc_css_minifier/tests/fixture/compress-at-rule/output.min.css
vendored
Normal file
1
crates/swc_css_minifier/tests/fixture/compress-at-rule/output.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
@import"custom.css";@import"custom.css";@import"custom.css";@import"custom.css";@import"custom.css";@import"custo\\(m.css";@import"custom.css"screen and (orientation:landscape);@import"fallback-layout.css"supports(not (display:flex));@import"mystyle.css"supports(display:flex);@import"mystyle.css"supports((display:flex));
|
Loading…
Reference in New Issue
Block a user