Skip to content

Commit 2fe1d7c

Browse files
committed
Update Coverage
1 parent ce2726a commit 2fe1d7c

File tree

3 files changed

+68
-20
lines changed

3 files changed

+68
-20
lines changed

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ pub fn extract_style_from_expression<'a>(
156156
}
157157

158158
if let Some(name) = name {
159-
if is_special_property(name) {
160-
return ExtractResult::default();
161-
}
162-
163159
if name == "as" {
164160
return ExtractResult {
165161
tag: Some(expression.clone_in(ast_builder.allocator)),
@@ -302,23 +298,9 @@ pub fn extract_style_from_expression<'a>(
302298
Expression::ComputedMemberExpression(mem) => {
303299
extract_style_from_member_expression(ast_builder, name, mem, level, selector)
304300
}
305-
Expression::TemplateLiteral(tmp) => {
301+
Expression::TemplateLiteral(_) => {
306302
let name = name.unwrap();
307-
if tmp.quasis.len() == 1 {
308-
ExtractResult {
309-
styles: vec![ExtractStyleProp::Static(if typo {
310-
ExtractStyleValue::Typography(tmp.quasis[0].value.raw.to_string())
311-
} else {
312-
ExtractStyleValue::Static(ExtractStaticStyle::new(
313-
name,
314-
&tmp.quasis[0].value.raw,
315-
level,
316-
selector.clone(),
317-
))
318-
})],
319-
..ExtractResult::default()
320-
}
321-
} else if typo {
303+
if typo {
322304
ExtractResult {
323305
styles: vec![ExtractStyleProp::Expression {
324306
expression: ast_builder.expression_template_literal(

libs/extractor/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,6 +2944,9 @@ e(o, { className: "a", bg: variable, style: { color: "blue" }, ...props })
29442944

29452945
reset_class_map();
29462946
assert_debug_snapshot!(ToBTreeSet::from(extract("test.js", r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:"header",children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, ExtractOption { package: "@devup-ui/react".to_string(), css_file: None }).unwrap()));
2947+
2948+
reset_class_map();
2949+
assert_debug_snapshot!(ToBTreeSet::from(extract("test.js", r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:`header`,children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, ExtractOption { package: "@devup-ui/react".to_string(), css_file: None }).unwrap()));
29472950
}
29482951

29492952
#[test]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.js\",\nr#\"\"use strict\";Object.defineProperty(exports,Symbol.toStringTag,{value:\"Module\"});const e=require(\"react/jsx-runtime\"),r=require(\"@devup-ui/react\");function t(){return e.jsxs(\"div\",{children:[e.jsx(r.Box,{_hover:{bg:\"blue\"},bg:\"$text\",color:\"red\",children:\"hello\"}),e.jsx(r.Text,{typography:`header`,children:\"typo\"}),e.jsx(r.Flex,{as:\"section\",mt:2,children:\"section\"})]})}exports.Lib=t;\"#,\nExtractOption\n{ package: \"@devup-ui/react\".to_string(), css_file: None }).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "$text",
11+
level: 0,
12+
selector: None,
13+
style_order: None,
14+
},
15+
),
16+
Static(
17+
ExtractStaticStyle {
18+
property: "background",
19+
value: "blue",
20+
level: 0,
21+
selector: Some(
22+
Selector(
23+
"&:hover",
24+
),
25+
),
26+
style_order: None,
27+
},
28+
),
29+
Static(
30+
ExtractStaticStyle {
31+
property: "color",
32+
value: "red",
33+
level: 0,
34+
selector: None,
35+
style_order: None,
36+
},
37+
),
38+
Static(
39+
ExtractStaticStyle {
40+
property: "display",
41+
value: "flex",
42+
level: 0,
43+
selector: None,
44+
style_order: Some(
45+
0,
46+
),
47+
},
48+
),
49+
Static(
50+
ExtractStaticStyle {
51+
property: "margin-top",
52+
value: "8px",
53+
level: 0,
54+
selector: None,
55+
style_order: None,
56+
},
57+
),
58+
Typography(
59+
"header",
60+
),
61+
},
62+
code: "\"use strict\";\nimport \"@devup-ui/react/devup-ui.css\";\nObject.defineProperty(exports, Symbol.toStringTag, { value: \"Module\" });\nconst e = require(\"react/jsx-runtime\"), r = require(\"@devup-ui/react\");\nfunction t() {\n\treturn e.jsxs(\"div\", { children: [\n\t\te.jsx(\"div\", {\n\t\t\tchildren: \"hello\",\n\t\t\tclassName: \"d0 d1 d2\"\n\t\t}),\n\t\te.jsx(\"span\", {\n\t\t\tchildren: \"typo\",\n\t\t\tclassName: \"typo-header\"\n\t\t}),\n\t\te.jsx(\"section\", {\n\t\t\tchildren: \"section\",\n\t\t\tclassName: \"d3 d4\"\n\t\t})\n\t] });\n}\nexports.Lib = t;\n",
63+
}

0 commit comments

Comments
 (0)