Skip to content

Commit 308b979

Browse files
authored
Merge pull request #36 from dev-five-git/fix-direct-selector
Fix direct select issue
2 parents 545b7e9 + 9fff520 commit 308b979

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

.changeset/hot-cherries-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Fix direct select issue

libs/extractor/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,8 @@ export {
11281128
}
11291129
)
11301130
.unwrap());
1131+
1132+
reset_class_map();
11311133
assert_debug_snapshot!(extract(
11321134
"test.js",
11331135
r#"import {Flex} from '@devup-ui/core'
@@ -1139,6 +1141,22 @@ export {
11391141
}
11401142
)
11411143
.unwrap());
1144+
1145+
reset_class_map();
1146+
assert_debug_snapshot!(extract(
1147+
"test.js",
1148+
r#"import {Center} from '@devup-ui/core'
1149+
<Center
1150+
bg={['$webBg', '$appBg', '$solutionBg'][categoryId - 1]}
1151+
>
1152+
</Center>
1153+
"#,
1154+
ExtractOption {
1155+
package: "@devup-ui/core".to_string(),
1156+
css_file: None
1157+
}
1158+
)
1159+
.unwrap());
11421160
}
11431161

11441162
#[test]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.js\",\nr#\"import {Center} from '@devup-ui/core'\n<Center\n bg={['$webBg', '$appBg', '$solutionBg'][categoryId - 1]}\n >\n </Center>\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "display",
10+
value: "flex",
11+
level: 0,
12+
selector: None,
13+
basic: true,
14+
},
15+
),
16+
Static(
17+
ExtractStaticStyle {
18+
property: "justifyContent",
19+
value: "center",
20+
level: 0,
21+
selector: None,
22+
basic: true,
23+
},
24+
),
25+
Static(
26+
ExtractStaticStyle {
27+
property: "alignItems",
28+
value: "center",
29+
level: 0,
30+
selector: None,
31+
basic: true,
32+
},
33+
),
34+
Dynamic(
35+
ExtractDynamicStyle {
36+
property: "bg",
37+
level: 0,
38+
identifier: "[\n\t\"var(--webBg)\",\n\t\"var(--appBg)\",\n\t\"var(--solutionBg)\"\n][categoryId - 1]",
39+
selector: None,
40+
},
41+
),
42+
],
43+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0 d1 d2 d3\" style={{ \"--d4\": [\n\t\"var(--webBg)\",\n\t\"var(--appBg)\",\n\t\"var(--solutionBg)\"\n][categoryId - 1] }}>\n </div>;\n",
44+
}

libs/extractor/src/style_extractor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn extract_style_from_expression<'a>(
150150
ExtractResult::Maintain
151151
}
152152
}
153-
Expression::Identifier(_) => {
153+
_ => {
154154
if let Some(name) = name {
155155
return ExtractResult::ExtractStyle(vec![
156156
ExtractStyleProp::Static(Dynamic(ExtractDynamicStyle::new(
@@ -163,7 +163,6 @@ pub fn extract_style_from_expression<'a>(
163163
}
164164
ExtractResult::Maintain
165165
}
166-
_ => ExtractResult::Maintain,
167166
}
168167
}
169168
Expression::ObjectExpression(obj) => match mem_expression {

0 commit comments

Comments
 (0)