Skip to content

Commit

Permalink
refactor(css/modules): Support stable rust (#8381)
Browse files Browse the repository at this point in the history
**Related issue:**
- #8316
  • Loading branch information
magic-akari authored Dec 4, 2023
1 parent c5ac93a commit 0ff4157
Showing 2 changed files with 21 additions and 24 deletions.
10 changes: 4 additions & 6 deletions crates/swc_css_modules/src/imports.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
use swc_atoms::JsWord;
use swc_css_ast::{
ComponentValue, Declaration, DeclarationName, Ident, ImportHref, ImportPrelude, Stylesheet,
UrlValue,
ComponentValue, Declaration, DeclarationName, ImportHref, ImportPrelude, Stylesheet, UrlValue,
};
use swc_css_visit::{Visit, VisitWith};

@@ -52,10 +51,9 @@ impl Visit for Analyzer {
// composes: name from 'foo.css'
if d.value.len() >= 3 {
match (&d.value[d.value.len() - 2], &d.value[d.value.len() - 1]) {
(
ComponentValue::Ident(box Ident { value: from, .. }),
ComponentValue::Str(s),
) if &**from == "from" => {
(ComponentValue::Ident(ident), ComponentValue::Str(s))
if ident.value == "from" =>
{
self.imports.push(s.value.clone());
}
_ => (),
35 changes: 17 additions & 18 deletions crates/swc_css_modules/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(box_patterns)]

use rustc_hash::FxHashMap;
use swc_atoms::JsWord;
use swc_common::{util::take::Take, Span};
@@ -275,10 +273,9 @@ where
// composes: name from 'foo.css'
if n.value.len() >= 3 {
match (&n.value[n.value.len() - 2], &n.value[n.value.len() - 1]) {
(
ComponentValue::Ident(box Ident { value, .. }),
ComponentValue::Str(import_source),
) if &**value == "from" => {
(ComponentValue::Ident(ident), ComponentValue::Str(import_source))
if ident.value == "from" =>
{
for class_name in n.value.iter().take(n.value.len() - 2) {
if let ComponentValue::Ident(value) = class_name {
composes_for_current.push(CssClassName::Import {
@@ -290,10 +287,9 @@ where

return;
}
(
ComponentValue::Ident(box Ident { value: from, .. }),
ComponentValue::Ident(box Ident { value: global, .. }),
) if &**from == "from" && &**global == "global" => {
(ComponentValue::Ident(from), ComponentValue::Ident(global))
if from.value == "from" && global.value == "global" =>
{
for class_name in n.value.iter().take(n.value.len() - 2) {
if let ComponentValue::Ident(value) = class_name {
composes_for_current.push(CssClassName::Global {
@@ -308,7 +304,8 @@ where
}

for class_name in n.value.iter_mut() {
if let ComponentValue::Ident(box Ident { span, value, .. }) = class_name {
if let ComponentValue::Ident(ident) = class_name {
let Ident { span, value, .. } = &mut **ident;
let orig = value.clone();
rename(
*span,
@@ -347,13 +344,15 @@ where

for v in &mut n.value {
match v {
ComponentValue::Ident(box Ident {
span, value, raw, ..
}) => {
ComponentValue::Ident(ident) => {
if !can_change {
continue;
}

let Ident {
span, value, raw, ..
} = &mut **ident;

match &**value {
// iteration-count
"infinite" => {
@@ -447,10 +446,10 @@ where
}
"animation-name" => {
for v in &mut n.value {
if let ComponentValue::Ident(box Ident {
span, value, raw, ..
}) = v
{
if let ComponentValue::Ident(ident) = v {
let Ident {
span, value, raw, ..
} = &mut **ident;
*raw = None;

rename(

0 comments on commit 0ff4157

Please sign in to comment.