Skip to content

Commit 460bdea

Browse files
authored
Merge pull request dev-five-git#270 from dev-five-git/optimize-join-syntax
Optimize join
2 parents 2646d6f + 87ebd4b commit 460bdea

File tree

20 files changed

+145
-131
lines changed

20 files changed

+145
-131
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ jobs:
4040
- run: |
4141
pnpm build
4242
pnpm lint
43+
# rust coverage issue
44+
echo 'max_width = 1000' > .rustfmt.toml
45+
echo 'tab_spaces = 4' >> .rustfmt.toml
46+
echo 'newline_style = "Unix"' >> .rustfmt.toml
47+
echo 'fn_call_width = 1000' >> .rustfmt.toml
48+
echo 'fn_params_layout = "Compressed"' >> .rustfmt.toml
49+
echo 'chain_width = 1000' >> .rustfmt.toml
50+
echo 'merge_derives = true' >> .rustfmt.toml
51+
echo 'use_small_heuristics = "Default"' >> .rustfmt.toml
52+
cargo fmt
4353
pnpm test
4454
- name: Benchmark
4555
run: pnpm benchmark

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,11 @@ mod tests {
640640
#[test]
641641
#[serial]
642642
fn test_debug() {
643-
assert_eq!(is_debug(), false);
643+
assert!(!is_debug());
644644
set_debug(true);
645-
assert_eq!(is_debug(), true);
645+
assert!(is_debug());
646646
set_debug(false);
647-
assert_eq!(is_debug(), false);
647+
assert!(!is_debug());
648648
}
649649

650650
#[test]

libs/css/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ mod tests {
454454
"cls",
455455
Some(&StyleSelector::Media {
456456
query: "print".to_string(),
457-
selector: None,
457+
selector: None
458458
})
459459
),
460460
".cls"
@@ -465,7 +465,7 @@ mod tests {
465465
"cls",
466466
Some(&StyleSelector::Media {
467467
query: "print".to_string(),
468-
selector: Some("&:hover".to_string()),
468+
selector: Some("&:hover".to_string())
469469
})
470470
),
471471
".cls:hover"

libs/css/src/optimize_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn optimize_value(value: &str) -> String {
114114
}
115115

116116
fn optimize_color(value: &str) -> String {
117-
let mut ret = value.to_string().to_uppercase();
117+
let mut ret = value.to_uppercase();
118118

119119
if ret.len() == 6 {
120120
let ch = ret.chars().collect::<Vec<char>>();

libs/extractor/src/css_utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn optimize_css_block(css: &str) -> String {
157157
.split(";")
158158
.map(|s| {
159159
if !s.contains(":") {
160-
s.to_string().trim().to_string()
160+
s.trim().to_string()
161161
} else {
162162
let mut iter = s.split(":");
163163
let property = iter.next().unwrap().trim();
@@ -470,11 +470,20 @@ mod tests {
470470
("50%", vec![("color", "red"), ("background", "blue")]),
471471
],
472472
)]
473+
// error case
474+
#[case(
475+
"50% { color: red ; background: blue ",
476+
vec![
477+
],
478+
)]
473479
fn test_keyframes_to_keyframes_style(
474480
#[case] input: &str,
475481
#[case] expected: Vec<(&str, Vec<(&str, &str)>)>,
476482
) {
477483
let styles = keyframes_to_keyframes_style(input);
484+
if styles.len() != expected.len() {
485+
panic!("styles.len() != expected.len()");
486+
}
478487
for (expected_key, expected_styles) in styles.iter() {
479488
let styles = expected_styles;
480489
let mut result: Vec<(&str, &str)> = styles

libs/extractor/src/extract_style/extract_dynamic_style.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use css::{
2-
optimize_value::optimize_value, sheet_to_classname,
3-
sheet_to_variable_name, style_selector::StyleSelector,
2+
optimize_value::optimize_value, sheet_to_classname, sheet_to_variable_name,
3+
style_selector::StyleSelector,
44
};
55

66
use crate::extract_style::{ExtractStyleProperty, style_property::StyleProperty};

libs/extractor/src/extract_style/extract_static_style.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use css::{
2-
optimize_value::optimize_value, sheet_to_classname,
3-
style_selector::StyleSelector,
4-
};
1+
use css::{optimize_value::optimize_value, sheet_to_classname, style_selector::StyleSelector};
52

63
use crate::{
74
extract_style::{

libs/extractor/src/extractor/extract_global_style_from_expression.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub fn extract_global_style_from_expression<'a>(
2929
t.quasis
3030
.iter()
3131
.map(|q| q.value.raw.as_str())
32-
.collect::<Vec<_>>()
33-
.join("")
32+
.collect::<String>()
3433
} else {
3534
continue;
3635
};
@@ -46,8 +45,7 @@ pub fn extract_global_style_from_expression<'a>(
4645
t.quasis
4746
.iter()
4847
.map(|q| q.value.raw.as_str())
49-
.collect::<Vec<_>>()
50-
.join("")
48+
.collect::<String>()
5149
.trim()
5250
.to_string()
5351
} else {

libs/extractor/src/extractor/extract_keyframes_from_expression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn extract_keyframes_from_expression<'a>(
2727
t.quasis
2828
.iter()
2929
.map(|q| q.value.raw.as_str())
30-
.collect::<Vec<_>>()
31-
.join("")
30+
.collect::<String>()
3231
} else if let PropertyKey::NumericLiteral(n) = &o.key {
3332
n.value.to_string()
3433
} else {

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ pub fn extract_style_from_expression<'a>(
144144
&tmp.quasis
145145
.iter()
146146
.map(|q| q.value.raw.as_str())
147-
.collect::<Vec<_>>()
148-
.join(""),
147+
.collect::<String>(),
149148
level,
150149
selector,
151150
),

0 commit comments

Comments
 (0)