Skip to content

Commit

Permalink
refactor: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 29, 2022
1 parent fb5756c commit 021a568
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
16 changes: 4 additions & 12 deletions crates/swc_html_minifier/src/lib.rs
Expand Up @@ -1775,17 +1775,12 @@ impl VisitMut for Minifier {
}
}

if &*n.name == "class" {
if self.sort_space_separated_attribute_values
&& self.is_attribute_value_unordered_set(current_element, &n.name)
{
let mut values = value.split_whitespace().collect::<Vec<_>>();

if self.sort_space_separated_attribute_values
&& self.is_attribute_value_unordered_set(
self.current_element.as_ref().unwrap(),
&n.name,
)
{
values.sort_unstable();
}
values.sort_unstable();

value = values.join(" ");
} else if self.is_event_handler_attribute(&n.name) {
Expand Down Expand Up @@ -2070,9 +2065,6 @@ fn create_minifier(context_element: Option<&Element>, options: &MinifyOptions) -
minify_css: options.minify_css,
minify_additional_attributes: options.minify_additional_attributes.clone(),
minify_additional_scripts_content: options.minify_additional_scripts_content.clone(),
preserve_comments: options.preserve_comments.clone(),
minify_conditional_comments: options.minify_conditional_comments,
sort_unordered_attribute_values: options.sort_unordered_attribute_values,

sort_space_separated_attribute_values: options.sort_space_separated_attribute_values,
}
Expand Down
14 changes: 6 additions & 8 deletions crates/swc_html_minifier/src/option.rs
Expand Up @@ -49,14 +49,6 @@ pub struct MinifyOptions {
pub minify_json: bool,
#[serde(default = "true_by_default")]
pub minify_css: bool,
/// Allow to compress value of custom attributes,
/// i.e. `<div data-js="myFunction(100 * 2, 'foo' + 'bar')"></div>`
///
/// The first item is tag_name
/// The second is attribute name
/// The third is type of minifier
#[serde(default)]
pub minify_additional_attributes: Option<Vec<(CachedRegex, MinifierType)>>,
// Allow to compress value of custom script elements,
// i.e. `<script type="text/html"><div><!-- text --> <div data-foo="bar> Text </div></script>`
//
Expand All @@ -65,6 +57,12 @@ pub struct MinifyOptions {
// The third is type of minifier
#[serde(default)]
pub minify_additional_scripts_content: Option<Vec<(CachedRegex, MinifierType)>>,
/// Allow to compress value of custom attributes,
/// i.e. `<div data-js="myFunction(100 * 2, 'foo' + 'bar')"></div>`
///
/// The first item is tag_name
/// The second is attribute name
/// The third is type of minifier
pub minify_additional_attributes: Option<Vec<(CachedRegex, MinifierType)>>,
/// Sorting the values of `class`, `rel`, etc. of attributes
#[serde(default = "true_by_default")]
Expand Down
@@ -1,2 +1,2 @@
<!doctype html><html lang=en><title>Document</title><link rel=stylesheet href=test.css media="screen and (min-width:1024px)"><a rel="foo bar baz"></a>
<!doctype html><html lang=en><title>Document</title><link rel=stylesheet href=test.css media="screen and (min-width:1024px)"><a rel="bar baz foo"></a>
<div onclick='javascript:alert("test")'></div>

0 comments on commit 021a568

Please sign in to comment.