Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fine-rabbits-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@devup-ui/webpack-plugin": patch
"@devup-ui/next-plugin": patch
---

Support next build cache
5 changes: 5 additions & 0 deletions .changeset/proud-paws-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Fix styleOrder issue
105 changes: 49 additions & 56 deletions libs/extractor/src/gen_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,51 +220,49 @@
},
ExtractStyleProp::Expression { styles, .. } => {
for style in styles {
match style.extract() {
StyleProperty::ClassName(_) => {}
StyleProperty::Variable {
variable_name,
identifier,
..
} => {
properties.push(ObjectPropertyKind::ObjectProperty(
ast_builder.alloc_object_property(
if let StyleProperty::Variable {
variable_name,
identifier,
..
} = style.extract()

Check warning on line 227 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L223-L227

Added lines #L223 - L227 were not covered by tests
{
properties.push(ObjectPropertyKind::ObjectProperty(
ast_builder.alloc_object_property(
SPAN,
PropertyKind::Init,
PropertyKey::StringLiteral(ast_builder.alloc_string_literal(

Check warning on line 233 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L229-L233

Added lines #L229 - L233 were not covered by tests
SPAN,
PropertyKind::Init,
PropertyKey::StringLiteral(ast_builder.alloc_string_literal(
SPAN,
ast_builder.atom(&variable_name),
None,
)),
Expression::Identifier(ast_builder.alloc_identifier_reference(
ast_builder.atom(&variable_name),
None,

Check warning on line 236 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L235-L236

Added lines #L235 - L236 were not covered by tests
)),
Expression::Identifier(
ast_builder.alloc_identifier_reference(

Check warning on line 239 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L238-L239

Added lines #L238 - L239 were not covered by tests
SPAN,
ast_builder.atom(&identifier),
)),
false,
false,
false,
),
),
));
}
false,
false,
false,

Check warning on line 246 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L244-L246

Added lines #L244 - L246 were not covered by tests
),
));
}
}
}
ExtractStyleProp::MemberExpression { map, expression } => {
let mut tmp_map = BTreeMap::<String, Vec<(String, String)>>::new();
for (key, value) in map.iter() {
for style in value.extract() {
match style.extract() {
StyleProperty::ClassName(_) => {}
StyleProperty::Variable {
variable_name,
identifier,
..
} => {
tmp_map
.entry(variable_name)
.or_default()
.push((key.to_string(), identifier));
}
if let StyleProperty::Variable {
variable_name,
identifier,
..
} = style.extract()

Check warning on line 260 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L259-L260

Added lines #L259 - L260 were not covered by tests
{
tmp_map
.entry(variable_name)

Check warning on line 263 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L263

Added line #L263 was not covered by tests
.or_default()
.push((key.to_string(), identifier));
}
}
}
Expand Down Expand Up @@ -359,29 +357,24 @@
) {
if let Some(ref mut value) = style_prop.value {
if let JSXAttributeValue::ExpressionContainer(container) = value {
match container.expression {
JSXExpression::ObjectExpression(ref mut obj) => {
expression.properties.insert(
0,
ObjectPropertyKind::SpreadProperty(ast_builder.alloc_spread_element(
SPAN,
Expression::ObjectExpression(obj.clone_in(ast_builder.allocator)),
)),
);
}
JSXExpression::Identifier(ref ident) => {
expression.properties.insert(
0,
ObjectPropertyKind::SpreadProperty(ast_builder.alloc_spread_element(
SPAN,
Expression::Identifier(ident.clone_in(ast_builder.allocator)),
)),
);
}
_ => {}
};
if let Some(spread_property) = match &container.expression {
JSXExpression::ObjectExpression(obj) => Some(Expression::ObjectExpression(
obj.clone_in(ast_builder.allocator),
)),
JSXExpression::Identifier(ident) => Some(Expression::Identifier(
ident.clone_in(ast_builder.allocator),
)),
_ => None,

Check warning on line 367 in libs/extractor/src/gen_style.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/gen_style.rs#L367

Added line #L367 was not covered by tests
} {
expression.properties.insert(
0,
ObjectPropertyKind::SpreadProperty(
ast_builder.alloc_spread_element(SPAN, spread_property),
),
);
}
container.expression = JSXExpression::ObjectExpression(ast_builder.alloc(expression));
};
}
} else {
style_prop.value = Some(JSXAttributeValue::ExpressionContainer(
ast_builder.alloc_jsx_expression_container(
Expand Down
110 changes: 104 additions & 6 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box as="secton" />
<Box as="section" />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
Expand All @@ -243,7 +243,7 @@ mod tests {
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box as={"secton"} />
<Box as={"section"} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
Expand All @@ -256,7 +256,35 @@ mod tests {
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box as={`secton`} />
<Box as={`section`} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box as={"section"}></Box>
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box as={`section`}></Box>
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
Expand All @@ -268,7 +296,7 @@ mod tests {
// assert_debug_snapshot!(extract(
// "test.tsx",
// r#"import {Box} from '@devup-ui/core'
// <Box as={b ? "div":"secton"} />
// <Box as={b ? "div":"section"} />
// "#,
// ExtractOption {
// package: "@devup-ui/core".to_string(),
Expand All @@ -279,7 +307,7 @@ mod tests {
// assert_debug_snapshot!(extract(
// "test.tsx",
// r#"import {Box} from '@devup-ui/core'
// <Box as={b ? undefined:"secton"} />
// <Box as={b ? undefined:"section"} />
// "#,
// ExtractOption {
// package: "@devup-ui/core".to_string(),
Expand All @@ -291,7 +319,7 @@ mod tests {
// assert_debug_snapshot!(extract(
// "test.tsx",
// r#"import {Box} from '@devup-ui/core'
// <Box as={b ? null:"secton"} />
// <Box as={b ? null:"section"} />
// "#,
// ExtractOption {
// package: "@devup-ui/core".to_string(),
Expand Down Expand Up @@ -2850,4 +2878,74 @@ export {
.unwrap()
));
}

#[test]
#[serial]
fn style_order2() {
reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.jsx",
r#"import {Box, css} from '@devup-ui/core'
<Box styleOrder="20" p="4" _hover={{ bg: ["red", "blue"]}}
className={css({color:"white", styleOrder:"100"})}

selectors={{
"*[aria-diabled='true'] &": {
opacity: 0.5
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.jsx",
r#"import {Box, css} from '@devup-ui/core'
<Box styleOrder={"20"} p="4" _hover={{ bg: ["red", "blue"]}}
className={css({color:"white", styleOrder:("100")})}

selectors={{
"*[aria-diabled='true'] &": {
opacity: 0.5
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.jsx",
r#"import {Box, css} from '@devup-ui/core'
<Box styleOrder={`20`} p="4" _hover={{ bg: ["red", "blue"]}}
className={css({color:"white", styleOrder:`100`})}

selectors={{
"*[aria-diabled='true'] &": {
opacity: 0.5
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={\"secton\"} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={\"section\"} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {},
code: "<secton />;\n",
code: "<section />;\n",
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={`secton`} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={`section`} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {},
code: "<secton />;\n",
code: "<section />;\n",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={\"section\"}></Box>\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {},
code: "<section></section>;\n",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as={`section`}></Box>\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {},
code: "<section></section>;\n",
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as=\"secton\" />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box as=\"section\" />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {},
code: "<secton />;\n",
code: "<section />;\n",
}
Loading