Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css/modules): Allow out-of-order class names for composes #8218

Merged
merged 9 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions crates/swc_css_modules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,23 @@ where
}
}

for class_name in n.value.iter() {
for class_name in n.value.iter_mut() {
if let ComponentValue::Ident(box Ident { span, value, .. }) = class_name {
if let Some(value) = self.data.orig_to_renamed.get(value) {
let orig = value.clone();
rename(
*span,
&mut self.config,
&mut self.result,
&mut self.data.orig_to_renamed,
&mut self.data.renamed_to_orig,
value,
);

if let Some(new_name) = self.data.orig_to_renamed.get(&orig) {
composes_for_current.push(CssClassName::Local {
name: Ident {
span: *span,
value: value.clone(),
value: new_name.clone(),
raw: None,
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.__local__child-class1 {
color: red;
}
.__local__root-class {}
.__local__child-class2 {
color: green;
}
10 changes: 10 additions & 0 deletions crates/swc_css_modules/tests/fixture/issue-7910.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.child-class1 {
color: red;
}
.root-class {
composes: child-class1;
composes: child-class2;
}
.child-class2 {
color: green;
}
28 changes: 28 additions & 0 deletions crates/swc_css_modules/tests/fixture/issue-7910.transform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"child-class1": [
{
"type": "local",
"name": "__local__child-class1"
}
],
"root-class": [
{
"type": "local",
"name": "__local__root-class"
},
{
"type": "local",
"name": "__local__child-class1"
},
{
"type": "local",
"name": "__local__child-class2"
}
],
"child-class2": [
{
"type": "local",
"name": "__local__child-class2"
}
]
}