diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0de72254e3d..025855eebab 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -275,6 +275,9 @@ jobs: - crate: swc_css_minifier os: ubuntu-latest runner: ubuntu-latest + - crate: swc_css_modules + os: ubuntu-latest + runner: ubuntu-latest - crate: swc_css_parser os: ubuntu-latest runner: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index d4bc9f4efde..14ba71562b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3197,6 +3197,7 @@ dependencies = [ "swc_css_ast", "swc_css_codegen", "swc_css_minifier", + "swc_css_modules", "swc_css_parser", "swc_css_utils", "swc_css_visit", @@ -3280,6 +3281,23 @@ dependencies = [ "testing", ] +[[package]] +name = "swc_css_modules" +version = "0.1.0" +dependencies = [ + "rustc-hash", + "serde", + "serde_json", + "swc_atoms", + "swc_common", + "swc_css_ast", + "swc_css_codegen", + "swc_css_parser", + "swc_css_visit", + "swc_ecma_loader", + "testing", +] + [[package]] name = "swc_css_parser" version = "0.123.5" diff --git a/crates/swc_css/Cargo.toml b/crates/swc_css/Cargo.toml index 8e6e3c588ee..28c8d03bfcb 100644 --- a/crates/swc_css/Cargo.toml +++ b/crates/swc_css/Cargo.toml @@ -1,27 +1,29 @@ [package] -authors = ["강동윤 "] -description = "CSS apis for rust" +authors = ["강동윤 "] +description = "CSS apis for rust" documentation = "https://rustdoc.swc.rs/swc_css/" -edition = "2021" -license = "Apache-2.0" -name = "swc_css" -repository = "https://github.com/swc-project/swc.git" -version = "0.127.6" +edition = "2021" +license = "Apache-2.0" +name = "swc_css" +repository = "https://github.com/swc-project/swc.git" +version = "0.127.6" -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] + [package.metadata.docs.rs] + all-features = true + rustdoc-args = ["--cfg", "docsrs"] [lib] bench = false [features] minifier = ["swc_css_minifier"] +modules = ["swc_css_modules"] [dependencies] -swc_css_ast = {version = "0.114.5", path = "../swc_css_ast"} -swc_css_codegen = {version = "0.124.5", path = "../swc_css_codegen"} -swc_css_minifier = {version = "0.89.6", path = "../swc_css_minifier", optional = true} -swc_css_parser = {version = "0.123.5", path = "../swc_css_parser"} -swc_css_utils = {version = "0.111.5", path = "../swc_css_utils/"} -swc_css_visit = {version = "0.113.5", path = "../swc_css_visit"} +swc_css_ast = { version = "0.114.5", path = "../swc_css_ast" } +swc_css_codegen = { version = "0.124.5", path = "../swc_css_codegen" } +swc_css_minifier = { version = "0.89.6", path = "../swc_css_minifier", optional = true } +swc_css_modules = { version = "0.1.0", path = "../swc_css_modules", optional = true } +swc_css_parser = { version = "0.123.5", path = "../swc_css_parser" } +swc_css_utils = { version = "0.111.5", path = "../swc_css_utils/" } +swc_css_visit = { version = "0.113.5", path = "../swc_css_visit" } diff --git a/crates/swc_css/src/lib.rs b/crates/swc_css/src/lib.rs index 806df7a68d2..4a941a019cd 100644 --- a/crates/swc_css/src/lib.rs +++ b/crates/swc_css/src/lib.rs @@ -3,6 +3,9 @@ pub extern crate swc_css_codegen as codegen; #[cfg(feature = "swc_css_minifier")] #[cfg_attr(docsrs, doc(cfg(feature = "minifier")))] pub extern crate swc_css_minifier as minifier; +#[cfg(feature = "swc_css_modules")] +#[cfg_attr(docsrs, doc(cfg(feature = "modules")))] +pub extern crate swc_css_modules as modules; pub extern crate swc_css_parser as parser; pub extern crate swc_css_utils as utils; pub extern crate swc_css_visit as visit; diff --git a/crates/swc_css_ast/src/selector.rs b/crates/swc_css_ast/src/selector.rs index 6bb52f8c256..365ac2b4fb9 100644 --- a/crates/swc_css_ast/src/selector.rs +++ b/crates/swc_css_ast/src/selector.rs @@ -1,7 +1,7 @@ use is_macro::Is; use string_enum::StringEnum; use swc_atoms::JsWord; -use swc_common::{ast_node, EqIgnoreSpan, Span}; +use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span}; use crate::{Delimiter, Ident, ListOfComponentValues, Str, TokenAndSpan}; @@ -65,6 +65,15 @@ pub struct ComplexSelector { pub children: Vec, } +impl Take for ComplexSelector { + fn dummy() -> Self { + Self { + span: Take::dummy(), + children: Take::dummy(), + } + } +} + #[ast_node] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ComplexSelectorChildren { diff --git a/crates/swc_css_ast/src/value.rs b/crates/swc_css_ast/src/value.rs index 23f6bdf4008..48a927c711e 100644 --- a/crates/swc_css_ast/src/value.rs +++ b/crates/swc_css_ast/src/value.rs @@ -6,7 +6,7 @@ use std::{ use is_macro::Is; use string_enum::StringEnum; use swc_atoms::JsWord; -use swc_common::{ast_node, EqIgnoreSpan, Span}; +use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span}; use crate::Function; @@ -26,6 +26,16 @@ impl EqIgnoreSpan for Ident { } } +impl Take for Ident { + fn dummy() -> Self { + Self { + span: Default::default(), + value: Default::default(), + raw: Default::default(), + } + } +} + #[ast_node("CustomIdent")] #[derive(Eq, Hash)] pub struct CustomIdent { diff --git a/crates/swc_css_modules/Cargo.toml b/crates/swc_css_modules/Cargo.toml new file mode 100644 index 00000000000..5a21770410d --- /dev/null +++ b/crates/swc_css_modules/Cargo.toml @@ -0,0 +1,30 @@ +[package] +authors = ["강동윤 "] +description = "CSS modules" +documentation = "https://rustdoc.swc.rs/swc_css_modules/" +edition = "2021" +include = ["Cargo.toml", "src/**/*.rs"] +license = "Apache-2.0" +name = "swc_css_modules" +repository = "https://github.com/swc-project/swc.git" +version = "0.1.0" + +[lib] +bench = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rustc-hash = "1.1.0" +serde = { version = "1", features = ["derive"] } +swc_atoms = { version = "0.4.18", path = "../swc_atoms" } +swc_common = { version = "0.29.4", path = "../swc_common" } +swc_css_ast = { version = "0.114.4", path = "../swc_css_ast" } +swc_css_codegen = { version = "0.124.5", path = "../swc_css_codegen" } +swc_css_parser = { version = "0.123.5", path = "../swc_css_parser" } +swc_css_visit = { version = "0.113.4", path = "../swc_css_visit" } +swc_ecma_loader = { version = "0.41.3", path = "../swc_ecma_loader" } + +[dev-dependencies] +serde_json = "1" +testing = { version = "0.31.4", path = "../testing" } diff --git a/crates/swc_css_modules/src/imports.rs b/crates/swc_css_modules/src/imports.rs new file mode 100644 index 00000000000..86b13893c63 --- /dev/null +++ b/crates/swc_css_modules/src/imports.rs @@ -0,0 +1,68 @@ +//! Import/export analyzer + +use swc_atoms::{js_word, JsWord}; +use swc_css_ast::{ + ComponentValue, Declaration, DeclarationName, Ident, ImportPrelude, ImportPreludeHref, + Stylesheet, UrlValue, +}; +use swc_css_visit::{Visit, VisitWith}; + +pub fn analyze_imports(ss: &Stylesheet) -> Vec { + let mut v = Analyzer { + imports: Default::default(), + }; + ss.visit_with(&mut v); + v.imports.sort(); + v.imports.dedup(); + v.imports +} + +struct Analyzer { + imports: Vec, +} + +impl Visit for Analyzer { + fn visit_import_prelude(&mut self, n: &ImportPrelude) { + n.visit_children_with(self); + + match &*n.href { + ImportPreludeHref::Url(u) => { + if let Some(s) = &u.value { + match &**s { + UrlValue::Str(s) => { + self.imports.push(s.value.clone()); + } + UrlValue::Raw(v) => { + self.imports.push(v.value.clone()); + } + } + } + } + ImportPreludeHref::Str(s) => { + self.imports.push(s.value.clone()); + } + } + } + + fn visit_declaration(&mut self, d: &Declaration) { + d.visit_children_with(self); + + if let DeclarationName::Ident(name) = &d.name { + if &*name.value == "composes" { + // comoses: name from 'foo.css' + if d.value.len() >= 3 { + if let ( + ComponentValue::Ident(Ident { + value: js_word!("from"), + .. + }), + ComponentValue::Str(s), + ) = (&d.value[d.value.len() - 2], &d.value[d.value.len() - 1]) + { + self.imports.push(s.value.clone()); + } + } + } + } + } +} diff --git a/crates/swc_css_modules/src/lib.rs b/crates/swc_css_modules/src/lib.rs new file mode 100644 index 00000000000..39160b642fe --- /dev/null +++ b/crates/swc_css_modules/src/lib.rs @@ -0,0 +1,437 @@ +use rustc_hash::FxHashMap; +use serde::Serialize; +use swc_atoms::{js_word, JsWord}; +use swc_common::util::take::Take; +use swc_css_ast::{ + ComplexSelector, ComplexSelectorChildren, ComponentValue, Declaration, DeclarationName, + DeclarationOrAtRule, Delimiter, DelimiterValue, Ident, KeyframesName, QualifiedRule, + QualifiedRulePrelude, StyleBlock, Stylesheet, SubclassSelector, +}; +use swc_css_parser::{parse_tokens, parser::ParserConfig}; +use swc_css_visit::{VisitMut, VisitMutWith}; +use util::to_tokens::to_tokens_vec; + +pub mod imports; +mod util; + +/// Various configurations for the css modules. +/// +/// # Note +/// +/// This is a trait rather than a struct because api like `fn() -> String` is +/// too restricted and `Box String` is (needlessly) slow. +pub trait TransformConfig { + /// Creates a class name for the given `local_name`. + fn new_name_for(&self, local: &JsWord) -> JsWord; + + // /// Used for `@value` imports. + // fn get_value(&self, import_source: &str, value_name: &JsWord) -> + // ComponentValue; +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[serde(tag = "type", rename_all = "camelCase")] +pub enum CssClassName { + Local { + /// Tranformed css class name + name: JsWord, + }, + Global { + name: JsWord, + }, + Import { + /// The exported class name. This is the value specified by the user. + name: JsWord, + /// The module specifier. + from: JsWord, + }, +} + +#[derive(Debug, Clone)] +pub struct TransformResult { + /// A map of js class name to css class names. + pub renamed: FxHashMap>, +} + +/// Returns a map from local name to exported name. +pub fn compile(ss: &mut Stylesheet, config: impl TransformConfig) -> TransformResult { + let mut compiler = Compiler { + config, + data: Default::default(), + result: TransformResult { + renamed: Default::default(), + }, + }; + + ss.visit_mut_with(&mut compiler); + + compiler.result +} + +struct Compiler +where + C: TransformConfig, +{ + config: C, + data: Data, + result: TransformResult, +} + +#[derive(Default)] +struct Data { + /// Context for `composes` + composes_for_current: Option>, + + renamed_to_orig: FxHashMap, + orig_to_renamed: FxHashMap, +} + +impl VisitMut for Compiler +where + C: TransformConfig, +{ + fn visit_mut_qualified_rule(&mut self, n: &mut QualifiedRule) { + let old_compose_stack = self.data.composes_for_current.take(); + self.data.composes_for_current = Some(Default::default()); + + n.visit_mut_children_with(self); + + if let QualifiedRulePrelude::SelectorList(sel) = &n.prelude { + // + if sel.children.len() == 1 && sel.children[0].children.len() == 1 { + if let ComplexSelectorChildren::CompoundSelector(sel) = &sel.children[0].children[0] + { + if sel.subclass_selectors.len() == 1 { + if let SubclassSelector::Class(class_sel) = &sel.subclass_selectors[0] { + if let Some(composes) = self.data.composes_for_current.take() { + let key = self + .data + .renamed_to_orig + .get(&class_sel.text.value) + .cloned(); + + if let Some(key) = key { + self.result.renamed.entry(key).or_default().extend(composes); + } + } + } + } + } + } + } + + self.data.composes_for_current = old_compose_stack; + } + + fn visit_mut_component_values(&mut self, n: &mut Vec) { + n.visit_mut_children_with(self); + + n.retain(|v| match v { + ComponentValue::StyleBlock(StyleBlock::Declaration(d)) + | ComponentValue::DeclarationOrAtRule(DeclarationOrAtRule::Declaration(d)) => { + if let DeclarationName::Ident(ident) = &d.name { + if &*ident.value == "composes" { + return false; + } + } + + true + } + _ => true, + }); + } + + /// Handles `composes` + fn visit_mut_declaration(&mut self, n: &mut Declaration) { + n.visit_mut_children_with(self); + + if let Some(composes_for_current) = &mut self.data.composes_for_current { + if let DeclarationName::Ident(name) = &n.name { + if &*name.value == "composes" { + // comoses: name from 'foo.css' + if n.value.len() >= 3 { + match (&n.value[n.value.len() - 2], &n.value[n.value.len() - 1]) { + ( + ComponentValue::Ident(Ident { + value: js_word!("from"), + .. + }), + ComponentValue::Str(import_source), + ) => { + for class_name in n.value.iter().take(n.value.len() - 2) { + if let ComponentValue::Ident(Ident { value, .. }) = class_name { + composes_for_current.push(CssClassName::Import { + name: value.clone(), + from: import_source.value.clone(), + }); + } + } + + return; + } + ( + ComponentValue::Ident(Ident { + value: js_word!("from"), + .. + }), + ComponentValue::Ident(Ident { + value: js_word!("global"), + .. + }), + ) => { + for class_name in n.value.iter().take(n.value.len() - 2) { + if let ComponentValue::Ident(Ident { value, .. }) = class_name { + composes_for_current.push(CssClassName::Global { + name: value.clone(), + }); + } + } + return; + } + _ => (), + } + } + + for class_name in n.value.iter() { + if let ComponentValue::Ident(Ident { value, .. }) = class_name { + if let Some(value) = self.data.orig_to_renamed.get(value) { + composes_for_current.push(CssClassName::Local { + name: value.clone(), + }); + } + } + } + } + } + } + + if let DeclarationName::Ident(name) = &n.name { + match name.value.to_ascii_lowercase() { + js_word!("animation") => { + let mut can_change = true; + + for v in &mut n.value { + if can_change { + if let ComponentValue::Ident(Ident { value, raw, .. }) = v { + *raw = None; + + rename( + &mut self.config, + &mut self.result, + &mut self.data.orig_to_renamed, + &mut self.data.renamed_to_orig, + value, + ); + can_change = false; + } + } else if let ComponentValue::Delimiter(Delimiter { + value: DelimiterValue::Comma, + .. + }) = v + { + can_change = true; + } + } + } + js_word!("animation-name") => { + for v in &mut n.value { + if let ComponentValue::Ident(Ident { value, raw, .. }) = v { + *raw = None; + + rename( + &mut self.config, + &mut self.result, + &mut self.data.orig_to_renamed, + &mut self.data.renamed_to_orig, + value, + ); + } + } + } + _ => {} + } + } + } + + fn visit_mut_complex_selector(&mut self, n: &mut ComplexSelector) { + n.visit_mut_children_with(self); + + let mut new_children = Vec::with_capacity(n.children.len()); + + 'complex: for mut n in n.children.take() { + match &mut n { + ComplexSelectorChildren::CompoundSelector(sel) => { + // + + for sel in &mut sel.subclass_selectors { + match sel { + SubclassSelector::Class(..) | SubclassSelector::Id(..) => { + process_local( + &mut self.config, + &mut self.result, + &mut self.data.orig_to_renamed, + &mut self.data.renamed_to_orig, + sel, + ); + } + SubclassSelector::PseudoClass(class_sel) => { + match &*class_sel.name.value { + "local" => { + if let Some(children) = &mut class_sel.children { + let tokens = to_tokens_vec(&*children); + + let mut sel: ComplexSelector = parse_tokens( + &tokens, + ParserConfig { + ..Default::default() + }, + &mut vec![], + ) + .unwrap(); + + sel.visit_mut_with(self); + + new_children.extend(sel.children); + + continue 'complex; + } + } + "global" => { + if let Some(children) = &mut class_sel.children { + let tokens = to_tokens_vec(&*children); + + let sel: ComplexSelector = parse_tokens( + &tokens, + ParserConfig { + ..Default::default() + }, + &mut vec![], + ) + .unwrap(); + + new_children.extend(sel.children); + + continue 'complex; + } + } + + _ => {} + } + } + _ => { + sel.visit_mut_children_with(self); + } + } + } + } + ComplexSelectorChildren::Combinator(_) => {} + } + + new_children.push(n); + } + + n.children = new_children; + } + + fn visit_mut_complex_selectors(&mut self, n: &mut Vec) { + n.visit_mut_children_with(self); + + n.retain_mut(|s| !s.children.is_empty()); + } + + fn visit_mut_keyframes_name(&mut self, n: &mut KeyframesName) { + n.visit_mut_children_with(self); + + match n { + KeyframesName::CustomIdent(n) => { + n.raw = None; + rename( + &mut self.config, + &mut self.result, + &mut self.data.orig_to_renamed, + &mut self.data.renamed_to_orig, + &mut n.value, + ) + } + KeyframesName::Str(n) => { + n.raw = None; + rename( + &mut self.config, + &mut self.result, + &mut self.data.orig_to_renamed, + &mut self.data.renamed_to_orig, + &mut n.value, + ) + } + } + } +} + +fn rename( + config: &mut C, + result: &mut TransformResult, + orig_to_renamed: &mut FxHashMap, + renamed_to_orig: &mut FxHashMap, + name: &mut JsWord, +) where + C: TransformConfig, +{ + if let Some(renamed) = orig_to_renamed.get(name) { + *name = renamed.clone(); + return; + } + + let new = config.new_name_for(name); + + orig_to_renamed.insert(name.clone(), new.clone()); + renamed_to_orig.insert(new.clone(), name.clone()); + + { + let e = result.renamed.entry(name.clone()).or_default(); + + let v = CssClassName::Local { name: new.clone() }; + if !e.contains(&v) { + e.push(v); + } + } + + *name = new; +} + +fn process_local( + config: &mut C, + result: &mut TransformResult, + orig_to_renamed: &mut FxHashMap, + renamed_to_orig: &mut FxHashMap, + sel: &mut SubclassSelector, +) where + C: TransformConfig, +{ + match sel { + SubclassSelector::Id(sel) => { + sel.text.raw = None; + + rename( + config, + result, + orig_to_renamed, + renamed_to_orig, + &mut sel.text.value, + ); + } + SubclassSelector::Class(sel) => { + sel.text.raw = None; + + rename( + config, + result, + orig_to_renamed, + renamed_to_orig, + &mut sel.text.value, + ); + } + SubclassSelector::Attribute(_) => {} + SubclassSelector::PseudoClass(_) => {} + SubclassSelector::PseudoElement(_) => {} + } +} diff --git a/crates/swc_css_modules/src/util/mod.rs b/crates/swc_css_modules/src/util/mod.rs new file mode 100644 index 00000000000..7630cbb4299 --- /dev/null +++ b/crates/swc_css_modules/src/util/mod.rs @@ -0,0 +1 @@ +pub mod to_tokens; diff --git a/crates/swc_css_modules/src/util/to_tokens.rs b/crates/swc_css_modules/src/util/to_tokens.rs new file mode 100644 index 00000000000..b6985175be7 --- /dev/null +++ b/crates/swc_css_modules/src/util/to_tokens.rs @@ -0,0 +1,63 @@ +use swc_common::{input::StringInput, Span, Spanned}; +use swc_css_ast::Tokens; +use swc_css_codegen::{ + writer::basic::{BasicCssWriter, BasicCssWriterConfig, IndentType}, + CodeGenerator, CodegenConfig, Emit, +}; +use swc_css_parser::{lexer::Lexer, parser::ParserConfig}; + +pub(crate) fn to_tokens_vec(n: &[N]) -> Tokens +where + N: Spanned, + for<'aa, 'ab> CodeGenerator>: swc_css_codegen::Emit, +{ + let lo = n.first().span().lo(); + let hi = n.last().span().lo(); + + let tokens = n.iter().flat_map(|n| to_tokens(n).tokens).collect(); + + Tokens { + span: Span::new(lo, hi, Default::default()), + tokens, + } +} + +pub(crate) fn to_tokens(n: &N) -> Tokens +where + N: Spanned, + for<'aa, 'ab> CodeGenerator>: swc_css_codegen::Emit, +{ + let span = n.span(); + + let mut buf = String::new(); + { + let wr = BasicCssWriter::new( + &mut buf, + None, + BasicCssWriterConfig { + indent_type: IndentType::Tab, + ..Default::default() + }, + ); + let mut g = CodeGenerator::new( + wr, + CodegenConfig { + ..Default::default() + }, + ); + + g.emit(n).unwrap(); + } + + let lexer = Lexer::new( + StringInput::new(&buf, span.lo, span.hi), + ParserConfig { + allow_wrong_line_comments: true, + }, + ); + + Tokens { + span, + tokens: lexer.collect(), + } +} diff --git a/crates/swc_css_modules/tests/fixture.rs b/crates/swc_css_modules/tests/fixture.rs new file mode 100644 index 00000000000..ccb3777588a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture.rs @@ -0,0 +1,95 @@ +use std::path::PathBuf; + +use swc_atoms::JsWord; +use swc_css_codegen::{ + writer::basic::{BasicCssWriter, BasicCssWriterConfig, IndentType}, + CodeGenerator, CodegenConfig, Emit, +}; +use testing::NormalizedOutput; + +#[testing::fixture("tests/fixture/**/*.css", exclude("compiled\\.css"))] +fn imports(input: PathBuf) { + testing::run_test(false, |cm, handler| { + let fm = cm.load_file(&input).unwrap(); + let mut errors = vec![]; + let ss = swc_css_parser::parse_file(&fm, Default::default(), &mut errors).unwrap(); + let result = swc_css_modules::imports::analyze_imports(&ss); + + if result.is_empty() { + return Ok(()); + } + + let s = serde_json::to_string_pretty(&result).unwrap(); + NormalizedOutput::from(s) + .compare_to_file(input.with_file_name(format!( + "{}.imports.json", + input.file_stem().unwrap().to_string_lossy() + ))) + .unwrap(); + + Ok(()) + }) + .unwrap(); +} + +#[testing::fixture("tests/fixture/**/*.css", exclude("compiled\\.css"))] +fn compile(input: PathBuf) { + testing::run_test(false, |cm, handler| { + let fm = cm.load_file(&input).unwrap(); + let mut errors = vec![]; + let mut ss = swc_css_parser::parse_file(&fm, Default::default(), &mut errors).unwrap(); + let result = swc_css_modules::imports::analyze_imports(&ss); + + let transform_result = swc_css_modules::compile(&mut ss, TestConfig {}); + + let mut buf = String::new(); + { + let mut wr = BasicCssWriter::new( + &mut buf, + None, + BasicCssWriterConfig { + indent_type: IndentType::Space, + indent_width: 2, + ..Default::default() + }, + ); + let mut g = CodeGenerator::new( + wr, + CodegenConfig { + ..Default::default() + }, + ); + + g.emit(&ss).unwrap(); + } + + NormalizedOutput::from(buf) + .compare_to_file(input.with_file_name(format!( + "{}.compiled.css", + input.file_stem().unwrap().to_string_lossy() + ))) + .unwrap(); + + if !transform_result.renamed.is_empty() { + let transformed_classes = + serde_json::to_string_pretty(&transform_result.renamed).unwrap(); + + NormalizedOutput::from(transformed_classes) + .compare_to_file(input.with_file_name(format!( + "{}.transform.json", + input.file_stem().unwrap().to_string_lossy() + ))) + .unwrap(); + } + Ok(()) + }) + .unwrap(); +} + +struct TestConfig {} + +impl swc_css_modules::TransformConfig for TestConfig { + fn new_name_for(&self, local: &JsWord) -> JsWord { + format!("__local__{}", local).into() + } +} diff --git a/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.compiled.css b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.compiled.css new file mode 100644 index 00000000000..c6d6741bf35 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.compiled.css @@ -0,0 +1,111 @@ +@charset "UTF-8"; +.__local__class { + color: red; + background: url("./url/img.png"); +} +.__local__class-duplicate-url { + background: url("./url/img.png"); +} +:root { + --foo: 1px; + --bar: 2px; +} +.__local__class { + a: b c d; +} +.__local__two {} +.__local__u-m\+ { + a: b c d; +} +.__local__class { + content: "\F10C"; +} +@media only screen and (max-width: 600px) { + body { + background-color: lightblue; + } +} +.__local__class { + content: "\2193"; + content: "\2193\2193"; + content: "\2193 \2193"; + content: "\2193\2193\2193"; + content: "\2193 \2193 \2193"; +} +.__local__-top {} +.__local__-top {} +#__local__\#test {} +.__local__grid { + display: flex; + flex-wrap: wrap; +} +.__local__grid.__local__-top { + align-items: flex-start; +} +.__local__grid.__local__-top { + align-items: flex-start; +} +.__local__grid.__local__-middle { + align-items: center; +} +.__local__grid.__local__-bottom { + align-items: flex-end; +} +.__local__u-m\+ {} +.__local__u-m00002b {} +#__local__u-m\+ {} +body { + font-family: '微软雅黑'; +} +.__local__myStyle { + content: '\e901'; +} +.__local__myStyle { + content: '\E901'; +} +.__local__♫ {} +.__local__\:\`\( {} +.__local__1a2b3c {} +#__local__\#fake-id {} +#__local__-a-b-c- {} +#__local__© {} +:root { + --title-align: center; + --sr-only: { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0,0,0,0); + white-space: nowrap; + clip-path: inset(50%); + border: 0; + }; +} +.__local__test { + content: "\2014\A0"; + content: "\2014 \A0"; + content: "\A0 \2014"; + content: "\A0\2014"; + margin-top: 1px\9; + background-color: #000\9; +} +.__local__light.__local__on .__local__bulb:before { + content: '💡'; +} +.__local__base64 { + background: url(data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAhxJREFUSA3tk71rU1EYxnMTEoJUkowWwdJ2akEHBfGjCiIF6ZylVUKSm2TqZLGI+A/oIu2UXm8C4lAyF4SWji0tdFLo1Eo7VN0SaBEhH7e/Nz0nPTfGOjiaCyfPc5734zlfCQT6X/8E/vUErL81KBaL9y3LSnued5PcITjUOwR3gsFg2bbtjYt6/NGgXC4P1et1l2aPLmpAbD0SidjpdPqgV15PA9d17zQajU8UxHQRK/4G35Q5pveAK8LlI1ZjPMnlcltnyvnvbwaO41xvtVqy7YHztMACq5xnlb9EY3dRdvcGo1kj5wR+t1AofDG0gM+A875E8DNjRCexsrV8Pj9ZqVQitVrtqejxePxjMpmss5hVTB4buXvMb2DyU2tBTRS+BjvNlVYUpPl7iuVO3Gq1uoQx1FtSOW1gPgp5ZWrdBtNmUDgv5asgxQ8F1af5vhY0YjyjuWC3wTszKJz7GBOkcFlQfW2ONq4FjWi+Hj6DRCKxQOK2TlY4x92EuYd5dvMAbYIzfikau3pu5tJ8KxaLLfo0cyKci7tK4TZjUMcoXAmHwzle0Q/RaC5P1GFMyVx9R9Fo9HYqlTrSgqDvFelAqVQa5hmuMR/WGtjAaBdjwBoDQ0ZsnwVMZjKZ9n0Zem8DSeDPdrnZbL6F2l3NOvUYNZk4oVDoRTabPe4EDNJzB0ZcjAYxeoZ2i3FNxQ7BHYw/cB/fldaH//UETgHHO8S44KbfXgAAAABJRU5ErkJggg==); +} +a[href=''] { + color: red; +} +a[href='' i] { + color: red; +} +a[href=""] { + color: blue; +} +a[href="" i] { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.css b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.css new file mode 100644 index 00000000000..491ad56b6e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.css @@ -0,0 +1,135 @@ +@charset "UTF-8"; + +/* Comment */ + +.class { + color: red; + background: url("./url/img.png"); +} + +.class-duplicate-url { + background: url("./url/img.png"); +} + +:root { + --foo: 1px; + --bar: 2px; +} + +.class { a: b c d; } + +.two {} + +.u-m\+ { a: b c d; } + +.class { content: "\F10C" } + +@media only screen and (max-width: 600px) { + body { + background-color: lightblue; + } +} + +.class { + content: "\2193"; + content: "\2193\2193"; + content: "\2193 \2193"; + content: "\2193\2193\2193"; + content: "\2193 \2193 \2193"; +} + +.-top {} +.\-top {} + +#\#test {} + +.grid { + display: flex; + flex-wrap: wrap; +} +.grid.\-top { + align-items: flex-start; +} +.grid.-top { + align-items: flex-start; +} +.grid.\-middle { + align-items: center; +} +.grid.\-bottom { + align-items: flex-end; +} + +.u-m\00002b {} + +.u-m00002b {} + +#u-m\+ {} + +body { + font-family: '微软雅黑'; /* some chinese font name */ +} + +.myStyle { + content: '\e901'; +} + +.myStyle { + content: '\E901'; +} + +.♫ {} + +.\3A \`\( {} /* matches elements with class=":`(" */ +.\31 a2b3c {} /* matches elements with class="1a2b3c" */ +#\#fake-id {} /* matches the element with id="#fake-id" */ +#-a-b-c- {} /* matches the element with id="-a-b-c-" */ +#© {} /* matches the element with id="©" */ + +:root { + --title-align: center; + --sr-only: { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0,0,0,0); + white-space: nowrap; + clip-path: inset(50%); + border: 0; + }; +} + +.test { + content: "\2014\A0"; + content: "\2014 \A0"; + content: "\A0 \2014"; + content: "\A0\2014"; + margin-top: 1px\9; + background-color: #000\9; +} + +.light.on .bulb:before{ + content: '💡'; +} + +.base64 { + background: url(data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAhxJREFUSA3tk71rU1EYxnMTEoJUkowWwdJ2akEHBfGjCiIF6ZylVUKSm2TqZLGI+A/oIu2UXm8C4lAyF4SWji0tdFLo1Eo7VN0SaBEhH7e/Nz0nPTfGOjiaCyfPc5734zlfCQT6X/8E/vUErL81KBaL9y3LSnued5PcITjUOwR3gsFg2bbtjYt6/NGgXC4P1et1l2aPLmpAbD0SidjpdPqgV15PA9d17zQajU8UxHQRK/4G35Q5pveAK8LlI1ZjPMnlcltnyvnvbwaO41xvtVqy7YHztMACq5xnlb9EY3dRdvcGo1kj5wR+t1AofDG0gM+A875E8DNjRCexsrV8Pj9ZqVQitVrtqejxePxjMpmss5hVTB4buXvMb2DyU2tBTRS+BjvNlVYUpPl7iuVO3Gq1uoQx1FtSOW1gPgp5ZWrdBtNmUDgv5asgxQ8F1af5vhY0YjyjuWC3wTszKJz7GBOkcFlQfW2ONq4FjWi+Hj6DRCKxQOK2TlY4x92EuYd5dvMAbYIzfikau3pu5tJ8KxaLLfo0cyKci7tK4TZjUMcoXAmHwzle0Q/RaC5P1GFMyVx9R9Fo9HYqlTrSgqDvFelAqVQa5hmuMR/WGtjAaBdjwBoDQ0ZsnwVMZjKZ9n0Zem8DSeDPdrnZbL6F2l3NOvUYNZk4oVDoRTabPe4EDNJzB0ZcjAYxeoZ2i3FNxQ7BHYw/cB/fldaH//UETgHHO8S44KbfXgAAAABJRU5ErkJggg==); +} + +a[href=''] { + color: red; +} + +a[href='' i] { + color: red; +} + +a[href=""] { + color: blue; +} + +a[href="" i] { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.transform.json b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.transform.json new file mode 100644 index 00000000000..e4f0467aead --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic-css-style-sheet.transform.json @@ -0,0 +1,134 @@ +{ + "bulb": [ + { + "type": "local", + "name": "__local__bulb" + } + ], + "class": [ + { + "type": "local", + "name": "__local__class" + } + ], + "class-duplicate-url": [ + { + "type": "local", + "name": "__local__class-duplicate-url" + } + ], + "two": [ + { + "type": "local", + "name": "__local__two" + } + ], + "grid": [ + { + "type": "local", + "name": "__local__grid" + } + ], + "-top": [ + { + "type": "local", + "name": "__local__-top" + } + ], + "-bottom": [ + { + "type": "local", + "name": "__local__-bottom" + } + ], + "#test": [ + { + "type": "local", + "name": "__local__#test" + } + ], + "myStyle": [ + { + "type": "local", + "name": "__local__myStyle" + } + ], + "♫": [ + { + "type": "local", + "name": "__local__♫" + } + ], + ":`(": [ + { + "type": "local", + "name": "__local__:`(" + } + ], + "#fake-id": [ + { + "type": "local", + "name": "__local__#fake-id" + } + ], + "-a-b-c-": [ + { + "type": "local", + "name": "__local__-a-b-c-" + } + ], + "light": [ + { + "type": "local", + "name": "__local__light" + } + ], + "u-m+": [ + { + "type": "local", + "name": "__local__u-m+" + } + ], + "base64": [ + { + "type": "local", + "name": "__local__base64" + } + ], + "©": [ + { + "type": "local", + "name": "__local__©" + } + ], + "on": [ + { + "type": "local", + "name": "__local__on" + } + ], + "-middle": [ + { + "type": "local", + "name": "__local__-middle" + } + ], + "u-m00002b": [ + { + "type": "local", + "name": "__local__u-m00002b" + } + ], + "test": [ + { + "type": "local", + "name": "__local__test" + } + ], + "1a2b3c": [ + { + "type": "local", + "name": "__local__1a2b3c" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/basic.compiled.css b/crates/swc_css_modules/tests/fixture/basic.compiled.css new file mode 100644 index 00000000000..aaff46c920d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic.compiled.css @@ -0,0 +1,112 @@ +@charset "UTF-8"; +@import 'imported.css'; +.__local__class { + color: red; + background: url("./url/img.png"); +} +.__local__class-duplicate-url { + background: url("./url/img.png"); +} +:root { + --foo: 1px; + --bar: 2px; +} +.__local__class { + a: b c d; +} +.__local__two {} +.__local__u-m\+ { + a: b c d; +} +.__local__class { + content: "\F10C"; +} +@media only screen and (max-width: 600px) { + body { + background-color: lightblue; + } +} +.__local__class { + content: "\2193"; + content: "\2193\2193"; + content: "\2193 \2193"; + content: "\2193\2193\2193"; + content: "\2193 \2193 \2193"; +} +.__local__-top {} +.__local__-top {} +#__local__\#test {} +.__local__grid { + display: flex; + flex-wrap: wrap; +} +.__local__grid.__local__-top { + align-items: flex-start; +} +.__local__grid.__local__-top { + align-items: flex-start; +} +.__local__grid.__local__-middle { + align-items: center; +} +.__local__grid.__local__-bottom { + align-items: flex-end; +} +.__local__u-m\+ {} +.__local__u-m00002b {} +#__local__u-m\+ {} +body { + font-family: '微软雅黑'; +} +.__local__myStyle { + content: '\e901'; +} +.__local__myStyle { + content: '\E901'; +} +.__local__♫ {} +.__local__\:\`\( {} +.__local__1a2b3c {} +#__local__\#fake-id {} +#__local__-a-b-c- {} +#__local__© {} +:root { + --title-align: center; + --sr-only: { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0,0,0,0); + white-space: nowrap; + clip-path: inset(50%); + border: 0; + }; +} +.__local__test { + content: "\2014\A0"; + content: "\2014 \A0"; + content: "\A0 \2014"; + content: "\A0\2014"; + margin-top: 1px\9; + background-color: #000\9; +} +.__local__light.__local__on .__local__bulb:before { + content: '💡'; +} +.__local__base64 { + background: url(data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAhxJREFUSA3tk71rU1EYxnMTEoJUkowWwdJ2akEHBfGjCiIF6ZylVUKSm2TqZLGI+A/oIu2UXm8C4lAyF4SWji0tdFLo1Eo7VN0SaBEhH7e/Nz0nPTfGOjiaCyfPc5734zlfCQT6X/8E/vUErL81KBaL9y3LSnued5PcITjUOwR3gsFg2bbtjYt6/NGgXC4P1et1l2aPLmpAbD0SidjpdPqgV15PA9d17zQajU8UxHQRK/4G35Q5pveAK8LlI1ZjPMnlcltnyvnvbwaO41xvtVqy7YHztMACq5xnlb9EY3dRdvcGo1kj5wR+t1AofDG0gM+A875E8DNjRCexsrV8Pj9ZqVQitVrtqejxePxjMpmss5hVTB4buXvMb2DyU2tBTRS+BjvNlVYUpPl7iuVO3Gq1uoQx1FtSOW1gPgp5ZWrdBtNmUDgv5asgxQ8F1af5vhY0YjyjuWC3wTszKJz7GBOkcFlQfW2ONq4FjWi+Hj6DRCKxQOK2TlY4x92EuYd5dvMAbYIzfikau3pu5tJ8KxaLLfo0cyKci7tK4TZjUMcoXAmHwzle0Q/RaC5P1GFMyVx9R9Fo9HYqlTrSgqDvFelAqVQa5hmuMR/WGtjAaBdjwBoDQ0ZsnwVMZjKZ9n0Zem8DSeDPdrnZbL6F2l3NOvUYNZk4oVDoRTabPe4EDNJzB0ZcjAYxeoZ2i3FNxQ7BHYw/cB/fldaH//UETgHHO8S44KbfXgAAAABJRU5ErkJggg==); +} +a[href=''] { + color: red; +} +a[href='' i] { + color: red; +} +a[href=""] { + color: blue; +} +a[href="" i] { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/basic.css b/crates/swc_css_modules/tests/fixture/basic.css new file mode 100644 index 00000000000..be9ee34e8ae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic.css @@ -0,0 +1,137 @@ +@charset "UTF-8"; + +@import 'imported.css'; + +/* Comment */ + +.class { + color: red; + background: url("./url/img.png"); +} + +.class-duplicate-url { + background: url("./url/img.png"); +} + +:root { + --foo: 1px; + --bar: 2px; +} + +.class { a: b c d; } + +.two {} + +.u-m\+ { a: b c d; } + +.class { content: "\F10C" } + +@media only screen and (max-width: 600px) { + body { + background-color: lightblue; + } +} + +.class { + content: "\2193"; + content: "\2193\2193"; + content: "\2193 \2193"; + content: "\2193\2193\2193"; + content: "\2193 \2193 \2193"; +} + +.-top {} +.\-top {} + +#\#test {} + +.grid { + display: flex; + flex-wrap: wrap; +} +.grid.\-top { + align-items: flex-start; +} +.grid.-top { + align-items: flex-start; +} +.grid.\-middle { + align-items: center; +} +.grid.\-bottom { + align-items: flex-end; +} + +.u-m\00002b {} + +.u-m00002b {} + +#u-m\+ {} + +body { + font-family: '微软雅黑'; /* some chinese font name */ +} + +.myStyle { + content: '\e901'; +} + +.myStyle { + content: '\E901'; +} + +.♫ {} + +.\3A \`\( {} /* matches elements with class=":`(" */ +.\31 a2b3c {} /* matches elements with class="1a2b3c" */ +#\#fake-id {} /* matches the element with id="#fake-id" */ +#-a-b-c- {} /* matches the element with id="-a-b-c-" */ +#© {} /* matches the element with id="©" */ + +:root { + --title-align: center; + --sr-only: { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0,0,0,0); + white-space: nowrap; + clip-path: inset(50%); + border: 0; + }; +} + +.test { + content: "\2014\A0"; + content: "\2014 \A0"; + content: "\A0 \2014"; + content: "\A0\2014"; + margin-top: 1px\9; + background-color: #000\9; +} + +.light.on .bulb:before{ + content: '💡'; +} + +.base64 { + background: url(data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAhxJREFUSA3tk71rU1EYxnMTEoJUkowWwdJ2akEHBfGjCiIF6ZylVUKSm2TqZLGI+A/oIu2UXm8C4lAyF4SWji0tdFLo1Eo7VN0SaBEhH7e/Nz0nPTfGOjiaCyfPc5734zlfCQT6X/8E/vUErL81KBaL9y3LSnued5PcITjUOwR3gsFg2bbtjYt6/NGgXC4P1et1l2aPLmpAbD0SidjpdPqgV15PA9d17zQajU8UxHQRK/4G35Q5pveAK8LlI1ZjPMnlcltnyvnvbwaO41xvtVqy7YHztMACq5xnlb9EY3dRdvcGo1kj5wR+t1AofDG0gM+A875E8DNjRCexsrV8Pj9ZqVQitVrtqejxePxjMpmss5hVTB4buXvMb2DyU2tBTRS+BjvNlVYUpPl7iuVO3Gq1uoQx1FtSOW1gPgp5ZWrdBtNmUDgv5asgxQ8F1af5vhY0YjyjuWC3wTszKJz7GBOkcFlQfW2ONq4FjWi+Hj6DRCKxQOK2TlY4x92EuYd5dvMAbYIzfikau3pu5tJ8KxaLLfo0cyKci7tK4TZjUMcoXAmHwzle0Q/RaC5P1GFMyVx9R9Fo9HYqlTrSgqDvFelAqVQa5hmuMR/WGtjAaBdjwBoDQ0ZsnwVMZjKZ9n0Zem8DSeDPdrnZbL6F2l3NOvUYNZk4oVDoRTabPe4EDNJzB0ZcjAYxeoZ2i3FNxQ7BHYw/cB/fldaH//UETgHHO8S44KbfXgAAAABJRU5ErkJggg==); +} + +a[href=''] { + color: red; +} + +a[href='' i] { + color: red; +} + +a[href=""] { + color: blue; +} + +a[href="" i] { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/basic.imports.json b/crates/swc_css_modules/tests/fixture/basic.imports.json new file mode 100644 index 00000000000..68542f65b3d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic.imports.json @@ -0,0 +1,3 @@ +[ + "imported.css" +] diff --git a/crates/swc_css_modules/tests/fixture/basic.transform.json b/crates/swc_css_modules/tests/fixture/basic.transform.json new file mode 100644 index 00000000000..e4f0467aead --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/basic.transform.json @@ -0,0 +1,134 @@ +{ + "bulb": [ + { + "type": "local", + "name": "__local__bulb" + } + ], + "class": [ + { + "type": "local", + "name": "__local__class" + } + ], + "class-duplicate-url": [ + { + "type": "local", + "name": "__local__class-duplicate-url" + } + ], + "two": [ + { + "type": "local", + "name": "__local__two" + } + ], + "grid": [ + { + "type": "local", + "name": "__local__grid" + } + ], + "-top": [ + { + "type": "local", + "name": "__local__-top" + } + ], + "-bottom": [ + { + "type": "local", + "name": "__local__-bottom" + } + ], + "#test": [ + { + "type": "local", + "name": "__local__#test" + } + ], + "myStyle": [ + { + "type": "local", + "name": "__local__myStyle" + } + ], + "♫": [ + { + "type": "local", + "name": "__local__♫" + } + ], + ":`(": [ + { + "type": "local", + "name": "__local__:`(" + } + ], + "#fake-id": [ + { + "type": "local", + "name": "__local__#fake-id" + } + ], + "-a-b-c-": [ + { + "type": "local", + "name": "__local__-a-b-c-" + } + ], + "light": [ + { + "type": "local", + "name": "__local__light" + } + ], + "u-m+": [ + { + "type": "local", + "name": "__local__u-m+" + } + ], + "base64": [ + { + "type": "local", + "name": "__local__base64" + } + ], + "©": [ + { + "type": "local", + "name": "__local__©" + } + ], + "on": [ + { + "type": "local", + "name": "__local__on" + } + ], + "-middle": [ + { + "type": "local", + "name": "__local__-middle" + } + ], + "u-m00002b": [ + { + "type": "local", + "name": "__local__u-m00002b" + } + ], + "test": [ + { + "type": "local", + "name": "__local__test" + } + ], + "1a2b3c": [ + { + "type": "local", + "name": "__local__1a2b3c" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/empty.css b/crates/swc_css_modules/tests/fixture/empty.css new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc_css_modules/tests/fixture/error.compiled.css b/crates/swc_css_modules/tests/fixture/error.compiled.css new file mode 100644 index 00000000000..1311ab6e9c0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/error.compiled.css @@ -0,0 +1,2 @@ +.__local__some { + invalid css;} diff --git a/crates/swc_css_modules/tests/fixture/error.css b/crates/swc_css_modules/tests/fixture/error.css new file mode 100644 index 00000000000..113c2f02b6f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/error.css @@ -0,0 +1,3 @@ +.some { + invalid css; +} diff --git a/crates/swc_css_modules/tests/fixture/error.transform.json b/crates/swc_css_modules/tests/fixture/error.transform.json new file mode 100644 index 00000000000..eb7f6a3be8b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/error.transform.json @@ -0,0 +1,8 @@ +{ + "some": [ + { + "type": "local", + "name": "__local__some" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/imported.compiled.css b/crates/swc_css_modules/tests/fixture/es-module/imported.compiled.css new file mode 100644 index 00000000000..50f5c47de37 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/imported.compiled.css @@ -0,0 +1,3 @@ +.__local__foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/imported.css b/crates/swc_css_modules/tests/fixture/es-module/imported.css new file mode 100644 index 00000000000..a15c877ac01 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/imported.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/imported.transform.json b/crates/swc_css_modules/tests/fixture/es-module/imported.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/imported.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/source.compiled.css b/crates/swc_css_modules/tests/fixture/es-module/source.compiled.css new file mode 100644 index 00000000000..b2ba0f462d5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/source.compiled.css @@ -0,0 +1,6 @@ +@charset "UTF-8"; +@import './imported.css'; +.__local__class { + color: red; + background: url("./img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/source.css b/crates/swc_css_modules/tests/fixture/es-module/source.css new file mode 100644 index 00000000000..e0750e64e66 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/source.css @@ -0,0 +1,10 @@ +@charset "UTF-8"; + +@import './imported.css'; + +/* Comment */ + +.class { + color: red; + background: url("./img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/source.imports.json b/crates/swc_css_modules/tests/fixture/es-module/source.imports.json new file mode 100644 index 00000000000..f2d9bde50c3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/source.imports.json @@ -0,0 +1,3 @@ +[ + "./imported.css" +] diff --git a/crates/swc_css_modules/tests/fixture/es-module/source.transform.json b/crates/swc_css_modules/tests/fixture/es-module/source.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/source.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/template/index.compiled.css b/crates/swc_css_modules/tests/fixture/es-module/template/index.compiled.css new file mode 100644 index 00000000000..a547fa4bd33 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/template/index.compiled.css @@ -0,0 +1,9 @@ +.__local__header-baz { + color: red; +} +.__local__body { + color: coral; +} +.__local__footer { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/template/index.css b/crates/swc_css_modules/tests/fixture/es-module/template/index.css new file mode 100644 index 00000000000..b3ccc301cd7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/template/index.css @@ -0,0 +1,11 @@ +:local(.header-baz) { + color: red; +} + +:local(.body) { + color: coral; +} + +:local(.footer) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/es-module/template/index.transform.json b/crates/swc_css_modules/tests/fixture/es-module/template/index.transform.json new file mode 100644 index 00000000000..8baa9556683 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/es-module/template/index.transform.json @@ -0,0 +1,20 @@ +{ + "body": [ + { + "type": "local", + "name": "__local__body" + } + ], + "footer": [ + { + "type": "local", + "name": "__local__footer" + } + ], + "header-baz": [ + { + "type": "local", + "name": "__local__header-baz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/absolute-url.compiled.css b/crates/swc_css_modules/tests/fixture/import/absolute-url.compiled.css new file mode 100644 index 00000000000..411c71079a9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/absolute-url.compiled.css @@ -0,0 +1,4 @@ +@import url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/imported.css"); +a { + background: url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/import/absolute-url.css b/crates/swc_css_modules/tests/fixture/import/absolute-url.css new file mode 100644 index 00000000000..0d440b541bb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/absolute-url.css @@ -0,0 +1,5 @@ +@import url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/imported.css"); + +a { + background: url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/import/absolute-url.imports.json b/crates/swc_css_modules/tests/fixture/import/absolute-url.imports.json new file mode 100644 index 00000000000..e0c091595e4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/absolute-url.imports.json @@ -0,0 +1,3 @@ +[ + "https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/imported.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/alias.compiled.css b/crates/swc_css_modules/tests/fixture/import/alias.compiled.css new file mode 100644 index 00000000000..f47650d28f8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/alias.compiled.css @@ -0,0 +1,3 @@ +.__local__alias { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/alias.css b/crates/swc_css_modules/tests/fixture/import/alias.css new file mode 100644 index 00000000000..17fd95e02f8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/alias.css @@ -0,0 +1,3 @@ +.alias { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/alias.transform.json b/crates/swc_css_modules/tests/fixture/import/alias.transform.json new file mode 100644 index 00000000000..da886711f69 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/alias.transform.json @@ -0,0 +1,8 @@ +{ + "alias": [ + { + "type": "local", + "name": "__local__alias" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/circular-nested.compiled.css b/crates/swc_css_modules/tests/fixture/import/circular-nested.compiled.css new file mode 100644 index 00000000000..1449e181de1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular-nested.compiled.css @@ -0,0 +1,4 @@ +@import url(circular.css); +div { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/circular-nested.css b/crates/swc_css_modules/tests/fixture/import/circular-nested.css new file mode 100644 index 00000000000..c11f930ca39 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular-nested.css @@ -0,0 +1,5 @@ +@import url(circular.css); + +div { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/circular-nested.imports.json b/crates/swc_css_modules/tests/fixture/import/circular-nested.imports.json new file mode 100644 index 00000000000..56952dc37db --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular-nested.imports.json @@ -0,0 +1,3 @@ +[ + "circular.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/circular.compiled.css b/crates/swc_css_modules/tests/fixture/import/circular.compiled.css new file mode 100644 index 00000000000..c6746604205 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular.compiled.css @@ -0,0 +1,6 @@ +@import url(circular.css); +@import url(circular.css); +@import url("relative.css"); +a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/circular.css b/crates/swc_css_modules/tests/fixture/import/circular.css new file mode 100644 index 00000000000..2d46cad5be2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular.css @@ -0,0 +1,11 @@ +@import url(circular.css); +@import url(circular.css); +/* + // TODO fixed nested circular `@import` + @import url(circular-nested.css); +*/ +@import url("relative.css"); + +a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/circular.imports.json b/crates/swc_css_modules/tests/fixture/import/circular.imports.json new file mode 100644 index 00000000000..d91970e761c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/circular.imports.json @@ -0,0 +1,4 @@ +[ + "circular.css", + "relative.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/data-uri.compiled.css b/crates/swc_css_modules/tests/fixture/import/data-uri.compiled.css new file mode 100644 index 00000000000..718e7ac04c9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/data-uri.compiled.css @@ -0,0 +1,5 @@ +@import url("data:text/css;charset=utf-8;base64,YSB7DQogIGNvbG9yOiByZWQ7DQp9"); +a { + display: block; + width: 100px; +} diff --git a/crates/swc_css_modules/tests/fixture/import/data-uri.css b/crates/swc_css_modules/tests/fixture/import/data-uri.css new file mode 100644 index 00000000000..d4bb2b27380 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/data-uri.css @@ -0,0 +1,6 @@ +@import url("data:text/css;charset=utf-8;base64,YSB7DQogIGNvbG9yOiByZWQ7DQp9"); + +a { + display: block; + width: 100px; +} diff --git a/crates/swc_css_modules/tests/fixture/import/data-uri.imports.json b/crates/swc_css_modules/tests/fixture/import/data-uri.imports.json new file mode 100644 index 00000000000..7f382094c08 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/data-uri.imports.json @@ -0,0 +1,3 @@ +[ + "data:text/css;charset=utf-8;base64,YSB7DQogIGNvbG9yOiByZWQ7DQp9" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.compiled.css new file mode 100644 index 00000000000..b1b7b24dc75 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.compiled.css @@ -0,0 +1,6 @@ +@import url("./import-with-layer.css") layer(form); +@layer form { + .__local__bar { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.css new file mode 100644 index 00000000000..b7f5bda32d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.css @@ -0,0 +1,7 @@ +@import url("./import-with-layer.css") layer(form); + +@layer form { + .bar { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.imports.json new file mode 100644 index 00000000000..18054b22116 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.imports.json @@ -0,0 +1,3 @@ +[ + "./import-with-layer.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.transform.json new file mode 100644 index 00000000000..f595edbe3de --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-layer.transform.json @@ -0,0 +1,8 @@ +{ + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.compiled.css new file mode 100644 index 00000000000..9f8b27df758 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.compiled.css @@ -0,0 +1 @@ +@import url("./import-with-media.css") screen and (min-width: 400px); diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.css new file mode 100644 index 00000000000..befb5cf6700 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.css @@ -0,0 +1 @@ +@import url("./import-with-media.css") screen and (min-width: 400px); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.imports.json new file mode 100644 index 00000000000..44c73786cfb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-media.imports.json @@ -0,0 +1,3 @@ +[ + "./import-with-media.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.compiled.css new file mode 100644 index 00000000000..03e231f1f1e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.compiled.css @@ -0,0 +1 @@ +@import url("./import-with-supports.css") supports(display: block); diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.css b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.css new file mode 100644 index 00000000000..6264f97310e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.css @@ -0,0 +1 @@ +@import url("./import-with-supports.css") supports(display: block); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.imports.json new file mode 100644 index 00000000000..c7191853a5a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-import-with-supports.imports.json @@ -0,0 +1,3 @@ +[ + "./import-with-supports.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-base.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.compiled.css new file mode 100644 index 00000000000..ab83c83bcbc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.compiled.css @@ -0,0 +1,2 @@ +@import url("./relative.css") layer; +@import url("./test.css") layer; diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-base.css b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.css new file mode 100644 index 00000000000..550ec2a545f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.css @@ -0,0 +1,3 @@ +/* unnamed wrapper layers around each sub-file */ +@import url("./relative.css") layer; +@import url("./test.css") layer; diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-base.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.imports.json new file mode 100644 index 00000000000..fbfec2d3424 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-base.imports.json @@ -0,0 +1,4 @@ +[ + "./relative.css", + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.compiled.css new file mode 100644 index 00000000000..afffaada4ef --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.compiled.css @@ -0,0 +1 @@ +@import url("./deep-layer-base.css") layer(base); diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.css b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.css new file mode 100644 index 00000000000..90a7710cc5d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.css @@ -0,0 +1,2 @@ +/* the internal names are hidden from access, subsumed in "base" */ +@import url("./deep-layer-base.css") layer(base); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.imports.json new file mode 100644 index 00000000000..b42c6a2f224 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer-first-level.imports.json @@ -0,0 +1,3 @@ +[ + "./deep-layer-base.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/deep-layer.compiled.css new file mode 100644 index 00000000000..271b3cd60e7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer.compiled.css @@ -0,0 +1,6 @@ +@import url(./deep-layer-first-level.css) layer(bootstrap); +@layer bootstrap { + .__local__test { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer.css b/crates/swc_css_modules/tests/fixture/import/deep-layer.css new file mode 100644 index 00000000000..2fe422a795a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer.css @@ -0,0 +1,8 @@ +@import url(./deep-layer-first-level.css) layer(bootstrap); + +/* Adds additional styles to the bootstrap layer: */ +@layer bootstrap { + .test { + color: red; + } +} \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/deep-layer.imports.json new file mode 100644 index 00000000000..34c9c6fc6f4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer.imports.json @@ -0,0 +1,3 @@ +[ + "./deep-layer-first-level.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/deep-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/deep-layer.transform.json new file mode 100644 index 00000000000..8b4747fe291 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/deep-layer.transform.json @@ -0,0 +1,8 @@ +{ + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/extensions-imported.mycss b/crates/swc_css_modules/tests/fixture/import/extensions-imported.mycss new file mode 100644 index 00000000000..538fa56f4ac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/extensions-imported.mycss @@ -0,0 +1,3 @@ +div { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/extensions.compiled.css b/crates/swc_css_modules/tests/fixture/import/extensions.compiled.css new file mode 100644 index 00000000000..a09ba588a24 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/extensions.compiled.css @@ -0,0 +1,4 @@ +@import url(./extensions-imported); +a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/extensions.css b/crates/swc_css_modules/tests/fixture/import/extensions.css new file mode 100644 index 00000000000..7b6fe66a8e5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/extensions.css @@ -0,0 +1,5 @@ +@import url(./extensions-imported); + +a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/extensions.imports.json b/crates/swc_css_modules/tests/fixture/import/extensions.imports.json new file mode 100644 index 00000000000..4f62d94ff76 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/extensions.imports.json @@ -0,0 +1,3 @@ +[ + "./extensions-imported" +] diff --git a/crates/swc_css_modules/tests/fixture/import/false-alias.compiled.css b/crates/swc_css_modules/tests/fixture/import/false-alias.compiled.css new file mode 100644 index 00000000000..4d2c9e767f3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/false-alias.compiled.css @@ -0,0 +1,4 @@ +@import "/style.css"; +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/false-alias.css b/crates/swc_css_modules/tests/fixture/import/false-alias.css new file mode 100644 index 00000000000..2be9b58fba6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/false-alias.css @@ -0,0 +1,5 @@ +@import "/style.css"; + +.class { + color: red; +} \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/false-alias.imports.json b/crates/swc_css_modules/tests/fixture/import/false-alias.imports.json new file mode 100644 index 00000000000..842f93c4ab9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/false-alias.imports.json @@ -0,0 +1,3 @@ +[ + "/style.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/false-alias.transform.json b/crates/swc_css_modules/tests/fixture/import/false-alias.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/false-alias.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-conditionNames.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.compiled.css new file mode 100644 index 00000000000..110ef1ae7c1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.compiled.css @@ -0,0 +1 @@ +@import "~package-with-exports"; diff --git a/crates/swc_css_modules/tests/fixture/import/import-conditionNames.css b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.css new file mode 100644 index 00000000000..110ef1ae7c1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.css @@ -0,0 +1 @@ +@import "~package-with-exports"; diff --git a/crates/swc_css_modules/tests/fixture/import/import-conditionNames.imports.json b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.imports.json new file mode 100644 index 00000000000..13cda01deb3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-conditionNames.imports.json @@ -0,0 +1,3 @@ +[ + "~package-with-exports" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.compiled.css new file mode 100644 index 00000000000..16f461fd1ad --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.compiled.css @@ -0,0 +1 @@ +@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); diff --git a/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.css b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.css new file mode 100644 index 00000000000..661f7a55d67 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.css @@ -0,0 +1 @@ +@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.imports.json b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.imports.json new file mode 100644 index 00000000000..10ba42caaf6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-deep-with-supports-and-media.imports.json @@ -0,0 +1,3 @@ +[ + "./import-with-supports-and-media.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.compiled.css new file mode 100644 index 00000000000..0b97bfb4ea1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.compiled.css @@ -0,0 +1,5 @@ +@import url("./test.css") layer; +@import url("./relative.css") layer; +.__local__foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.css b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.css new file mode 100644 index 00000000000..d701600bc26 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.css @@ -0,0 +1,6 @@ +@import url("./test.css") layer; +@import url("./relative.css") layer; + +.foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.imports.json new file mode 100644 index 00000000000..fbfec2d3424 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.imports.json @@ -0,0 +1,4 @@ +[ + "./relative.css", + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-unnamed-layer.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.compiled.css new file mode 100644 index 00000000000..c6dca5b23fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.compiled.css @@ -0,0 +1,7 @@ +@import url('./test.css') layer(base); +@import url('./relative.css') layer(base); +@layer base { + .__local__foo { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.css b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.css new file mode 100644 index 00000000000..cc01fd45bb9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.css @@ -0,0 +1,8 @@ +@import url('./test.css') layer(base); +@import url('./relative.css') layer(base); + +@layer base { + .foo { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.imports.json new file mode 100644 index 00000000000..fbfec2d3424 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.imports.json @@ -0,0 +1,4 @@ +[ + "./relative.css", + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-multiple-with-layer.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-order.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-order.compiled.css new file mode 100644 index 00000000000..f758ecfa995 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-order.compiled.css @@ -0,0 +1,3 @@ +@import "test"; +@import "issue-683"; +@import "aliasesPackage"; diff --git a/crates/swc_css_modules/tests/fixture/import/import-order.css b/crates/swc_css_modules/tests/fixture/import/import-order.css new file mode 100644 index 00000000000..f758ecfa995 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-order.css @@ -0,0 +1,3 @@ +@import "test"; +@import "issue-683"; +@import "aliasesPackage"; diff --git a/crates/swc_css_modules/tests/fixture/import/import-order.imports.json b/crates/swc_css_modules/tests/fixture/import/import-order.imports.json new file mode 100644 index 00000000000..47856de06fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-order.imports.json @@ -0,0 +1,5 @@ +[ + "aliasesPackage", + "issue-683", + "test" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.compiled.css new file mode 100644 index 00000000000..bec8e22b95f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.compiled.css @@ -0,0 +1,5 @@ +@import url(/import/test.css); +@import "/import/test.css"; +.__local__class { + a: b c d; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.css b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.css new file mode 100644 index 00000000000..61bc392b44b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.css @@ -0,0 +1,6 @@ +@import url(/import/test.css); +@import "/import/test.css"; + +.class { + a: b c d; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.imports.json b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.imports.json new file mode 100644 index 00000000000..3ba800fdadd --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.imports.json @@ -0,0 +1,3 @@ +[ + "/import/test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.transform.json b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-server-relative-url.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.compiled.css new file mode 100644 index 00000000000..90783121dec --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.compiled.css @@ -0,0 +1,4 @@ +@import url("./test.css") layer; +.__local__foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.css b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.css new file mode 100644 index 00000000000..c3fbb53b265 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.css @@ -0,0 +1,5 @@ +@import url("./test.css") layer; + +.foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-unnamed-layer.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.compiled.css new file mode 100644 index 00000000000..a892fd44d4d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.compiled.css @@ -0,0 +1 @@ +@import url("./test.css") layer(base) supports(display: grid) screen and (min-width: 900px); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.css new file mode 100644 index 00000000000..6b946d233f6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.css @@ -0,0 +1 @@ +@import url("./test.css") layer(base) supports(display: grid) screen and (min-width: 900px); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports-and-media.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.compiled.css new file mode 100644 index 00000000000..cc63ebeb4c9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.compiled.css @@ -0,0 +1 @@ +@import url('./test.css') layer(base); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.css new file mode 100644 index 00000000000..9fa9cbdc260 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.css @@ -0,0 +1 @@ +@import url('./test.css') layer(base); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-and-supports.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.compiled.css new file mode 100644 index 00000000000..6b4900f05f4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.compiled.css @@ -0,0 +1 @@ +@import url('./test.css') layer; diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.css new file mode 100644 index 00000000000..1d8c4a8ed59 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.css @@ -0,0 +1 @@ +@import url('./test.css') layer; \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer-unnamed.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer.compiled.css new file mode 100644 index 00000000000..e4a00c21dd7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer.compiled.css @@ -0,0 +1,6 @@ +@import url('./test.css') layer(base); +@layer base { + .__local__foo { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer.css b/crates/swc_css_modules/tests/fixture/import/import-with-layer.css new file mode 100644 index 00000000000..218aa9c38cc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer.css @@ -0,0 +1,7 @@ +@import url('./test.css') layer(base); + +@layer base { + .foo { + color: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-layer.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-layer.transform.json b/crates/swc_css_modules/tests/fixture/import/import-with-layer.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-layer.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-media.compiled.css new file mode 100644 index 00000000000..c0139dc37bb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-media.compiled.css @@ -0,0 +1 @@ +@import url('./test.css') screen and (max-width: 1200px); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-media.css b/crates/swc_css_modules/tests/fixture/import/import-with-media.css new file mode 100644 index 00000000000..c0139dc37bb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-media.css @@ -0,0 +1 @@ +@import url('./test.css') screen and (max-width: 1200px); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-media.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-media.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-media.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.compiled.css new file mode 100644 index 00000000000..b784d2426de --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.compiled.css @@ -0,0 +1 @@ +@import url('./test.css') supports(display: grid) screen and (max-width: 1200px); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.css b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.css new file mode 100644 index 00000000000..5829b0b3604 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.css @@ -0,0 +1 @@ +@import url('./test.css') supports(display: grid) screen and (max-width: 1200px); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports-and-media.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports.compiled.css b/crates/swc_css_modules/tests/fixture/import/import-with-supports.compiled.css new file mode 100644 index 00000000000..d0a0b354ef8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports.compiled.css @@ -0,0 +1 @@ +@import url('./test.css') supports(display: grid); diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports.css b/crates/swc_css_modules/tests/fixture/import/import-with-supports.css new file mode 100644 index 00000000000..218435a6698 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports.css @@ -0,0 +1 @@ +@import url('./test.css') supports(display: grid); \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/import/import-with-supports.imports.json b/crates/swc_css_modules/tests/fixture/import/import-with-supports.imports.json new file mode 100644 index 00000000000..be46fb84fd0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import-with-supports.imports.json @@ -0,0 +1,3 @@ +[ + "./test.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import.compiled.css b/crates/swc_css_modules/tests/fixture/import/import.compiled.css new file mode 100644 index 00000000000..9b1bdcb3eeb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import.compiled.css @@ -0,0 +1,168 @@ +@import url(test.css); +@import url('test.css'); +@import url("test.css"); +@IMPORT url(test.css); +@import URL(test.css); +@import url(test.css ); +@import url( test.css); +@import url( test.css ); +@import url( + test.css +); +@import url(); +@import url(''); +@import url(""); +@import "test.css"; +@import 'test.css'; +@import ''; +@import ""; +@import " "; +@import url(); +@import url(''); +@import url(""); +@import url(test.css) screen and (orientation: landscape); +@import url(test.css) SCREEN AND (ORIENTATION: LANDSCAPE); +@import url(test.css) screen and (orientation: landscape); +@import url(test.css) screen and (orientation: landscape); +@import url(test-media.css) screen and (orientation: landscape); +@import url(test-other.css) (min-width: 100px); +@import url(http://example.com/style.css); +@import url(http://example.com/style.css); +@import url(http://example.com/style.css#hash); +@import url(http://example.com/style.css?#hash); +@import url(http://example.com/style.css?foo=bar#hash); +@import url(http://example.com/other-style.css) screen and (orientation: landscape); +@import url(http://example.com/other-style.css) screen and (orientation: landscape); +@import url("//example.com/style.css"); +@import url(~package/test.css); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} +@import url('query.css?foo=1&bar=1'); +@import url('other-query.css?foo=1&bar=1#hash'); +@import url('other-query.css?foo=1&bar=1#hash') screen and (orientation: landscape); +@import url('https://fonts.googleapis.com/css?family=Roboto'); +@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC'); +@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto'); +.__local__class { + a: b c d; +} +.__local__foo { + @import 'path.css'; +} +@import url('./relative.css'); +@import url('../import/top-relative.css'); +@import url(~package/tilde.css); +@import url(~aliasesImport/alias.css); +@import url('./url.css'); +.__local__background { + background: url('./img.png'); +} +@import url(./test.css); +@import './te\ +st.css'; +@import './te\ +\ +\ +st.css'; +@import url('./te\ +st.css'); +@import url('./te\ +\ +\ +st.css'); +@import "./te'st.css"; +@import url("./te'st.css"); +@import './te\'st.css'; +@import url('./te\'st.css'); +@import './test test.css'; +@import url('./test test.css'); +@import './test\ test.css'; +@import url('./test\ test.css'); +@import './test%20test.css'; +@import url('./test%20test.css'); +@import './\74\65\73\74.css'; +@import url('./\74\65\73\74.css'); +@import './t\65\73\74.css'; +@import url('./t\65\73\74.css'); +@import url(./test\ test.css); +@import url(./t\65st%20test.css); +@import url('./t\65st%20test.css'); +@import url("./t\65st%20test.css"); +@import "./t\65st%20test.css"; +@import './t\65st%20test.css'; +@import url( test.css ); +@import nourl(test.css); +@import '\ +\ +\ +'; +@import url('!!../../helpers/string-loader.js?esModule=false!~package/tilde.css'); +@import url(test.css?foo=bar); +@import url(test.css?foo=bar#hash); +@import url(test.css?#hash); +@import "test.css" supports(display: flex); +@import "test.css" supports(display: flex) screen and (orientation: landscape); +@import url('something.css'); +@import url('something.css'); +@import url('something.css?foo=bar'); +@import url('something.css?foo=bar'); +@import url('something.css?foo=bar#hash'); +@import url('something.css?foo=bar#hash'); +@import url('something.css?foo=bar'); +@import url('something.css?bar=foo'); +@import url('something.css?foo=bar#one'); +@import url('something.css?foo=bar#two'); +@import url('something.css?foo=1&bar=2'); +@import url('something.css?foo=2&bar=1'); +@import " ./test.css "; +@import url(' ./test.css '); +@import url( ./test.css ); +@import "./my.scss"; +@import url(' https://fonts.googleapis.com/css?family=Roboto '); +@import url('!!../../helpers/string-loader.js?esModule=false!'); +@import url(' !!../../helpers/string-loader.js?esModule=false!~package/tilde.css '); +@import url(data:text/css;charset=utf-8,a%20%7B%0D%0A%20%20color%3A%20red%3B%0D%0A%7D); +@import url(package/first.css); +@import url(package/second.css); +@import url("./test.css") supports(); +@import url("./test.css") supports(unknown); +@import url("./test.css") supports(display: flex); +@import url("./test.css") supports(display: flex !important); +@import url("./test.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer; +@import url("./test.css") layer(default); +@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer() supports(display: flex) screen and (min-width: 400px); +@import url("./test.css"); +@import url("http://example.com/style.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") screen and (min-width: 400px); +@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") LAYER(DEFAULT) supports(DISPLAY: FLEX) SCREEN AND (MIN-WIDTH: 400PX); +@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url(test.css); +@import url(test.css); +@import url(test.css) print and (orientation: landscape); +@import url(test.css) print and (orientation: landscape); +@import url("./import-with-media.css") screen and (min-width: 400px); +@import url("./deep-import-with-media.css") (prefers-color-scheme: dark); +@import url("./import-with-supports.css") supports(display: flex); +@import url("./import-with-supports.css") supports(((display: flex))); +@import url("./deep-import-with-supports.css") supports(display: flex); +@import url('./test.css') supports(display: grid); +@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); +@import url("./import-deep-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer(framework); +@import url("./import-with-layer.css") layer(framework); +@import url("./deep-import-with-layer.css") layer(framework); +@import url("./import-multiple-with-layer.css") layer(default); +@import url("./import-with-layer-unnamed.css") layer(default); +@import url("./import-unnamed-layer.css") layer(base); +@import url("./import-multiple-unnamed-layer.css") layer(base); +@import url("./import-with-layer-and-supports.css") layer(default) supports(display: flex); +@import url("./import-with-layer-and-supports-and-media.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./deep-layer.css"); +@import url("./test.css") unknown(default) unknown(display: flex) unknown; diff --git a/crates/swc_css_modules/tests/fixture/import/import.css b/crates/swc_css_modules/tests/fixture/import/import.css new file mode 100644 index 00000000000..0bac822253f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import.css @@ -0,0 +1,203 @@ +@import url(test.css); +@import url('test.css'); +@import url("test.css"); +@IMPORT url(test.css); +@import URL(test.css); +@import url(test.css ); +@import url( test.css); +@import url( test.css ); +@import url( + test.css +); +@import url(); +@import url(''); +@import url(""); +@import "test.css"; +@import 'test.css'; +@import ''; +@import ""; +@import " "; +@import " +"; +@import url(); +@import url(''); +@import url(""); +@import url(test.css) screen and (orientation:landscape); +@import url(test.css) SCREEN AND (ORIENTATION: LANDSCAPE); +@import url(test.css)screen and (orientation:landscape); +@import url(test.css) screen and (orientation:landscape); +@import url(test-media.css) screen and (orientation:landscape); +@import url(test-other.css) (min-width: 100px); +@import url(http://example.com/style.css); +@import url(http://example.com/style.css); +@import url(http://example.com/style.css#hash); +@import url(http://example.com/style.css?#hash); +@import url(http://example.com/style.css?foo=bar#hash); +@import url(http://example.com/other-style.css) screen and (orientation:landscape); +@import url(http://example.com/other-style.css) screen and (orientation:landscape); +@import url("//example.com/style.css"); +@import url(~package/test.css); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} +@import url('query.css?foo=1&bar=1'); +@import url('other-query.css?foo=1&bar=1#hash'); +@import url('other-query.css?foo=1&bar=1#hash') screen and (orientation:landscape); +@import url('https://fonts.googleapis.com/css?family=Roboto'); +@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC'); +@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto'); + +.class { + a: b c d; +} + +.foo { + @import 'path.css'; +} + +@import url('./relative.css'); +@import url('../import/top-relative.css'); +@import url(~package/tilde.css); +@import url(~aliasesImport/alias.css); +@import url('./url.css'); + +.background { + background: url('./img.png'); +} + +@import url(./test.css); + +@import './te\ +st.css'; +@import './te\ +\ +\ +st.css'; +@import url('./te\ +st.css'); +@import url('./te\ +\ +\ +st.css'); + +@import "./te'st.css"; +@import url("./te'st.css"); +@import './te\'st.css'; +@import url('./te\'st.css'); +@import './test test.css'; +@import url('./test test.css'); +@import './test\ test.css'; +@import url('./test\ test.css'); +@import './test%20test.css'; +@import url('./test%20test.css'); +@import './\74\65\73\74.css'; +@import url('./\74\65\73\74.css'); +@import './t\65\73\74.css'; +@import url('./t\65\73\74.css'); +@import url(./test\ test.css); +@import url(./t\65st%20test.css); +@import url('./t\65st%20test.css'); +@import url("./t\65st%20test.css"); +@import "./t\65st%20test.css"; +@import './t\65st%20test.css'; +@import url( test.css ); +@import nourl(test.css); +@import '\ +\ +\ +'; +@import url('!!../../helpers/string-loader.js?esModule=false!~package/tilde.css'); +@import url(test.css?foo=bar); +@import url(test.css?foo=bar#hash); +@import url(test.css?#hash); +@import "test.css" supports(display: flex); +@import "test.css" supports(display: flex) screen and (orientation:landscape); + +/* Should be one import and two css modules */ + +@import url('something.css'); +@import url('something.css'); + +/* Should be one import and two css modules */ + +@import url('something.css?foo=bar'); +@import url('something.css?foo=bar'); + +/* Should be one import and two css modules */ + +@import url('something.css?foo=bar#hash'); +@import url('something.css?foo=bar#hash'); + +/* Should be two import and two css modules */ + +@import url('something.css?foo=bar'); +@import url('something.css?bar=foo'); + +/* Should be two import and two css modules */ + +@import url('something.css?foo=bar#one'); +@import url('something.css?foo=bar#two'); + +/* Should be two import and two css modules */ + +@import url('something.css?foo=1&bar=2'); +@import url('something.css?foo=2&bar=1'); + +@import " ./test.css "; +@import url(' ./test.css '); +@import url( ./test.css ); + +@import "./my.scss"; + +@import url(' https://fonts.googleapis.com/css?family=Roboto '); +@import url('!!../../helpers/string-loader.js?esModule=false!'); +@import url(' !!../../helpers/string-loader.js?esModule=false!~package/tilde.css '); +@import url(data:text/css;charset=utf-8,a%20%7B%0D%0A%20%20color%3A%20red%3B%0D%0A%7D); + +/* Prefer relative */ +@import url(package/first.css); +@import url(package/second.css); + +@import url("./test.css") supports(); +@import url("./test.css") supports(unknown); +@import url("./test.css") supports(display: flex); +@import url("./test.css") supports(display: flex !important); +@import url("./test.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer; +@import url("./test.css") layer(default); +@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer() supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer(); +@import url("http://example.com/style.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css")layer(default)supports(display: flex)screen and (min-width:400px); +@import url("./test.css")screen and (min-width: 400px); +@import url("./test.css") layer( default ) supports( display : flex ) screen and ( min-width : 400px ); +@import url("./test.css") LAYER(DEFAULT) SUPPORTS(DISPLAY: FLEX) SCREEN AND (MIN-WIDTH: 400PX); +@import url("./test.css") /* Comment */ layer(/* Comment */default/* Comment */) /* Comment */ supports(/* Comment */display/* Comment */:/* Comment */ flex/* Comment */)/* Comment */ screen/* Comment */ and/* Comment */ (/* Comment */min-width/* Comment */: /* Comment */400px/* Comment */); +@import url(test.css) /* Comment */; +@import /* Comment */ url(test.css) /* Comment */; +@import url(test.css) /* Comment */ print and (orientation:landscape); +@import /* Comment */ url(test.css) /* Comment */ print and (orientation:landscape); + +@import url("./import-with-media.css") screen and (min-width: 400px); +@import url("./deep-import-with-media.css") (prefers-color-scheme: dark); +@import url("./import-with-supports.css") supports(display: flex); +@import url("./import-with-supports.css") supports(((display: flex))); +@import url("./deep-import-with-supports.css") supports(display: flex); +@import url('./test.css') supports(display: grid); +@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); +@import url("./import-deep-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px); +@import url("./test.css") layer(framework); +@import url("./import-with-layer.css") layer(framework); +@import url("./deep-import-with-layer.css") layer(framework); +@import url("./import-multiple-with-layer.css") layer(default); +@import url("./import-with-layer-unnamed.css") layer(default); +@import url("./import-unnamed-layer.css") layer(base); +@import url("./import-multiple-unnamed-layer.css") layer(base); +@import url("./import-with-layer-and-supports.css") layer(default) supports(display: flex); +@import url("./import-with-layer-and-supports-and-media.css") layer(default) supports(display: flex) screen and (min-width: 400px); +@import url("./deep-layer.css"); + +@import url("./test.css") unknown(default) unknown(display: flex) unknown; diff --git a/crates/swc_css_modules/tests/fixture/import/import.imports.json b/crates/swc_css_modules/tests/fixture/import/import.imports.json new file mode 100644 index 00000000000..a12b1b5e894 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import.imports.json @@ -0,0 +1,64 @@ +[ + "", + " ", + " !!../../helpers/string-loader.js?esModule=false!~package/tilde.css ", + " ./test.css ", + " https://fonts.googleapis.com/css?family=Roboto ", + "!!../../helpers/string-loader.js?esModule=false!", + "!!../../helpers/string-loader.js?esModule=false!~package/tilde.css", + "../import/top-relative.css", + "./deep-import-with-layer.css", + "./deep-import-with-media.css", + "./deep-import-with-supports.css", + "./deep-layer.css", + "./import-deep-with-supports-and-media.css", + "./import-multiple-unnamed-layer.css", + "./import-multiple-with-layer.css", + "./import-unnamed-layer.css", + "./import-with-layer-and-supports-and-media.css", + "./import-with-layer-and-supports.css", + "./import-with-layer-unnamed.css", + "./import-with-layer.css", + "./import-with-media.css", + "./import-with-supports-and-media.css", + "./import-with-supports.css", + "./my.scss", + "./relative.css", + "./te'st.css", + "./test test.css", + "./test%20test.css", + "./test.css", + "./url.css", + "//example.com/style.css", + "data:text/css;charset=utf-8,a%20%7B%0D%0A%20%20color%3A%20red%3B%0D%0A%7D", + "http://example.com/other-style.css", + "http://example.com/style.css", + "http://example.com/style.css#hash", + "http://example.com/style.css?#hash", + "http://example.com/style.css?foo=bar#hash", + "https://fonts.googleapis.com/css?family=Noto+Sans+TC", + "https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto", + "https://fonts.googleapis.com/css?family=Roboto", + "other-query.css?foo=1&bar=1#hash", + "package/first.css", + "package/second.css", + "path.css", + "query.css?foo=1&bar=1", + "something.css", + "something.css?bar=foo", + "something.css?foo=1&bar=2", + "something.css?foo=2&bar=1", + "something.css?foo=bar", + "something.css?foo=bar#hash", + "something.css?foo=bar#one", + "something.css?foo=bar#two", + "test-media.css", + "test-other.css", + "test.css", + "test.css?#hash", + "test.css?foo=bar", + "test.css?foo=bar#hash", + "~aliasesImport/alias.css", + "~package/test.css", + "~package/tilde.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/import.transform.json b/crates/swc_css_modules/tests/fixture/import/import.transform.json new file mode 100644 index 00000000000..bf4985921d9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/import.transform.json @@ -0,0 +1,20 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ], + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "background": [ + { + "type": "local", + "name": "__local__background" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/issue-683.compiled.css b/crates/swc_css_modules/tests/fixture/import/issue-683.compiled.css new file mode 100644 index 00000000000..beed9687342 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/issue-683.compiled.css @@ -0,0 +1 @@ +@import "~issue-683-package"; diff --git a/crates/swc_css_modules/tests/fixture/import/issue-683.css b/crates/swc_css_modules/tests/fixture/import/issue-683.css new file mode 100644 index 00000000000..beed9687342 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/issue-683.css @@ -0,0 +1 @@ +@import "~issue-683-package"; diff --git a/crates/swc_css_modules/tests/fixture/import/issue-683.imports.json b/crates/swc_css_modules/tests/fixture/import/issue-683.imports.json new file mode 100644 index 00000000000..51aa342b652 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/issue-683.imports.json @@ -0,0 +1,3 @@ +[ + "~issue-683-package" +] diff --git a/crates/swc_css_modules/tests/fixture/import/order-1.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-1.compiled.css new file mode 100644 index 00000000000..700c1d0442b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-1.compiled.css @@ -0,0 +1,3 @@ +.__local__order-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-1.css b/crates/swc_css_modules/tests/fixture/import/order-1.css new file mode 100644 index 00000000000..3e23caf85ef --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-1.css @@ -0,0 +1,3 @@ +.order-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-1.transform.json b/crates/swc_css_modules/tests/fixture/import/order-1.transform.json new file mode 100644 index 00000000000..eb697abe2fc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-1.transform.json @@ -0,0 +1,8 @@ +{ + "order-1": [ + { + "type": "local", + "name": "__local__order-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-2.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-2.compiled.css new file mode 100644 index 00000000000..a03749117c1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-2.compiled.css @@ -0,0 +1,3 @@ +.__local__order-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-2.css b/crates/swc_css_modules/tests/fixture/import/order-2.css new file mode 100644 index 00000000000..a7c5b2c5633 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-2.css @@ -0,0 +1,3 @@ +.order-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-2.transform.json b/crates/swc_css_modules/tests/fixture/import/order-2.transform.json new file mode 100644 index 00000000000..feca8a055df --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-2.transform.json @@ -0,0 +1,8 @@ +{ + "order-2": [ + { + "type": "local", + "name": "__local__order-2" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3-1.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-3-1.compiled.css new file mode 100644 index 00000000000..61c243208e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3-1.compiled.css @@ -0,0 +1,3 @@ +.__local__order-3-1 { + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3-1.css b/crates/swc_css_modules/tests/fixture/import/order-3-1.css new file mode 100644 index 00000000000..f34c6020639 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3-1.css @@ -0,0 +1,3 @@ +.order-3-1 { + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3-1.transform.json b/crates/swc_css_modules/tests/fixture/import/order-3-1.transform.json new file mode 100644 index 00000000000..e32f1cb1949 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3-1.transform.json @@ -0,0 +1,8 @@ +{ + "order-3-1": [ + { + "type": "local", + "name": "__local__order-3-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-3.compiled.css new file mode 100644 index 00000000000..0de521ae824 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3.compiled.css @@ -0,0 +1,4 @@ +@import url('./order-3-1.css') screen and (orientation: landscape); +.__local__order-3 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3.css b/crates/swc_css_modules/tests/fixture/import/order-3.css new file mode 100644 index 00000000000..2894e271576 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3.css @@ -0,0 +1,5 @@ +@import url('./order-3-1.css') screen and (orientation:landscape); + +.order-3 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-3.imports.json b/crates/swc_css_modules/tests/fixture/import/order-3.imports.json new file mode 100644 index 00000000000..15ac8b3fc1d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3.imports.json @@ -0,0 +1,3 @@ +[ + "./order-3-1.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/order-3.transform.json b/crates/swc_css_modules/tests/fixture/import/order-3.transform.json new file mode 100644 index 00000000000..532d6f5cb45 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-3.transform.json @@ -0,0 +1,8 @@ +{ + "order-3": [ + { + "type": "local", + "name": "__local__order-3" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-1.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-4-1.compiled.css new file mode 100644 index 00000000000..691613b6d1a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-1.compiled.css @@ -0,0 +1,3 @@ +.__local__order-4-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-1.css b/crates/swc_css_modules/tests/fixture/import/order-4-1.css new file mode 100644 index 00000000000..d80177cb7ea --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-1.css @@ -0,0 +1,3 @@ +.order-4-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-1.transform.json b/crates/swc_css_modules/tests/fixture/import/order-4-1.transform.json new file mode 100644 index 00000000000..6c7b2c7f567 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-1.transform.json @@ -0,0 +1,8 @@ +{ + "order-4-1": [ + { + "type": "local", + "name": "__local__order-4-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-1.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.compiled.css new file mode 100644 index 00000000000..78661ccfd00 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.compiled.css @@ -0,0 +1,3 @@ +.__local__order-4-2-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-1.css b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.css new file mode 100644 index 00000000000..d063acd2262 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.css @@ -0,0 +1,3 @@ +.order-4-2-1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-1.transform.json b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.transform.json new file mode 100644 index 00000000000..f5520f58fab --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-1.transform.json @@ -0,0 +1,8 @@ +{ + "order-4-2-1": [ + { + "type": "local", + "name": "__local__order-4-2-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-2.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.compiled.css new file mode 100644 index 00000000000..f87bbd472fe --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.compiled.css @@ -0,0 +1,3 @@ +.__local__order-4-2-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-2.css b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.css new file mode 100644 index 00000000000..851d03b232d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.css @@ -0,0 +1,3 @@ +.order-4-2-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2-2.transform.json b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.transform.json new file mode 100644 index 00000000000..5baf4a6e159 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2-2.transform.json @@ -0,0 +1,8 @@ +{ + "order-4-2-2": [ + { + "type": "local", + "name": "__local__order-4-2-2" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-4-2.compiled.css new file mode 100644 index 00000000000..849bcb43783 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2.compiled.css @@ -0,0 +1,5 @@ +@import url('./order-4-2-1.css'); +@import url('./order-4-2-2.css') (orientation: landscape); +.__local__order-4-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2.css b/crates/swc_css_modules/tests/fixture/import/order-4-2.css new file mode 100644 index 00000000000..319f2869d46 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2.css @@ -0,0 +1,6 @@ +@import url('./order-4-2-1.css'); +@import url('./order-4-2-2.css') (orientation:landscape); + +.order-4-2 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2.imports.json b/crates/swc_css_modules/tests/fixture/import/order-4-2.imports.json new file mode 100644 index 00000000000..650899ec771 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2.imports.json @@ -0,0 +1,4 @@ +[ + "./order-4-2-1.css", + "./order-4-2-2.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/order-4-2.transform.json b/crates/swc_css_modules/tests/fixture/import/order-4-2.transform.json new file mode 100644 index 00000000000..016b7bf057d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4-2.transform.json @@ -0,0 +1,8 @@ +{ + "order-4-2": [ + { + "type": "local", + "name": "__local__order-4-2" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4.compiled.css b/crates/swc_css_modules/tests/fixture/import/order-4.compiled.css new file mode 100644 index 00000000000..e8af6809819 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4.compiled.css @@ -0,0 +1,5 @@ +@import url('./order-4-1.css') (min-width: 1000px); +@import url('./order-4-2.css') (min-width: 2000px); +.__local__order-4 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4.css b/crates/swc_css_modules/tests/fixture/import/order-4.css new file mode 100644 index 00000000000..66940a7113f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4.css @@ -0,0 +1,6 @@ +@import url('./order-4-1.css') (min-width: 1000px); +@import url('./order-4-2.css') (min-width: 2000px); + +.order-4 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order-4.imports.json b/crates/swc_css_modules/tests/fixture/import/order-4.imports.json new file mode 100644 index 00000000000..86e1359e1fc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4.imports.json @@ -0,0 +1,4 @@ +[ + "./order-4-1.css", + "./order-4-2.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/order-4.transform.json b/crates/swc_css_modules/tests/fixture/import/order-4.transform.json new file mode 100644 index 00000000000..8ab58fe5594 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order-4.transform.json @@ -0,0 +1,8 @@ +{ + "order-4": [ + { + "type": "local", + "name": "__local__order-4" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/order.compiled.css b/crates/swc_css_modules/tests/fixture/import/order.compiled.css new file mode 100644 index 00000000000..77f6b74615c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order.compiled.css @@ -0,0 +1,15 @@ +@import url('./order-1.css'); +@import url(http://example.com/style.css); +@import url('./order-2.css'); +@import url(http://example.com/style.css); +@import url('./order-1.css'); +@import url(http://example.com/style.css); +@import url('./order-2.css') screen and (min-width: 2000px); +@import url(http://example.com/style.css); +@import url('./order-3.css'); +@import url(http://example.com/style.css); +@import url('./order-4.css') screen; +div { + width: 100%; + height: 200px; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order.css b/crates/swc_css_modules/tests/fixture/import/order.css new file mode 100644 index 00000000000..0f13810261b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order.css @@ -0,0 +1,16 @@ +@import url('./order-1.css'); +@import url(http://example.com/style.css); +@import url('./order-2.css'); +@import url(http://example.com/style.css); +@import url('./order-1.css'); +@import url(http://example.com/style.css); +@import url('./order-2.css') screen and (min-width: 2000px); +@import url(http://example.com/style.css); +@import url('./order-3.css'); +@import url(http://example.com/style.css); +@import url('./order-4.css') screen; + +div { + width: 100%; + height: 200px; +} diff --git a/crates/swc_css_modules/tests/fixture/import/order.imports.json b/crates/swc_css_modules/tests/fixture/import/order.imports.json new file mode 100644 index 00000000000..9f41d7b8bf4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/order.imports.json @@ -0,0 +1,7 @@ +[ + "./order-1.css", + "./order-2.css", + "./order-3.css", + "./order-4.css", + "http://example.com/style.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/other-query.compiled.css b/crates/swc_css_modules/tests/fixture/import/other-query.compiled.css new file mode 100644 index 00000000000..e17dbaca806 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/other-query.compiled.css @@ -0,0 +1,3 @@ +.__local__other-query { + f: f; +} diff --git a/crates/swc_css_modules/tests/fixture/import/other-query.css b/crates/swc_css_modules/tests/fixture/import/other-query.css new file mode 100644 index 00000000000..a7d49c99bfa --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/other-query.css @@ -0,0 +1,3 @@ +.other-query { + f: f; +} diff --git a/crates/swc_css_modules/tests/fixture/import/other-query.transform.json b/crates/swc_css_modules/tests/fixture/import/other-query.transform.json new file mode 100644 index 00000000000..7d1fd674b44 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/other-query.transform.json @@ -0,0 +1,8 @@ +{ + "other-query": [ + { + "type": "local", + "name": "__local__other-query" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/package/first.compiled.css b/crates/swc_css_modules/tests/fixture/import/package/first.compiled.css new file mode 100644 index 00000000000..e88c6ac3b6f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/package/first.compiled.css @@ -0,0 +1,3 @@ +.__local__first { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/package/first.css b/crates/swc_css_modules/tests/fixture/import/package/first.css new file mode 100644 index 00000000000..ef566be01e7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/package/first.css @@ -0,0 +1,3 @@ +.first { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/package/first.transform.json b/crates/swc_css_modules/tests/fixture/import/package/first.transform.json new file mode 100644 index 00000000000..70e8d6c630a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/package/first.transform.json @@ -0,0 +1,8 @@ +{ + "first": [ + { + "type": "local", + "name": "__local__first" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/query.compiled.css b/crates/swc_css_modules/tests/fixture/import/query.compiled.css new file mode 100644 index 00000000000..f0db458b785 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/query.compiled.css @@ -0,0 +1,3 @@ +.__local__query { + e: e; +} diff --git a/crates/swc_css_modules/tests/fixture/import/query.css b/crates/swc_css_modules/tests/fixture/import/query.css new file mode 100644 index 00000000000..4e9fb508c08 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/query.css @@ -0,0 +1,3 @@ +.query { + e: e; +} diff --git a/crates/swc_css_modules/tests/fixture/import/query.transform.json b/crates/swc_css_modules/tests/fixture/import/query.transform.json new file mode 100644 index 00000000000..e1e5b8ac8cb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/query.transform.json @@ -0,0 +1,8 @@ +{ + "query": [ + { + "type": "local", + "name": "__local__query" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/relative.compiled.css b/crates/swc_css_modules/tests/fixture/import/relative.compiled.css new file mode 100644 index 00000000000..33b64f55344 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/relative.compiled.css @@ -0,0 +1,3 @@ +.__local__relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/relative.css b/crates/swc_css_modules/tests/fixture/import/relative.css new file mode 100644 index 00000000000..73597627ba7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/relative.css @@ -0,0 +1,3 @@ +.relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/relative.transform.json b/crates/swc_css_modules/tests/fixture/import/relative.transform.json new file mode 100644 index 00000000000..ed6b94f045d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/relative.transform.json @@ -0,0 +1,8 @@ +{ + "relative": [ + { + "type": "local", + "name": "__local__relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/something.compiled.css b/crates/swc_css_modules/tests/fixture/import/something.compiled.css new file mode 100644 index 00000000000..5355e595abc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/something.compiled.css @@ -0,0 +1,3 @@ +.__local__my-box { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/something.css b/crates/swc_css_modules/tests/fixture/import/something.css new file mode 100644 index 00000000000..1135b17d1a6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/something.css @@ -0,0 +1,3 @@ +.my-box { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/something.transform.json b/crates/swc_css_modules/tests/fixture/import/something.transform.json new file mode 100644 index 00000000000..e9c3bf2e494 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/something.transform.json @@ -0,0 +1,8 @@ +{ + "my-box": [ + { + "type": "local", + "name": "__local__my-box" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/te'st.compiled.css b/crates/swc_css_modules/tests/fixture/import/te'st.compiled.css new file mode 100644 index 00000000000..16df5f24b78 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/te'st.compiled.css @@ -0,0 +1,3 @@ +.__local__strange { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/te'st.css b/crates/swc_css_modules/tests/fixture/import/te'st.css new file mode 100644 index 00000000000..b4c37197821 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/te'st.css @@ -0,0 +1,3 @@ +.strange { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/import/te'st.transform.json b/crates/swc_css_modules/tests/fixture/import/te'st.transform.json new file mode 100644 index 00000000000..afac51e0ec1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/te'st.transform.json @@ -0,0 +1,8 @@ +{ + "strange": [ + { + "type": "local", + "name": "__local__strange" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/test test.compiled.css b/crates/swc_css_modules/tests/fixture/import/test test.compiled.css new file mode 100644 index 00000000000..861626e64ad --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test test.compiled.css @@ -0,0 +1,3 @@ +.__local__space { + color: gray; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test test.css b/crates/swc_css_modules/tests/fixture/import/test test.css new file mode 100644 index 00000000000..8c6bf2f213d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test test.css @@ -0,0 +1,3 @@ +.space { + color: gray; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test test.transform.json b/crates/swc_css_modules/tests/fixture/import/test test.transform.json new file mode 100644 index 00000000000..0281f0dbeca --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test test.transform.json @@ -0,0 +1,8 @@ +{ + "space": [ + { + "type": "local", + "name": "__local__space" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/test-media.compiled.css new file mode 100644 index 00000000000..7168dfbde69 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-media.compiled.css @@ -0,0 +1,4 @@ +@import url('test-nested-media.css') (min-width: 100px); +.__local__test { + c: c; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-media.css b/crates/swc_css_modules/tests/fixture/import/test-media.css new file mode 100644 index 00000000000..72921bc7434 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-media.css @@ -0,0 +1,5 @@ +@import url('test-nested-media.css') (min-width: 100px); + +.test { + c: c; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-media.imports.json b/crates/swc_css_modules/tests/fixture/import/test-media.imports.json new file mode 100644 index 00000000000..de9dd08a8b8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-media.imports.json @@ -0,0 +1,3 @@ +[ + "test-nested-media.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/test-media.transform.json b/crates/swc_css_modules/tests/fixture/import/test-media.transform.json new file mode 100644 index 00000000000..8b4747fe291 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-media.transform.json @@ -0,0 +1,8 @@ +{ + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-nested-media.compiled.css b/crates/swc_css_modules/tests/fixture/import/test-nested-media.compiled.css new file mode 100644 index 00000000000..8fcc420b811 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-nested-media.compiled.css @@ -0,0 +1,3 @@ +a { + b: b; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-nested-media.css b/crates/swc_css_modules/tests/fixture/import/test-nested-media.css new file mode 100644 index 00000000000..8fcc420b811 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-nested-media.css @@ -0,0 +1,3 @@ +a { + b: b; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-other.compiled.css b/crates/swc_css_modules/tests/fixture/import/test-other.compiled.css new file mode 100644 index 00000000000..538c768f567 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-other.compiled.css @@ -0,0 +1,3 @@ +.__local__test { + d: d; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-other.css b/crates/swc_css_modules/tests/fixture/import/test-other.css new file mode 100644 index 00000000000..fc97be2edb1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-other.css @@ -0,0 +1,3 @@ +.test { + d: d; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test-other.transform.json b/crates/swc_css_modules/tests/fixture/import/test-other.transform.json new file mode 100644 index 00000000000..8b4747fe291 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test-other.transform.json @@ -0,0 +1,8 @@ +{ + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/test.compiled.css b/crates/swc_css_modules/tests/fixture/import/test.compiled.css new file mode 100644 index 00000000000..917dd094f89 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test.compiled.css @@ -0,0 +1,3 @@ +.__local__test { + a: a; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test.css b/crates/swc_css_modules/tests/fixture/import/test.css new file mode 100644 index 00000000000..c931aa2836a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test.css @@ -0,0 +1,3 @@ +.test { + a: a; +} diff --git a/crates/swc_css_modules/tests/fixture/import/test.transform.json b/crates/swc_css_modules/tests/fixture/import/test.transform.json new file mode 100644 index 00000000000..8b4747fe291 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/test.transform.json @@ -0,0 +1,8 @@ +{ + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/top-relative.compiled.css b/crates/swc_css_modules/tests/fixture/import/top-relative.compiled.css new file mode 100644 index 00000000000..167b9f9921a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/top-relative.compiled.css @@ -0,0 +1,3 @@ +.__local__top-relative { + color: black; +} diff --git a/crates/swc_css_modules/tests/fixture/import/top-relative.css b/crates/swc_css_modules/tests/fixture/import/top-relative.css new file mode 100644 index 00000000000..13a954d0111 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/top-relative.css @@ -0,0 +1,3 @@ +.top-relative { + color: black; +} diff --git a/crates/swc_css_modules/tests/fixture/import/top-relative.transform.json b/crates/swc_css_modules/tests/fixture/import/top-relative.transform.json new file mode 100644 index 00000000000..5fbd94088d5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/top-relative.transform.json @@ -0,0 +1,8 @@ +{ + "top-relative": [ + { + "type": "local", + "name": "__local__top-relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/import/unresolved.compiled.css b/crates/swc_css_modules/tests/fixture/import/unresolved.compiled.css new file mode 100644 index 00000000000..6cd410c8a55 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/unresolved.compiled.css @@ -0,0 +1 @@ +@import "unresolved-file.css"; diff --git a/crates/swc_css_modules/tests/fixture/import/unresolved.css b/crates/swc_css_modules/tests/fixture/import/unresolved.css new file mode 100644 index 00000000000..6cd410c8a55 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/unresolved.css @@ -0,0 +1 @@ +@import "unresolved-file.css"; diff --git a/crates/swc_css_modules/tests/fixture/import/unresolved.imports.json b/crates/swc_css_modules/tests/fixture/import/unresolved.imports.json new file mode 100644 index 00000000000..de40a2e5fb1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/unresolved.imports.json @@ -0,0 +1,3 @@ +[ + "unresolved-file.css" +] diff --git a/crates/swc_css_modules/tests/fixture/import/url.compiled.css b/crates/swc_css_modules/tests/fixture/import/url.compiled.css new file mode 100644 index 00000000000..0fff09cb907 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/url.compiled.css @@ -0,0 +1,3 @@ +.__local__background-imported { + background: url('./img.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/import/url.css b/crates/swc_css_modules/tests/fixture/import/url.css new file mode 100644 index 00000000000..859daa15e1d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/url.css @@ -0,0 +1,3 @@ +.background-imported { + background: url('./img.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/import/url.transform.json b/crates/swc_css_modules/tests/fixture/import/url.transform.json new file mode 100644 index 00000000000..d8decdcc292 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/import/url.transform.json @@ -0,0 +1,8 @@ +{ + "background-imported": [ + { + "type": "local", + "name": "__local__background-imported" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/imported.compiled.css b/crates/swc_css_modules/tests/fixture/imported.compiled.css new file mode 100644 index 00000000000..50f5c47de37 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/imported.compiled.css @@ -0,0 +1,3 @@ +.__local__foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/imported.css b/crates/swc_css_modules/tests/fixture/imported.css new file mode 100644 index 00000000000..a15c877ac01 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/imported.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/imported.transform.json b/crates/swc_css_modules/tests/fixture/imported.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/imported.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.compiled.css b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.compiled.css new file mode 100644 index 00000000000..8b45145016e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.compiled.css @@ -0,0 +1,6 @@ +.__local__foo { + color: red; +} +.__local__blue { + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.css b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.css new file mode 100644 index 00000000000..da2c967c46e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.css @@ -0,0 +1,7 @@ +.foo { + color: red; +} + +.blue { + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.transform.json b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.transform.json new file mode 100644 index 00000000000..ac5e71c741e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/index-loader-syntax.modules.transform.json @@ -0,0 +1,14 @@ +{ + "blue": [ + { + "type": "local", + "name": "__local__blue" + } + ], + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/index-loader-syntax.transform.json b/crates/swc_css_modules/tests/fixture/index-loader-syntax.transform.json new file mode 100644 index 00000000000..1d62625f4f0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/index-loader-syntax.transform.json @@ -0,0 +1,8 @@ +{ + "a": [ + { + "type": "local", + "name": "__local__a" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/css.module.compiled.css b/crates/swc_css_modules/tests/fixture/integration/css.module.compiled.css new file mode 100644 index 00000000000..92b7fbb36f9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/css.module.compiled.css @@ -0,0 +1,7 @@ +.__local__local { + overflow: hidden auto; + color: red; +} +.global { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/css.module.css b/crates/swc_css_modules/tests/fixture/integration/css.module.css new file mode 100644 index 00000000000..0a789dbb113 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/css.module.css @@ -0,0 +1,8 @@ +.local { + overflow: hidden auto; + color: red; +} + +:global(.global) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/css.module.transform.json b/crates/swc_css_modules/tests/fixture/integration/css.module.transform.json new file mode 100644 index 00000000000..d60592138a9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/css.module.transform.json @@ -0,0 +1,8 @@ +{ + "local": [ + { + "type": "local", + "name": "__local__local" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.compiled.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.compiled.css new file mode 100644 index 00000000000..bef460e4372 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-by-module-scss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.css new file mode 100644 index 00000000000..7e2a33772fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.css @@ -0,0 +1,3 @@ +.imported-by-module-scss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.transform.json b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.transform.json new file mode 100644 index 00000000000..d7617d62309 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-module-scss.transform.json @@ -0,0 +1,8 @@ +{ + "imported-by-module-scss": [ + { + "type": "local", + "name": "__local__imported-by-module-scss" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.compiled.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.compiled.css new file mode 100644 index 00000000000..d97fa73b3a3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-by-postcss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.css new file mode 100644 index 00000000000..833e8c80d5a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.css @@ -0,0 +1,3 @@ +.imported-by-postcss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.transform.json b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.transform.json new file mode 100644 index 00000000000..a362cd165be --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-postcss.transform.json @@ -0,0 +1,8 @@ +{ + "imported-by-postcss": [ + { + "type": "local", + "name": "__local__imported-by-postcss" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.compiled.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.compiled.css new file mode 100644 index 00000000000..4cf017707cb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-by-pure { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.css new file mode 100644 index 00000000000..2f7c8d882ee --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.css @@ -0,0 +1,3 @@ +.imported-by-pure { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.transform.json b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.transform.json new file mode 100644 index 00000000000..a194fd3d511 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-pure.transform.json @@ -0,0 +1,8 @@ +{ + "imported-by-pure": [ + { + "type": "local", + "name": "__local__imported-by-pure" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.compiled.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.compiled.css new file mode 100644 index 00000000000..5600d19855e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-by-scss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.css b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.css new file mode 100644 index 00000000000..dbc202982e1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.css @@ -0,0 +1,3 @@ +.imported-by-scss { + overflow: hidden auto; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.transform.json b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.transform.json new file mode 100644 index 00000000000..34d249c8fa8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/imported-by-scss.transform.json @@ -0,0 +1,8 @@ +{ + "imported-by-scss": [ + { + "type": "local", + "name": "__local__imported-by-scss" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/postcss.compiled.css b/crates/swc_css_modules/tests/fixture/integration/postcss.compiled.css new file mode 100644 index 00000000000..d5061111181 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/postcss.compiled.css @@ -0,0 +1,7 @@ +@import "./imported-by-postcss.css"; +.__local__postcss { + color: rgb(0 0 100% / 90%); + &:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/integration/postcss.css b/crates/swc_css_modules/tests/fixture/integration/postcss.css new file mode 100644 index 00000000000..0c035a8c0c9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/postcss.css @@ -0,0 +1,9 @@ +@import "./imported-by-postcss.css"; + +.postcss { + color: rgb(0 0 100% / 90%); + + &:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/integration/postcss.imports.json b/crates/swc_css_modules/tests/fixture/integration/postcss.imports.json new file mode 100644 index 00000000000..ea23cf7a5a4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/postcss.imports.json @@ -0,0 +1,3 @@ +[ + "./imported-by-postcss.css" +] diff --git a/crates/swc_css_modules/tests/fixture/integration/postcss.transform.json b/crates/swc_css_modules/tests/fixture/integration/postcss.transform.json new file mode 100644 index 00000000000..827ed8fd8e4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/postcss.transform.json @@ -0,0 +1,8 @@ +{ + "postcss": [ + { + "type": "local", + "name": "__local__postcss" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/integration/pure.compiled.css b/crates/swc_css_modules/tests/fixture/integration/pure.compiled.css new file mode 100644 index 00000000000..b56618b97a8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/pure.compiled.css @@ -0,0 +1,4 @@ +@import "./imported-by-pure.css"; +.__local__pure { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/pure.css b/crates/swc_css_modules/tests/fixture/integration/pure.css new file mode 100644 index 00000000000..c8f30ac1c39 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/pure.css @@ -0,0 +1,5 @@ +@import "./imported-by-pure.css"; + +.pure { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/integration/pure.imports.json b/crates/swc_css_modules/tests/fixture/integration/pure.imports.json new file mode 100644 index 00000000000..8c7eac047fd --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/pure.imports.json @@ -0,0 +1,3 @@ +[ + "./imported-by-pure.css" +] diff --git a/crates/swc_css_modules/tests/fixture/integration/pure.transform.json b/crates/swc_css_modules/tests/fixture/integration/pure.transform.json new file mode 100644 index 00000000000..d7cb01875fe --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/integration/pure.transform.json @@ -0,0 +1,8 @@ +{ + "pure": [ + { + "type": "local", + "name": "__local__pure" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/invisible-space.compiled.css b/crates/swc_css_modules/tests/fixture/invisible-space.compiled.css new file mode 100644 index 00000000000..7fbbf482a0d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/invisible-space.compiled.css @@ -0,0 +1,2 @@ +a { + 

 color: red;

 } diff --git a/crates/swc_css_modules/tests/fixture/invisible-space.css b/crates/swc_css_modules/tests/fixture/invisible-space.css new file mode 100644 index 00000000000..6d22c4f809b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/invisible-space.css @@ -0,0 +1 @@ +a { 

 color: red; 

 } \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.compiled.css b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.compiled.css new file mode 100644 index 00000000000..9a634b28e82 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.compiled.css @@ -0,0 +1,9 @@ +.__local__header { + color: red; +} +.__local__body { + color: green; +} +.__local__footer { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.css b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.css new file mode 100644 index 00000000000..ebefbd06289 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.css @@ -0,0 +1,11 @@ +.header { + color: red; +} + +.body { + color: green; +} + +.footer { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.transform.json b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.transform.json new file mode 100644 index 00000000000..bf6f364f10b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/ComponentName/index.modules.transform.json @@ -0,0 +1,20 @@ +{ + "footer": [ + { + "type": "local", + "name": "__local__footer" + } + ], + "header": [ + { + "type": "local", + "name": "__local__header" + } + ], + "body": [ + { + "type": "local", + "name": "__local__body" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/alias.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/alias.compiled.css new file mode 100644 index 00000000000..05fdd98dd77 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/alias.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-alias { + display: table; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/alias.css b/crates/swc_css_modules/tests/fixture/modules/composes/alias.css new file mode 100644 index 00000000000..a09f6378d3b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/alias.css @@ -0,0 +1,3 @@ +.imported-alias { + display: table; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/alias.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/alias.transform.json new file mode 100644 index 00000000000..db1408da53c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/alias.transform.json @@ -0,0 +1,8 @@ +{ + "imported-alias": [ + { + "type": "local", + "name": "__local__imported-alias" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.compiled.css new file mode 100644 index 00000000000..bd080c6a655 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.compiled.css @@ -0,0 +1,6 @@ +.__local__simple-foo { + color: red; +} +.__local__simple-bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.css b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.css new file mode 100644 index 00000000000..8f96762c5a1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.css @@ -0,0 +1,9 @@ +.simple-foo { + color: red; + composes: imported-simple from './imported-simple.css'; +} + +.simple-bar { + color: red; + composes: imported-simple from './imported-simple.css'; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.imports.json b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.imports.json new file mode 100644 index 00000000000..d86a99a7371 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.imports.json @@ -0,0 +1,3 @@ +[ + "./imported-simple.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.transform.json new file mode 100644 index 00000000000..2f410c16fe5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-duplicate.transform.json @@ -0,0 +1,24 @@ +{ + "simple-foo": [ + { + "type": "local", + "name": "__local__simple-foo" + }, + { + "type": "import", + "name": "imported-simple", + "from": "./imported-simple.css" + } + ], + "simple-bar": [ + { + "type": "local", + "name": "__local__simple-bar" + }, + { + "type": "import", + "name": "imported-simple", + "from": "./imported-simple.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.compiled.css new file mode 100644 index 00000000000..1406d80f7ff --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.compiled.css @@ -0,0 +1,18 @@ +@value v-def from './values.css'; +@value v-foo from './less-file.less'; +@value v-bar from './scss-file.scss'; +.globalClassName { + color: orange; +} +.__local__ghi { + color: v-def; +} +.__local__class { + color: v-foo; +} +.__local__other { + color: v-bar; +} +.__local__otherClassName { + background: #000; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.css b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.css new file mode 100644 index 00000000000..9b1785288fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.css @@ -0,0 +1,26 @@ +@value v-def from './values.css'; +@value v-foo from './less-file.less'; +@value v-bar from './scss-file.scss'; + +:global(.globalClassName) { + color: orange; +} + +.ghi { + color: v-def; +} + +.class { + color: v-foo; + composes: lessClass from "less-file.less"; +} + +.other { + color: v-bar; + composes: scssClass from "scss-file.scss"; +} + +.otherClassName { + composes: globalClassName from global; + background: #000; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.imports.json b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.imports.json new file mode 100644 index 00000000000..4a5eb01668a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.imports.json @@ -0,0 +1,4 @@ +[ + "less-file.less", + "scss-file.scss" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.transform.json new file mode 100644 index 00000000000..5c2c48257f6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/composes-preprocessors.transform.json @@ -0,0 +1,40 @@ +{ + "otherClassName": [ + { + "type": "local", + "name": "__local__otherClassName" + }, + { + "type": "global", + "name": "globalClassName" + } + ], + "class": [ + { + "type": "local", + "name": "__local__class" + }, + { + "type": "import", + "name": "lessClass", + "from": "less-file.less" + } + ], + "ghi": [ + { + "type": "local", + "name": "__local__ghi" + } + ], + "other": [ + { + "type": "local", + "name": "__local__other" + }, + { + "type": "import", + "name": "scssClass", + "from": "scss-file.scss" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.compiled.css new file mode 100644 index 00000000000..17fabde9570 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-simple { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.css b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.css new file mode 100644 index 00000000000..888c92a5788 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.css @@ -0,0 +1,3 @@ +.imported-simple { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.transform.json new file mode 100644 index 00000000000..e81397b84d0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/imported-simple.transform.json @@ -0,0 +1,8 @@ +{ + "imported-simple": [ + { + "type": "local", + "name": "__local__imported-simple" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/relative.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/relative.compiled.css new file mode 100644 index 00000000000..2db5e1a1702 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/relative.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-relative { + display: inline; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/relative.css b/crates/swc_css_modules/tests/fixture/modules/composes/relative.css new file mode 100644 index 00000000000..4cd3d00b26a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/relative.css @@ -0,0 +1,3 @@ +.imported-relative { + display: inline; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/relative.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/relative.transform.json new file mode 100644 index 00000000000..7abdec479ac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/relative.transform.json @@ -0,0 +1,8 @@ +{ + "imported-relative": [ + { + "type": "local", + "name": "__local__imported-relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/something.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/something.compiled.css new file mode 100644 index 00000000000..14efd103d01 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/something.compiled.css @@ -0,0 +1 @@ +@value v-something: 2112moon; diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/something.css b/crates/swc_css_modules/tests/fixture/modules/composes/something.css new file mode 100644 index 00000000000..14efd103d01 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/something.css @@ -0,0 +1 @@ +@value v-something: 2112moon; diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/test-other.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.compiled.css new file mode 100644 index 00000000000..538c768f567 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.compiled.css @@ -0,0 +1,3 @@ +.__local__test { + d: d; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/test-other.css b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.css new file mode 100644 index 00000000000..fc97be2edb1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.css @@ -0,0 +1,3 @@ +.test { + d: d; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/test-other.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.transform.json new file mode 100644 index 00000000000..8b4747fe291 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/test-other.transform.json @@ -0,0 +1,8 @@ +{ + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.compiled.css new file mode 100644 index 00000000000..bd53d6b1be5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-relative { + display: flex; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.css b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.css new file mode 100644 index 00000000000..19f8df1f812 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.css @@ -0,0 +1,3 @@ +.imported-relative { + display: flex; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.transform.json b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.transform.json new file mode 100644 index 00000000000..7abdec479ac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/top-relative.transform.json @@ -0,0 +1,8 @@ +{ + "imported-relative": [ + { + "type": "local", + "name": "__local__imported-relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/values.compiled.css b/crates/swc_css_modules/tests/fixture/modules/composes/values.compiled.css new file mode 100644 index 00000000000..017265bd01f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/values.compiled.css @@ -0,0 +1,4 @@ +@value v-def: red; +@value v-other: green; +@value s-white: white; +@value m-small: (min-width: 320px); diff --git a/crates/swc_css_modules/tests/fixture/modules/composes/values.css b/crates/swc_css_modules/tests/fixture/modules/composes/values.css new file mode 100644 index 00000000000..017265bd01f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/composes/values.css @@ -0,0 +1,4 @@ +@value v-def: red; +@value v-other: green; +@value s-white: white; +@value m-small: (min-width: 320px); diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.compiled.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.compiled.css new file mode 100644 index 00000000000..94f1fbf0b12 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.compiled.css @@ -0,0 +1,5 @@ +.__local__button { + border: none; + padding: 7px 15px; + cursor: pointer; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.css new file mode 100644 index 00000000000..63446188dc0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.css @@ -0,0 +1,6 @@ +.button +{ + border:none; + padding:7px 15px; + cursor:pointer; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.transform.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.transform.json new file mode 100644 index 00000000000..53488afadd8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/button.transform.json @@ -0,0 +1,8 @@ +{ + "button": [ + { + "type": "local", + "name": "__local__button" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.compiled.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.compiled.css new file mode 100644 index 00000000000..cb0e312460a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.compiled.css @@ -0,0 +1,4 @@ +.__local__primaryButton { + background-color: blue; + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.css new file mode 100644 index 00000000000..17bd070d991 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.css @@ -0,0 +1,6 @@ +.primaryButton +{ + composes:button from './button.css'; + background-color:blue; + color:white; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.imports.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.imports.json new file mode 100644 index 00000000000..1688a74f4e2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.imports.json @@ -0,0 +1,3 @@ +[ + "./button.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.transform.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.transform.json new file mode 100644 index 00000000000..099d2ce94ff --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/primary-button.transform.json @@ -0,0 +1,13 @@ +{ + "primaryButton": [ + { + "type": "local", + "name": "__local__primaryButton" + }, + { + "type": "import", + "name": "button", + "from": "./button.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.compiled.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.compiled.css new file mode 100644 index 00000000000..16319a215a9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.compiled.css @@ -0,0 +1,4 @@ +.__local__secondaryButton { + background-color: #555; + color: white; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.css new file mode 100644 index 00000000000..8d9eefc8e66 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.css @@ -0,0 +1,6 @@ +.secondaryButton +{ + composes:button from './button.css'; + background-color:#555; + color:white; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.imports.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.imports.json new file mode 100644 index 00000000000..1688a74f4e2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.imports.json @@ -0,0 +1,3 @@ +[ + "./button.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.transform.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.transform.json new file mode 100644 index 00000000000..b1d233ac64c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/buttons/secondary-button.transform.json @@ -0,0 +1,13 @@ +{ + "secondaryButton": [ + { + "type": "local", + "name": "__local__secondaryButton" + }, + { + "type": "import", + "name": "button", + "from": "./button.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.compiled.css new file mode 100644 index 00000000000..fe0a28c1cb8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.compiled.css @@ -0,0 +1,2 @@ +.__local__nextButton {} +.__local__backButton {} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/source.css b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.css new file mode 100644 index 00000000000..1abaadd3c94 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.css @@ -0,0 +1,9 @@ +.nextButton +{ + composes:primaryButton from './buttons/primary-button.css'; +} + +.backButton +{ + composes:secondaryButton from './buttons/secondary-button.css'; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.imports.json new file mode 100644 index 00000000000..50798b33b61 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.imports.json @@ -0,0 +1,4 @@ +[ + "./buttons/primary-button.css", + "./buttons/secondary-button.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/dedupe/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.transform.json new file mode 100644 index 00000000000..ee28ab75943 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/dedupe/source.transform.json @@ -0,0 +1,24 @@ +{ + "backButton": [ + { + "type": "local", + "name": "__local__backButton" + }, + { + "type": "import", + "name": "secondaryButton", + "from": "./buttons/secondary-button.css" + } + ], + "nextButton": [ + { + "type": "local", + "name": "__local__nextButton" + }, + { + "type": "import", + "name": "primaryButton", + "from": "./buttons/primary-button.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.compiled.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.compiled.css new file mode 100644 index 00000000000..e57d6f852c4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.compiled.css @@ -0,0 +1,9 @@ +.__local__foo { + background-color: red; +} +.__local__bar { + background-color: green; +} +.baz { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.css new file mode 100644 index 00000000000..fea8c37c8fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.css @@ -0,0 +1,11 @@ +.foo { + background-color: red; +} + +:local(.bar) { + background-color: green; +} + +:global(.baz) { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.transform.json b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.transform.json new file mode 100644 index 00000000000..1b69775afbc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-global/exportGlobals.transform.json @@ -0,0 +1,14 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.compiled.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.compiled.css new file mode 100644 index 00000000000..e57d6f852c4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.compiled.css @@ -0,0 +1,9 @@ +.__local__foo { + background-color: red; +} +.__local__bar { + background-color: green; +} +.baz { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.css new file mode 100644 index 00000000000..fea8c37c8fb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.css @@ -0,0 +1,11 @@ +.foo { + background-color: red; +} + +:local(.bar) { + background-color: green; +} + +:global(.baz) { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.transform.json b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.transform.json new file mode 100644 index 00000000000..1b69775afbc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-local/exportGlobals.transform.json @@ -0,0 +1,14 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.compiled.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.compiled.css new file mode 100644 index 00000000000..4e6572427ea --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.compiled.css @@ -0,0 +1,9 @@ +.__local__foo { + background-color: red; +} +.__local__one .__local__bar { + background-color: green; +} +.__local__two .baz { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.css b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.css new file mode 100644 index 00000000000..a334282bb18 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.css @@ -0,0 +1,11 @@ +.foo { + background-color: red; +} + +.one :local(.bar) { + background-color: green; +} + +.two :global(.baz) { + background-color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.transform.json b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.transform.json new file mode 100644 index 00000000000..49dce7c2ff0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/exportGlobals-pure/exportGlobals.transform.json @@ -0,0 +1,26 @@ +{ + "two": [ + { + "type": "local", + "name": "__local__two" + } + ], + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "one": [ + { + "type": "local", + "name": "__local__one" + } + ], + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/imported.compiled.css b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.compiled.css new file mode 100644 index 00000000000..c1311b20488 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-relative { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/imported.css b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.css new file mode 100644 index 00000000000..4459531856a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.css @@ -0,0 +1,3 @@ +.imported-relative { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/imported.transform.json b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.transform.json new file mode 100644 index 00000000000..7abdec479ac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/imported.transform.json @@ -0,0 +1,8 @@ +{ + "imported-relative": [ + { + "type": "local", + "name": "__local__imported-relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/extensions/source.compiled.css new file mode 100644 index 00000000000..4e4badef198 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/source.compiled.css @@ -0,0 +1,3 @@ +.__local__one { + color: yellow; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/source.css b/crates/swc_css_modules/tests/fixture/modules/extensions/source.css new file mode 100644 index 00000000000..f0cc65db06c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/source.css @@ -0,0 +1,4 @@ +.one { + color: yellow; + composes: imported-relative from 'imported'; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/extensions/source.imports.json new file mode 100644 index 00000000000..6faa8b58b36 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/source.imports.json @@ -0,0 +1,3 @@ +[ + "imported" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/extensions/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/extensions/source.transform.json new file mode 100644 index 00000000000..bc90b019b21 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/extensions/source.transform.json @@ -0,0 +1,13 @@ +{ + "one": [ + { + "type": "local", + "name": "__local__one" + }, + { + "type": "import", + "name": "imported-relative", + "from": "imported" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1033/issue-1033.css b/crates/swc_css_modules/tests/fixture/modules/issue-1033/issue-1033.css new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.compiled.css new file mode 100644 index 00000000000..4f876391ceb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.compiled.css @@ -0,0 +1,6 @@ +.__local__classNameGlobalFile { + color: black; +} +.__local__otherClassGlobalFile { + color: coral; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.css new file mode 100644 index 00000000000..95eb9774e6d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.css @@ -0,0 +1,7 @@ +.classNameGlobalFile { + color: black; +} + +:local(.otherClassGlobalFile) { + color: coral; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.transform.json new file mode 100644 index 00000000000..26dda0befb0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/global.transform.json @@ -0,0 +1,14 @@ +{ + "classNameGlobalFile": [ + { + "type": "local", + "name": "__local__classNameGlobalFile" + } + ], + "otherClassGlobalFile": [ + { + "type": "local", + "name": "__local__otherClassGlobalFile" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.compiled.css new file mode 100644 index 00000000000..75a650d5e2d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.compiled.css @@ -0,0 +1,6 @@ +.__local__classNameLocalFile { + color: green; +} +.otherClassLocalFile { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.css new file mode 100644 index 00000000000..f68ef05a641 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.css @@ -0,0 +1,7 @@ +.classNameLocalFile { + color: green; +} + +:global(.otherClassLocalFile) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.transform.json new file mode 100644 index 00000000000..c3646940794 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/local.transform.json @@ -0,0 +1,8 @@ +{ + "classNameLocalFile": [ + { + "type": "local", + "name": "__local__classNameLocalFile" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.compiled.css new file mode 100644 index 00000000000..6e7d368ed00 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.compiled.css @@ -0,0 +1,3 @@ +.__local__foo .__local__bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.css b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.css new file mode 100644 index 00000000000..679c427bc88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.css @@ -0,0 +1,3 @@ +.foo :local(.bar) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.transform.json new file mode 100644 index 00000000000..1b69775afbc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1063/pure.transform.json @@ -0,0 +1,14 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.compiled.css new file mode 100644 index 00000000000..e69fdcde2e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.compiled.css @@ -0,0 +1,3 @@ +.__local__some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.css b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.css new file mode 100644 index 00000000000..b58cc07a481 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.css @@ -0,0 +1,3 @@ +.some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.transform.json new file mode 100644 index 00000000000..8305c2964d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191-custom.transform.json @@ -0,0 +1,8 @@ +{ + "some-class": [ + { + "type": "local", + "name": "__local__some-class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.compiled.css new file mode 100644 index 00000000000..e69fdcde2e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.compiled.css @@ -0,0 +1,3 @@ +.__local__some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.css b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.css new file mode 100644 index 00000000000..b58cc07a481 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.css @@ -0,0 +1,3 @@ +.some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.transform.json new file mode 100644 index 00000000000..8305c2964d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1191/issue-1191.transform.json @@ -0,0 +1,8 @@ +{ + "some-class": [ + { + "type": "local", + "name": "__local__some-class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.compiled.css new file mode 100644 index 00000000000..b365e4ce0e1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.compiled.css @@ -0,0 +1,3 @@ +.__local__myClass { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.css b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.css new file mode 100644 index 00000000000..58869fbbe5e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.css @@ -0,0 +1,3 @@ +.myClass { + color: red; +} \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.transform.json new file mode 100644 index 00000000000..9f48ed3c406 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1223/@foo/bar/index.module.transform.json @@ -0,0 +1,8 @@ +{ + "myClass": [ + { + "type": "local", + "name": "__local__myClass" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.compiled.css new file mode 100644 index 00000000000..200f250c2dd --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.compiled.css @@ -0,0 +1,17 @@ +.__local__a { + animation: 3s __local__animationName; +} +.__local__b { + animation: __local__animationName 3s; +} +.__local__c { + animation-name: __local__animationName; +} +@keyframes __local__animationName { + 0% { + background: white; + } + 100% { + background: red; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.css b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.css new file mode 100644 index 00000000000..7da41d8a73f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.css @@ -0,0 +1,20 @@ +.a { + animation: 3s animationName; +} + +.b { + animation: animationName 3s; +} + +.c { + animation-name: animationName; +} + +@keyframes animationName { + 0% { + background: white; + } + 100% { + background: red; + } +} \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.transform.json new file mode 100644 index 00000000000..86a8236dd00 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-1228/source.transform.json @@ -0,0 +1,26 @@ +{ + "b": [ + { + "type": "local", + "name": "__local__b" + } + ], + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "c": [ + { + "type": "local", + "name": "__local__c" + } + ], + "animationName": [ + { + "type": "local", + "name": "__local__animationName" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.compiled.css new file mode 100644 index 00000000000..a6d73c04760 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.compiled.css @@ -0,0 +1,3 @@ +.__local__red { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.css b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.css new file mode 100644 index 00000000000..442fcb11b4c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.css @@ -0,0 +1 @@ +.red { color: red } diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.transform.json new file mode 100644 index 00000000000..10bdcfe2e47 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/dep.transform.json @@ -0,0 +1,8 @@ +{ + "red": [ + { + "type": "local", + "name": "__local__red" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.compiled.css new file mode 100644 index 00000000000..bbca9b404f3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.compiled.css @@ -0,0 +1 @@ +.__local__main {} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/source.css b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.css new file mode 100644 index 00000000000..a0482c69698 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.css @@ -0,0 +1 @@ +.main { composes: red from './dep.css'; } diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.imports.json new file mode 100644 index 00000000000..e5e22114e28 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.imports.json @@ -0,0 +1,3 @@ +[ + "./dep.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-286/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.transform.json new file mode 100644 index 00000000000..01cefacbb15 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-286/source.transform.json @@ -0,0 +1,13 @@ +{ + "main": [ + { + "type": "local", + "name": "__local__main" + }, + { + "type": "import", + "name": "red", + "from": "./dep.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.compiled.css new file mode 100644 index 00000000000..9436d665acf --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.compiled.css @@ -0,0 +1,6 @@ +@value color-grey from "./node_modules/@localpackage/color.css"; +.__local__copyright { + color: color-grey; + margin: 0; + padding: 0; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.css b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.css new file mode 100644 index 00000000000..4df75268288 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.css @@ -0,0 +1,8 @@ +@value color-grey from "./node_modules/@localpackage/color.css"; + +.copyright { + color: color-grey; + composes: type-heading from "./node_modules/@localpackage/style.css"; + margin: 0; + padding: 0; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.imports.json b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.imports.json new file mode 100644 index 00000000000..e3916f8c029 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.imports.json @@ -0,0 +1,3 @@ +[ + "./node_modules/@localpackage/style.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.transform.json new file mode 100644 index 00000000000..0074f344811 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-861/resolving-from-node_modules.transform.json @@ -0,0 +1,13 @@ +{ + "copyright": [ + { + "type": "local", + "name": "__local__copyright" + }, + { + "type": "import", + "name": "type-heading", + "from": "./node_modules/@localpackage/style.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-914/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.compiled.css new file mode 100644 index 00000000000..03f2b466ec3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.compiled.css @@ -0,0 +1,6 @@ +@value foo from '~test'; +@value bar from 'test'; +.__local__className { + color: foo; + background: bar; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-914/source.css b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.css new file mode 100644 index 00000000000..9a606d7c20c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.css @@ -0,0 +1,8 @@ +@value foo from '~test'; +@value bar from 'test'; + +.className { + color: foo; + background: bar; +} + diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-914/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.transform.json new file mode 100644 index 00000000000..6e33c82e5c7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-914/source.transform.json @@ -0,0 +1,8 @@ +{ + "className": [ + { + "type": "local", + "name": "__local__className" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/button.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.compiled.css new file mode 100644 index 00000000000..3e0643d9850 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.compiled.css @@ -0,0 +1,3 @@ +.__local__button { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/button.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.css new file mode 100644 index 00000000000..1dfac231681 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.css @@ -0,0 +1,3 @@ +.button { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/button.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.transform.json new file mode 100644 index 00000000000..53488afadd8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/button.transform.json @@ -0,0 +1,8 @@ +{ + "button": [ + { + "type": "local", + "name": "__local__button" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.compiled.css new file mode 100644 index 00000000000..5bd9e7ab2b5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.compiled.css @@ -0,0 +1,15 @@ +.__local__foo-class { + color: red; +} +.__local__bar-class { + color: red; +} +.__local__baz-class { + color: red; +} +.__local__fooBaz-class { + color: red; +} +.__local__some.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.css new file mode 100644 index 00000000000..a27ca561c7d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.css @@ -0,0 +1,19 @@ +.foo-class { + color: red; +} + +.bar-class { + color: red; +} + +.baz-class { + color: red; +} + +.fooBaz-class { + color: red; +} + +.some.class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.transform.json new file mode 100644 index 00000000000..4351176ca6b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/issue-966.transform.json @@ -0,0 +1,38 @@ +{ + "bar-class": [ + { + "type": "local", + "name": "__local__bar-class" + } + ], + "fooBaz-class": [ + { + "type": "local", + "name": "__local__fooBaz-class" + } + ], + "foo-class": [ + { + "type": "local", + "name": "__local__foo-class" + } + ], + "some": [ + { + "type": "local", + "name": "__local__some" + } + ], + "class": [ + { + "type": "local", + "name": "__local__class" + } + ], + "baz-class": [ + { + "type": "local", + "name": "__local__baz-class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.compiled.css new file mode 100644 index 00000000000..4a73998a35d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.compiled.css @@ -0,0 +1,4 @@ +@value btn from './button.css'; +.__local__toolbar > btn { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.css b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.css new file mode 100644 index 00000000000..ca5da32013a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.css @@ -0,0 +1,5 @@ +@value btn from './button.css'; + +.toolbar > btn { + color: red +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.transform.json new file mode 100644 index 00000000000..37693277487 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-966/toolbar.transform.json @@ -0,0 +1,8 @@ +{ + "toolbar": [ + { + "type": "local", + "name": "__local__toolbar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.compiled.css new file mode 100644 index 00000000000..fcb0ca7e04d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.compiled.css @@ -0,0 +1,9 @@ +.__local__foo { + color: red; +} +.__local__foo\/bar { + color: blue; +} +.__local__\[\/\?\<\>\\\\\:\*\|\"\:\] { + color: yellow; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.css b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.css new file mode 100644 index 00000000000..7b503616268 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.css @@ -0,0 +1,11 @@ +.foo { + color: red; +} + +.foo\/bar { + color: blue; +} + +.\[\/\?\<\>\\\\\3A \*\|\"\3A \] { + color: yellow; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.transform.json new file mode 100644 index 00000000000..285f48f8d03 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-967/path-placeholder.transform.json @@ -0,0 +1,20 @@ +{ + "[/?<>\\\\:*|\":]": [ + { + "type": "local", + "name": "__local__[/?<>\\\\:*|\":]" + } + ], + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "foo/bar": [ + { + "type": "local", + "name": "__local__foo/bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.compiled.css new file mode 100644 index 00000000000..822a6d63c18 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.compiled.css @@ -0,0 +1,3 @@ +.__local__a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.css b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.css new file mode 100644 index 00000000000..5451a331f9c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.css @@ -0,0 +1,3 @@ +.a { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.transform.json new file mode 100644 index 00000000000..1d62625f4f0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-980/file.with.many.dots.in.name.transform.json @@ -0,0 +1,8 @@ +{ + "a": [ + { + "type": "local", + "name": "__local__a" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.compiled.css new file mode 100644 index 00000000000..08140af2c77 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.compiled.css @@ -0,0 +1,60 @@ +.__local__a { + color: red; +} +.__local__a.__local__b { + color: red; +} +.__local__a .__local__b { + color: red; +} +.__local__😀 { + color: red; +} +.__local__😀.__local__😓 { + color: red; +} +.__local__😀 .__local__😓 { + color: red; +} +.__local__😀 { + color: red; +} +.__local__😀.__local__😓 { + color: red; +} +.__local__😀 .__local__😓 { + color: red; +} +.__local__a { + color: red; +} +.__local__a.__local__b { + color: red; +} +.__local__a .__local__b { + color: red; +} +.__local__😀 .__local__a .__local__😀 { + color: red; +} +.__local__a .__local__b .__local__a { + color: red; +} +div:not(.__local__a) { + color: red; +} +.__local__a .__local__b { + color: red; +} +.__local__b .__local__a { + color: red; +} +.__local__😓 .__local__a { + color: red; +} +.__local__a { + color: red; +} +.__local__a > .__local__b > .__local__c { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.css b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.css new file mode 100644 index 00000000000..8a01f25106a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.css @@ -0,0 +1,93 @@ +/* class="😀" */ +.a { + color: red; +} + +/* class="😀 😓" */ +.a.b { + color: red; +} + +/* class="😀" > class="😓" */ +.a .b { + color: red; +} + +/* class="😀" */ +.😀 { + color: red; +} + +/* class="😀 😓" */ +.😀.😓 { + color: red; +} + +/* class="😀" > class="😓" */ +.😀 .😓 { + color: red; +} + +/* class="😀" */ +.\1F600 { + color: red; +} + +/* class="😀 😓" */ +.\1F600.\1F613 { + color: red; +} + +/* class="😀" > class="😓" */ +.\1F600 .\1F613 { + color: red; +} + +/* Local */ + +/* class="😀" */ +:local(.a) { + color: red; +} + +/* class="😀 😓" */ +:local(.a.b) { + color: red; +} + +/* class="😀" > class="😓" */ +:local(.a .b) { + color: red; +} + +.\1F600 .a .\1F600 { + color: red; +} + +:local(.a .b .a) { + color: red; +} + +div:not(:local(.a)) { + color: red; +} + +:local(.a) .b { + color: red; +} + +.b :local(.a) { + color: red; +} + +.\1F613 :local(.a) { + color: red; +} + +.\1F613 :local(.a) { + color: red; +} + +:local(.a) > :local(.b) > :local(.c) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.transform.json new file mode 100644 index 00000000000..37affad81c4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/issue-995/issue-995.transform.json @@ -0,0 +1,32 @@ +{ + "b": [ + { + "type": "local", + "name": "__local__b" + } + ], + "😓": [ + { + "type": "local", + "name": "__local__😓" + } + ], + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "😀": [ + { + "type": "local", + "name": "__local__😀" + } + ], + "c": [ + { + "type": "local", + "name": "__local__c" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.compiled.css b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.compiled.css new file mode 100644 index 00000000000..59d40772798 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.compiled.css @@ -0,0 +1,161 @@ +.__local__test { + background: red; +} +.__local___test { + background: blue; +} +.__local__className { + background: red; +} +#__local__someId { + background: green; +} +.__local__className .__local__subClass { + color: green; +} +#__local__someId .__local__subClass { + color: blue; +} +.__local__-a0-34a___f { + color: red; +} +.__local__m_x_\@ { + margin-left: auto !important; + margin-right: auto !important; +} +.__local__B\&W\? { + margin-left: auto !important; + margin-right: auto !important; +} +.__local__\:\`\( { + color: aqua; +} +.__local__1a2b3c { + color: aliceblue; +} +#__local__\#fake-id { + color: antiquewhite; +} +#__local__-a-b-c- { + color: azure; +} +#__local__© { + color: black; +} +.__local__♥ { + background: lime; +} +.__local__© { + background: lime; +} +.__local__😍 { + background: lime; +} +.__local__“‘’” { + background: lime; +} +.__local__☺☃ { + background: lime; +} +.__local__⌘⌥ { + background: lime; +} +.__local__𝄞♪♩♫♬ { + background: lime; +} +.__local__💩 { + background: lime; +} +.__local__\? { + background: lime; +} +.__local__\@ { + background: lime; +} +.__local__\. { + background: lime; +} +.__local__\:\) { + background: lime; +} +.__local__\:\`\( { + background: lime; +} +.__local__123 { + background: lime; +} +.__local__1a2b3c { + background: lime; +} +.__local__\ { + background: lime; +} +.__local__\<\>\<\<\<\>\>\<\> { + background: lime; +} +.__local__\+\+\+\+\+\+\+\+\+\+\[\>\+\+\+\+\+\+\+\>\+\+\+\+\+\+\+\+\+\+\>\+\+\+\>\+\<\<\<\<-\]\>\+\+\.\>\+\.\+\+\+\+\+\+\+\.\.\+\+\+\.\>\+\+\.\<\<\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\.\>\.\+\+\+\.------\.--------\.\>\+\.\>\. { + background: lime; +} +.__local__\# { + background: lime; +} +.__local__\#\# { + background: lime; +} +.__local__\#\.\#\.\# { + background: lime; +} +.__local___ { + background: lime; +} +.__local__\{\} { + background: lime; +} +.__local__\#fake-id { + background: lime; +} +.__local__foo\.bar { + background: lime; +} +.__local__\:hover { + background: lime; +} +.__local__\:hover\:focus\:active { + background: lime; +} +.__local__\[attr\=value\] { + background: lime; +} +.__local__f\/o\/o { + background: lime; +} +.__local__f\\o\\o { + background: lime; +} +.__local__f\*o\*o { + background: lime; +} +.__local__f\!o\!o { + background: lime; +} +.__local__f\'o\'o { + background: lime; +} +.__local__f\~o\~o { + background: lime; +} +.__local__f\+o\+o { + background: lime; +} +.__local__foo\/bar { + background: hotpink; +} +.__local__foo\\bar { + background: hotpink; +} +.__local__foo\/bar\/baz { + background: hotpink; +} +.__local__foo\\bar\\baz { + background: hotpink; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.css b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.css new file mode 100644 index 00000000000..aea057654a2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.css @@ -0,0 +1,114 @@ +.test { + background: red; +} + +._test { + background: blue; +} + +.className { + background: red; +} + +#someId { + background: green; +} + +.className .subClass { + color: green; +} + +#someId .subClass { + color: blue; +} + +.-a0-34a___f { + color: red; +} + +.m_x_\@ { + margin-left: auto !important; + margin-right: auto !important; +} + +.B\&W\? { + margin-left: auto !important; + margin-right: auto !important; +} + +/* matches elements with class=":`(" */ +.\3A \`\( { + color: aqua; +} + +/* matches elements with class="1a2b3c" */ +.\31 a2b3c { + color: aliceblue; +} + +/* matches the element with id="#fake-id" */ +#\#fake-id { + color: antiquewhite; +} + +/* matches the element with id="-a-b-c-" */ +#-a-b-c- { + color: azure; +} + +/* matches the element with id="©" */ +#© { + color: black; +} + +.♥ { background: lime; } +.© { background: lime; } +.😍 { background: lime; } +.“‘’” { background: lime; } +.☺☃ { background: lime; } +.⌘⌥ { background: lime; } +.𝄞♪♩♫♬ { background: lime; } +.💩 { background: lime; } +.\? { background: lime; } +.\@ { background: lime; } +.\. { background: lime; } +.\3A \) { background: lime; } +.\3A \`\( { background: lime; } +.\31 23 { background: lime; } +.\31 a2b3c { background: lime; } +.\ { background: lime; } +.\<\>\<\<\<\>\>\<\> { background: lime; } +.\+\+\+\+\+\+\+\+\+\+\[\>\+\+\+\+\+\+\+\>\+\+\+\+\+\+\+\+\+\+\>\+\+\+\>\+\<\<\<\<\-\]\>\+\+\.\>\+\.\+\+\+\+\+\+\+\.\.\+\+\+\.\>\+\+\.\<\<\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\.\>\.\+\+\+\.\-\-\-\-\-\-\.\-\-\-\-\-\-\-\-\.\>\+\.\>\. { background: lime; } +.\# { background: lime; } +.\#\# { background: lime; } +.\#\.\#\.\# { background: lime; } +.\_ { background: lime; } +.\{\} { background: lime; } +.\#fake\-id { background: lime; } +.foo\.bar { background: lime; } +.\3A hover { background: lime; } +.\3A hover\3A focus\3A active { background: lime; } +.\[attr\=value\] { background: lime; } +.f\/o\/o { background: lime; } +.f\\o\\o { background: lime; } +.f\*o\*o { background: lime; } +.f\!o\!o { background: lime; } +.f\'o\'o { background: lime; } +.f\~o\~o { background: lime; } +.f\+o\+o { background: lime; } + +.foo\/bar { + background: hotpink; +} + +.foo\\bar { + background: hotpink; +} + +.foo\/bar\/baz { + background: hotpink; +} + +.foo\\bar\\baz { + background: hotpink; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.transform.json b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.transform.json new file mode 100644 index 00000000000..f1986252d38 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localIdentName/localIdentName.transform.json @@ -0,0 +1,290 @@ +{ + "⌘⌥": [ + { + "type": "local", + "name": "__local__⌘⌥" + } + ], + "1a2b3c": [ + { + "type": "local", + "name": "__local__1a2b3c" + } + ], + "f+o+o": [ + { + "type": "local", + "name": "__local__f+o+o" + } + ], + ":`(": [ + { + "type": "local", + "name": "__local__:`(" + } + ], + "className": [ + { + "type": "local", + "name": "__local__className" + } + ], + "♥": [ + { + "type": "local", + "name": "__local__♥" + } + ], + "💩": [ + { + "type": "local", + "name": "__local__💩" + } + ], + "123": [ + { + "type": "local", + "name": "__local__123" + } + ], + "_test": [ + { + "type": "local", + "name": "__local___test" + } + ], + "

": [ + { + "type": "local", + "name": "__local__

" + } + ], + "foo.bar": [ + { + "type": "local", + "name": "__local__foo.bar" + } + ], + "-a-b-c-": [ + { + "type": "local", + "name": "__local__-a-b-c-" + } + ], + "f\\o\\o": [ + { + "type": "local", + "name": "__local__f\\o\\o" + } + ], + "𝄞♪♩♫♬": [ + { + "type": "local", + "name": "__local__𝄞♪♩♫♬" + } + ], + "someId": [ + { + "type": "local", + "name": "__local__someId" + } + ], + "B&W?": [ + { + "type": "local", + "name": "__local__B&W?" + } + ], + "[attr=value]": [ + { + "type": "local", + "name": "__local__[attr=value]" + } + ], + "f/o/o": [ + { + "type": "local", + "name": "__local__f/o/o" + } + ], + "test": [ + { + "type": "local", + "name": "__local__test" + } + ], + "f*o*o": [ + { + "type": "local", + "name": "__local__f*o*o" + } + ], + ":hover:focus:active": [ + { + "type": "local", + "name": "__local__:hover:focus:active" + } + ], + "f~o~o": [ + { + "type": "local", + "name": "__local__f~o~o" + } + ], + "foo/bar/baz": [ + { + "type": "local", + "name": "__local__foo/bar/baz" + } + ], + "-a0-34a___f": [ + { + "type": "local", + "name": "__local__-a0-34a___f" + } + ], + ":hover": [ + { + "type": "local", + "name": "__local__:hover" + } + ], + "?": [ + { + "type": "local", + "name": "__local__?" + } + ], + "m_x_@": [ + { + "type": "local", + "name": "__local__m_x_@" + } + ], + "@": [ + { + "type": "local", + "name": "__local__@" + } + ], + ".": [ + { + "type": "local", + "name": "__local__." + } + ], + "<><<<>><>": [ + { + "type": "local", + "name": "__local__<><<<>><>" + } + ], + "“‘’”": [ + { + "type": "local", + "name": "__local__“‘’”" + } + ], + "#": [ + { + "type": "local", + "name": "__local__#" + } + ], + "#.#.#": [ + { + "type": "local", + "name": "__local__#.#.#" + } + ], + "subClass": [ + { + "type": "local", + "name": "__local__subClass" + } + ], + "#fake-id": [ + { + "type": "local", + "name": "__local__#fake-id" + } + ], + "_": [ + { + "type": "local", + "name": "__local___" + } + ], + "f!o!o": [ + { + "type": "local", + "name": "__local__f!o!o" + } + ], + "f'o'o": [ + { + "type": "local", + "name": "__local__f'o'o" + } + ], + "foo\\bar": [ + { + "type": "local", + "name": "__local__foo\\bar" + } + ], + "©": [ + { + "type": "local", + "name": "__local__©" + } + ], + ":)": [ + { + "type": "local", + "name": "__local__:)" + } + ], + "##": [ + { + "type": "local", + "name": "__local__##" + } + ], + "{}": [ + { + "type": "local", + "name": "__local__{}" + } + ], + "foo/bar": [ + { + "type": "local", + "name": "__local__foo/bar" + } + ], + "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": [ + { + "type": "local", + "name": "__local__++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." + } + ], + "foo\\bar\\baz": [ + { + "type": "local", + "name": "__local__foo\\bar\\baz" + } + ], + "😍": [ + { + "type": "local", + "name": "__local__😍" + } + ], + "☺☃": [ + { + "type": "local", + "name": "__local__☺☃" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.compiled.css b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.compiled.css new file mode 100644 index 00000000000..8fe609633ea --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.compiled.css @@ -0,0 +1,19 @@ +.__local__btn-info_is-disabled { + color: blue; +} +.__local__btn--info_is-disabled_1 { + color: blue; +} +.__local__simple { + color: red; +} +a { + color: yellow; +} +:export { + foo: bar; + my-btn-info_is-disabled: value; +} +.__local__foo_bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.css b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.css new file mode 100644 index 00000000000..894f64b1890 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.css @@ -0,0 +1,24 @@ +.btn-info_is-disabled { + color: blue; +} + +.btn--info_is-disabled_1 { + color: blue; +} + +.simple { + color: red; +} + +a { + color: yellow; +} + +:export { + foo: bar; + my-btn-info_is-disabled: value; +} + +.foo_bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.transform.json b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.transform.json new file mode 100644 index 00000000000..bfce18f1956 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/localsConvention/localsConvention.transform.json @@ -0,0 +1,26 @@ +{ + "btn-info_is-disabled": [ + { + "type": "local", + "name": "__local__btn-info_is-disabled" + } + ], + "btn--info_is-disabled_1": [ + { + "type": "local", + "name": "__local__btn--info_is-disabled_1" + } + ], + "simple": [ + { + "type": "local", + "name": "__local__simple" + } + ], + "foo_bar": [ + { + "type": "local", + "name": "__local__foo_bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/entry.compiled.css b/crates/swc_css_modules/tests/fixture/modules/mode/entry.compiled.css new file mode 100644 index 00000000000..d5d806a6eae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/entry.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/entry.css b/crates/swc_css_modules/tests/fixture/modules/mode/entry.css new file mode 100644 index 00000000000..a95613b1759 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/entry.css @@ -0,0 +1,3 @@ +.class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/entry.transform.json b/crates/swc_css_modules/tests/fixture/modules/mode/entry.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/entry.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.compiled.css b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.compiled.css new file mode 100644 index 00000000000..d5d806a6eae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.css b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.css new file mode 100644 index 00000000000..a95613b1759 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.css @@ -0,0 +1,3 @@ +.class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.transform.json b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/no-modules.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.compiled.css b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.compiled.css new file mode 100644 index 00000000000..33b64f55344 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.compiled.css @@ -0,0 +1,3 @@ +.__local__relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.css b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.css new file mode 100644 index 00000000000..73597627ba7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.css @@ -0,0 +1,3 @@ +.relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.transform.json b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.transform.json new file mode 100644 index 00000000000..ed6b94f045d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.module.transform.json @@ -0,0 +1,8 @@ +{ + "relative": [ + { + "type": "local", + "name": "__local__relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.compiled.css b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.compiled.css new file mode 100644 index 00000000000..33b64f55344 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.compiled.css @@ -0,0 +1,3 @@ +.__local__relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.css b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.css new file mode 100644 index 00000000000..73597627ba7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.css @@ -0,0 +1,3 @@ +.relative { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.transform.json b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.transform.json new file mode 100644 index 00000000000..ed6b94f045d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/relative.modules.transform.json @@ -0,0 +1,8 @@ +{ + "relative": [ + { + "type": "local", + "name": "__local__relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.compiled.css b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.compiled.css new file mode 100644 index 00000000000..d5d806a6eae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.css b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.css new file mode 100644 index 00000000000..a95613b1759 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.css @@ -0,0 +1,3 @@ +.class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.transform.json b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/mode/style.modules.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.compiled.css new file mode 100644 index 00000000000..43b4965b8da --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.compiled.css @@ -0,0 +1,6 @@ +.__local__bar-baz { + color: red; +} +.bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.css new file mode 100644 index 00000000000..628f3ed659b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.css @@ -0,0 +1,7 @@ +:local(.bar-baz) { + color: red; +} + +:global(.bar) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.transform.json new file mode 100644 index 00000000000..a7f9fe31578 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/base/index.transform.json @@ -0,0 +1,8 @@ +{ + "bar-baz": [ + { + "type": "local", + "name": "__local__bar-baz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.compiled.css new file mode 100644 index 00000000000..d5d806a6eae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.css new file mode 100644 index 00000000000..a219fc2f9ad --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.css @@ -0,0 +1,3 @@ +:local(.class) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/broken/index.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.compiled.css new file mode 100644 index 00000000000..77c7befa867 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.compiled.css @@ -0,0 +1,19 @@ +@value v_def from './values.css'; +@value v_other-other from './values.css'; +@value s-white from './values.css'; +@value m-small from './values.css'; +.__local__ghi { + color: v_def; +} +.__local__my-class { + color: s-white; +} +.__local__other { + display: m-small; +} +.__local__other-other { + width: v_def; +} +.__local__green { + color: v_other-other; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.css new file mode 100644 index 00000000000..7a7d4fa9696 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.css @@ -0,0 +1,24 @@ +@value v_def from './values.css'; +@value v_other-other from './values.css'; +@value s-white from './values.css'; +@value m-small from './values.css'; + +.ghi { + color: v_def; +} + +.my-class { + color: s-white; +} + +.other { + display: m-small; +} + +.other-other { + width: v_def; +} + +.green { + color: v_other-other; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.transform.json new file mode 100644 index 00000000000..9b67d56f10b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/composes.transform.json @@ -0,0 +1,32 @@ +{ + "my-class": [ + { + "type": "local", + "name": "__local__my-class" + } + ], + "other": [ + { + "type": "local", + "name": "__local__other" + } + ], + "ghi": [ + { + "type": "local", + "name": "__local__ghi" + } + ], + "other-other": [ + { + "type": "local", + "name": "__local__other-other" + } + ], + "green": [ + { + "type": "local", + "name": "__local__green" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.compiled.css new file mode 100644 index 00000000000..075f5246b02 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.compiled.css @@ -0,0 +1,4 @@ +@value v_def: red; +@value v_other-other: green; +@value s-white: white; +@value m-small: (min-width: 320px); diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.css new file mode 100644 index 00000000000..075f5246b02 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/composes/values.css @@ -0,0 +1,4 @@ +@value v_def: red; +@value v_other-other: green; +@value s-white: white; +@value m-small: (min-width: 320px); diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.compiled.css new file mode 100644 index 00000000000..2ca8bb06daf --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.compiled.css @@ -0,0 +1,6 @@ +.__local__foo_barBaz { + color: red; +} +.bar { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.css new file mode 100644 index 00000000000..6c1ec23d112 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.css @@ -0,0 +1,7 @@ +:local(.foo_barBaz) { + color: red; +} + +:global(.bar) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.transform.json new file mode 100644 index 00000000000..426d42a0ba1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/dashesOnly/index.transform.json @@ -0,0 +1,8 @@ +{ + "foo_barBaz": [ + { + "type": "local", + "name": "__local__foo_barBaz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.compiled.css new file mode 100644 index 00000000000..b2cda0a546d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.compiled.css @@ -0,0 +1,17 @@ +@value v-def from '../../composes/values.css'; +@value v-primary: #BF4040; +@value s-black: black-selector; +@value m-large: (min-width: 960px); +.__local__header { + color: v-primary; + padding: 0 10px; +} +.__local__s-black { + color: black; +} +@media m-large and (max-width: 1024px) { + .__local__header { + color: v-def; + padding: 0 20px; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.css new file mode 100644 index 00000000000..0d260864fbe --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.css @@ -0,0 +1,20 @@ +@value v-def from '../../composes/values.css'; +@value v-primary: #BF4040; +@value s-black: black-selector; +@value m-large: (min-width: 960px); + +.header { + color: v-primary; + padding: 0 10px; +} + +.s-black { + color: black; +} + +@media m-large and (max-width: 1024px) { + .header { + color: v-def; + padding: 0 20px; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.transform.json new file mode 100644 index 00000000000..059f4fb6da7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/nested/index.transform.json @@ -0,0 +1,14 @@ +{ + "s-black": [ + { + "type": "local", + "name": "__local__s-black" + } + ], + "header": [ + { + "type": "local", + "name": "__local__header" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.compiled.css new file mode 100644 index 00000000000..a547fa4bd33 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.compiled.css @@ -0,0 +1,9 @@ +.__local__header-baz { + color: red; +} +.__local__body { + color: coral; +} +.__local__footer { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.css new file mode 100644 index 00000000000..b3ccc301cd7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.css @@ -0,0 +1,11 @@ +:local(.header-baz) { + color: red; +} + +:local(.body) { + color: coral; +} + +:local(.footer) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.transform.json new file mode 100644 index 00000000000..8baa9556683 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template-2/index.transform.json @@ -0,0 +1,20 @@ +{ + "body": [ + { + "type": "local", + "name": "__local__body" + } + ], + "footer": [ + { + "type": "local", + "name": "__local__footer" + } + ], + "header-baz": [ + { + "type": "local", + "name": "__local__header-baz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.compiled.css new file mode 100644 index 00000000000..a547fa4bd33 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.compiled.css @@ -0,0 +1,9 @@ +.__local__header-baz { + color: red; +} +.__local__body { + color: coral; +} +.__local__footer { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.css b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.css new file mode 100644 index 00000000000..b3ccc301cd7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.css @@ -0,0 +1,11 @@ +:local(.header-baz) { + color: red; +} + +:local(.body) { + color: coral; +} + +:local(.footer) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.transform.json new file mode 100644 index 00000000000..8baa9556683 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/namedExport/template/index.transform.json @@ -0,0 +1,20 @@ +{ + "body": [ + { + "type": "local", + "name": "__local__body" + } + ], + "footer": [ + { + "type": "local", + "name": "__local__footer" + } + ], + "header-baz": [ + { + "type": "local", + "name": "__local__header-baz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/index.compiled.css b/crates/swc_css_modules/tests/fixture/modules/order/index.compiled.css new file mode 100644 index 00000000000..cea80dd730c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/index.compiled.css @@ -0,0 +1,6 @@ +.__local__simple { + display: block; +} +.__local__simple-other { + display: inline; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/index.css b/crates/swc_css_modules/tests/fixture/modules/order/index.css new file mode 100644 index 00000000000..35fdc4701d0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/index.css @@ -0,0 +1,12 @@ +.simple { + display: block; + composes: order-1 from './order-1.css'; + composes: order-2 from './order-2.css'; + composes: order-1-1 from './order-1.css'; + composes: order-2-2 from './order-2.css'; +} + +.simple-other { + display: inline; + composes: order-1 from './order-1.css'; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/index.imports.json b/crates/swc_css_modules/tests/fixture/modules/order/index.imports.json new file mode 100644 index 00000000000..66731099c06 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/index.imports.json @@ -0,0 +1,4 @@ +[ + "./order-1.css", + "./order-2.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/order/index.transform.json b/crates/swc_css_modules/tests/fixture/modules/order/index.transform.json new file mode 100644 index 00000000000..bdf804168d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/index.transform.json @@ -0,0 +1,39 @@ +{ + "simple": [ + { + "type": "local", + "name": "__local__simple" + }, + { + "type": "import", + "name": "order-1", + "from": "./order-1.css" + }, + { + "type": "import", + "name": "order-2", + "from": "./order-2.css" + }, + { + "type": "import", + "name": "order-1-1", + "from": "./order-1.css" + }, + { + "type": "import", + "name": "order-2-2", + "from": "./order-2.css" + } + ], + "simple-other": [ + { + "type": "local", + "name": "__local__simple-other" + }, + { + "type": "import", + "name": "order-1", + "from": "./order-1.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-1.compiled.css b/crates/swc_css_modules/tests/fixture/modules/order/order-1.compiled.css new file mode 100644 index 00000000000..5ee3ae9100b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-1.compiled.css @@ -0,0 +1,6 @@ +.__local__order-1 { + color: red; +} +.__local__order-1-1 { + color: aliceblue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-1.css b/crates/swc_css_modules/tests/fixture/modules/order/order-1.css new file mode 100644 index 00000000000..a215a5be948 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-1.css @@ -0,0 +1,7 @@ +.order-1 { + color: red; +} + +.order-1-1 { + color: aliceblue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-1.transform.json b/crates/swc_css_modules/tests/fixture/modules/order/order-1.transform.json new file mode 100644 index 00000000000..4c0f2cfe9fa --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-1.transform.json @@ -0,0 +1,14 @@ +{ + "order-1": [ + { + "type": "local", + "name": "__local__order-1" + } + ], + "order-1-1": [ + { + "type": "local", + "name": "__local__order-1-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-2.compiled.css b/crates/swc_css_modules/tests/fixture/modules/order/order-2.compiled.css new file mode 100644 index 00000000000..be18dd5aa8e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-2.compiled.css @@ -0,0 +1,6 @@ +.__local__order-2 { + color: blue; +} +.__local__order-2-2 { + color: azure; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-2.css b/crates/swc_css_modules/tests/fixture/modules/order/order-2.css new file mode 100644 index 00000000000..0c18d6bfb79 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-2.css @@ -0,0 +1,7 @@ +.order-2 { + color: blue; +} + +.order-2-2 { + color: azure; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/order/order-2.transform.json b/crates/swc_css_modules/tests/fixture/modules/order/order-2.transform.json new file mode 100644 index 00000000000..4321ee4d149 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/order/order-2.transform.json @@ -0,0 +1,14 @@ +{ + "order-2": [ + { + "type": "local", + "name": "__local__order-2" + } + ], + "order-2-2": [ + { + "type": "local", + "name": "__local__order-2-2" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.compiled.css b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.compiled.css new file mode 100644 index 00000000000..c1311b20488 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.compiled.css @@ -0,0 +1,3 @@ +.__local__imported-relative { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.css b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.css new file mode 100644 index 00000000000..4459531856a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.css @@ -0,0 +1,3 @@ +.imported-relative { + display: block; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.transform.json b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.transform.json new file mode 100644 index 00000000000..7abdec479ac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/package/one.transform.json @@ -0,0 +1,8 @@ +{ + "imported-relative": [ + { + "type": "local", + "name": "__local__imported-relative" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.compiled.css new file mode 100644 index 00000000000..a135fdf8163 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.compiled.css @@ -0,0 +1,6 @@ +.__local__one { + color: yellow; +} +.__local__two { + color: yellow; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.css b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.css new file mode 100644 index 00000000000..320ac0d7004 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.css @@ -0,0 +1,9 @@ +.one { + color: yellow; + composes: imported-relative from 'package/one.css'; +} + +.two { + color: yellow; + composes: imported-relative from 'package/two.css'; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.imports.json new file mode 100644 index 00000000000..1d37d416b64 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.imports.json @@ -0,0 +1,4 @@ +[ + "package/one.css", + "package/two.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.transform.json new file mode 100644 index 00000000000..58d82c92a9a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/prefer-relative/source.transform.json @@ -0,0 +1,24 @@ +{ + "one": [ + { + "type": "local", + "name": "__local__one" + }, + { + "type": "import", + "name": "imported-relative", + "from": "package/one.css" + } + ], + "two": [ + { + "type": "local", + "name": "__local__two" + }, + { + "type": "import", + "name": "imported-relative", + "from": "package/two.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/pure/pure.compiled.css b/crates/swc_css_modules/tests/fixture/modules/pure/pure.compiled.css new file mode 100644 index 00000000000..b37d5f7d052 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/pure/pure.compiled.css @@ -0,0 +1,30 @@ +.__local__foo { + color: red; +} +h1 .__local__foo-1 { + color: green; +} +.__local__foo-2 h1 { + color: blue; +} +.__local__foo-3 h1 .__local__foo-4 { + color: red; +} +#__local__foo-5 { + color: red; +} +h1 #__local__foo-6 { + color: green; +} +#__local__foo-7 h1 { + color: blue; +} +#__local__foo-8 h1 #__local__foo-9 { + color: red; +} +.__local__bar-1 .bar .__local__bar-2 { + color: white; +} +.__local__baz-3 .__local__baz .__local__bar-4 { + color: black; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/pure/pure.css b/crates/swc_css_modules/tests/fixture/modules/pure/pure.css new file mode 100644 index 00000000000..addb88d0603 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/pure/pure.css @@ -0,0 +1,39 @@ +.foo { + color: red; +} + +h1 .foo-1 { + color: green; +} + +.foo-2 h1 { + color: blue; +} + +.foo-3 h1 .foo-4 { + color: red; +} + +#foo-5 { + color: red; +} + +h1 #foo-6 { + color: green; +} + +#foo-7 h1 { + color: blue; +} + +#foo-8 h1 #foo-9 { + color: red; +} + +.bar-1 :global(.bar) .bar-2 { + color: white; +} + +.baz-3 :local(.baz) .bar-4 { + color: black; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/pure/pure.transform.json b/crates/swc_css_modules/tests/fixture/modules/pure/pure.transform.json new file mode 100644 index 00000000000..9f2ca7579da --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/pure/pure.transform.json @@ -0,0 +1,92 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "baz": [ + { + "type": "local", + "name": "__local__baz" + } + ], + "foo-2": [ + { + "type": "local", + "name": "__local__foo-2" + } + ], + "foo-3": [ + { + "type": "local", + "name": "__local__foo-3" + } + ], + "foo-7": [ + { + "type": "local", + "name": "__local__foo-7" + } + ], + "foo-8": [ + { + "type": "local", + "name": "__local__foo-8" + } + ], + "foo-9": [ + { + "type": "local", + "name": "__local__foo-9" + } + ], + "bar-1": [ + { + "type": "local", + "name": "__local__bar-1" + } + ], + "bar-2": [ + { + "type": "local", + "name": "__local__bar-2" + } + ], + "baz-3": [ + { + "type": "local", + "name": "__local__baz-3" + } + ], + "foo-4": [ + { + "type": "local", + "name": "__local__foo-4" + } + ], + "foo-5": [ + { + "type": "local", + "name": "__local__foo-5" + } + ], + "foo-6": [ + { + "type": "local", + "name": "__local__foo-6" + } + ], + "foo-1": [ + { + "type": "local", + "name": "__local__foo-1" + } + ], + "bar-4": [ + { + "type": "local", + "name": "__local__bar-4" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.compiled.css new file mode 100644 index 00000000000..c52e0d9a64b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.compiled.css @@ -0,0 +1,3 @@ +a { + animation: __local__slide-right 300ms forwards ease-out, __local__fade-in 300ms forwards ease-out; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.css new file mode 100644 index 00000000000..cf71c59c48f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.css @@ -0,0 +1,4 @@ +a { + animation: slide-right 300ms forwards ease-out, fade-in 300ms forwards ease-out; + +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.transform.json new file mode 100644 index 00000000000..6191234b6fa --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/animation/source.transform.json @@ -0,0 +1,14 @@ +{ + "fade-in": [ + { + "type": "local", + "name": "__local__fade-in" + } + ], + "slide-right": [ + { + "type": "local", + "name": "__local__slide-right" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.compiled.css new file mode 100644 index 00000000000..6fcf868f6e6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.compiled.css @@ -0,0 +1,4 @@ +.__local__class-1, +.__local__class-10 .__local__bar-1 { + color: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.css new file mode 100644 index 00000000000..b22e5c34c59 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.css @@ -0,0 +1,3 @@ +.class-1, .class-10 .bar-1 { + color: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.transform.json new file mode 100644 index 00000000000..e5d6b638693 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/class-names/source.transform.json @@ -0,0 +1,20 @@ +{ + "class-10": [ + { + "type": "local", + "name": "__local__class-10" + } + ], + "bar-1": [ + { + "type": "local", + "name": "__local__bar-1" + } + ], + "class-1": [ + { + "type": "local", + "name": "__local__class-1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.compiled.css new file mode 100644 index 00000000000..f7d3a00b9d9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.compiled.css @@ -0,0 +1,3 @@ +.__local__c1.__local__c3 { + background: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.css new file mode 100644 index 00000000000..c0f875603fd --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.css @@ -0,0 +1 @@ +:local(.c1/*.c2*/.c3) { background: red; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.transform.json new file mode 100644 index 00000000000..56ec1e43774 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comment-in-local/source.transform.json @@ -0,0 +1,14 @@ +{ + "c1": [ + { + "type": "local", + "name": "__local__c1" + } + ], + "c3": [ + { + "type": "local", + "name": "__local__c3" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.compiled.css new file mode 100644 index 00000000000..2c8c75d796b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.compiled.css @@ -0,0 +1,3 @@ +.__local__bg { + background-image: url(./img.png); +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.css new file mode 100644 index 00000000000..085fa70cff4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.css @@ -0,0 +1,11 @@ +/* + * a ' above + */ + +.bg { + background-image: url(./img.png); +} + +/* + * a ' below + */ diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.transform.json new file mode 100644 index 00000000000..06a8f7e4e93 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/comments/source.transform.json @@ -0,0 +1,8 @@ +{ + "bg": [ + { + "type": "local", + "name": "__local__bg" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.compiled.css new file mode 100644 index 00000000000..2f30a68b6ee --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.compiled.css @@ -0,0 +1,9 @@ +.__local__c2 { + color: red; +} +.__local__c4 { + color: blue; +} +.__local__test { + c: d; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.css new file mode 100644 index 00000000000..46865129fad --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.css @@ -0,0 +1,11 @@ +:local(.c2) { + color: red; +} + +:local(.c4) { + color: blue; +} + +.test{ + c: d +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.transform.json new file mode 100644 index 00000000000..455a7a8cc95 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/file.transform.json @@ -0,0 +1,20 @@ +{ + "c2": [ + { + "type": "local", + "name": "__local__c2" + } + ], + "c4": [ + { + "type": "local", + "name": "__local__c4" + } + ], + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.compiled.css new file mode 100644 index 00000000000..c2e5c66c726 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.compiled.css @@ -0,0 +1,9 @@ +.__local__c1 { + b: 1; +} +.__local__c3 { + b: 3; +} +.__local__c5 { + b: 5; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.css new file mode 100644 index 00000000000..1b2e16dd2e5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.css @@ -0,0 +1,3 @@ +:local(.c1) { composes: c2 from "./file.css"; b: 1; } +:local(.c3) { composes: c1; b: 3; } +:local(.c5) { composes: c2 c4 from "./file.css"; b: 5; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.imports.json new file mode 100644 index 00000000000..fec663e32db --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.imports.json @@ -0,0 +1,3 @@ +[ + "./file.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.transform.json new file mode 100644 index 00000000000..9d2c41fdcb4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-1/source.transform.json @@ -0,0 +1,39 @@ +{ + "c1": [ + { + "type": "local", + "name": "__local__c1" + }, + { + "type": "import", + "name": "c2", + "from": "./file.css" + } + ], + "c3": [ + { + "type": "local", + "name": "__local__c3" + }, + { + "type": "local", + "name": "__local__c1" + } + ], + "c5": [ + { + "type": "local", + "name": "__local__c5" + }, + { + "type": "import", + "name": "c2", + "from": "./file.css" + }, + { + "type": "import", + "name": "c4", + "from": "./file.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.compiled.css new file mode 100644 index 00000000000..70b3378799d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.compiled.css @@ -0,0 +1,9 @@ +.__local__c-2 { + color: red; +} +.__local__c4 { + color: blue; +} +.__local__test { + c: d; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.css new file mode 100644 index 00000000000..73635f2e17e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.css @@ -0,0 +1,11 @@ +:local(.c-2) { + color: red; +} + +:local(.c4) { + color: blue; +} + +.test{ + c: d +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.transform.json new file mode 100644 index 00000000000..090a27d3b6a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/file.transform.json @@ -0,0 +1,20 @@ +{ + "c-2": [ + { + "type": "local", + "name": "__local__c-2" + } + ], + "c4": [ + { + "type": "local", + "name": "__local__c4" + } + ], + "test": [ + { + "type": "local", + "name": "__local__test" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.compiled.css new file mode 100644 index 00000000000..c2e5c66c726 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.compiled.css @@ -0,0 +1,9 @@ +.__local__c1 { + b: 1; +} +.__local__c3 { + b: 3; +} +.__local__c5 { + b: 5; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.css new file mode 100644 index 00000000000..213d023ddd3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.css @@ -0,0 +1,3 @@ +:local(.c1) { composes: c-2 from "./file.css"; b: 1; } +:local(.c3) { composes: c1; b: 3; } +:local(.c5) { composes: c-2 c4 from "./file.css"; b: 5; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.imports.json new file mode 100644 index 00000000000..fec663e32db --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.imports.json @@ -0,0 +1,3 @@ +[ + "./file.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.transform.json new file mode 100644 index 00000000000..74d54730c71 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-2/source.transform.json @@ -0,0 +1,39 @@ +{ + "c1": [ + { + "type": "local", + "name": "__local__c1" + }, + { + "type": "import", + "name": "c-2", + "from": "./file.css" + } + ], + "c3": [ + { + "type": "local", + "name": "__local__c3" + }, + { + "type": "local", + "name": "__local__c1" + } + ], + "c5": [ + { + "type": "local", + "name": "__local__c5" + }, + { + "type": "import", + "name": "c-2", + "from": "./file.css" + }, + { + "type": "import", + "name": "c4", + "from": "./file.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.compiled.css new file mode 100644 index 00000000000..adcf2d56385 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.compiled.css @@ -0,0 +1,3 @@ +.__local__def1 { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.css new file mode 100644 index 00000000000..881655a8031 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.css @@ -0,0 +1,3 @@ +:local(.def1) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.transform.json new file mode 100644 index 00000000000..2a0580018b8 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file1.transform.json @@ -0,0 +1,8 @@ +{ + "def1": [ + { + "type": "local", + "name": "__local__def1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.compiled.css new file mode 100644 index 00000000000..e3147e28c1b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.compiled.css @@ -0,0 +1,3 @@ +.__local__def2 { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.css new file mode 100644 index 00000000000..6dcbdaf7bc6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.css @@ -0,0 +1,3 @@ +:local(.def2) { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.transform.json new file mode 100644 index 00000000000..01e3034ed9d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/file2.transform.json @@ -0,0 +1,8 @@ +{ + "def2": [ + { + "type": "local", + "name": "__local__def2" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.compiled.css new file mode 100644 index 00000000000..434d0d60dfe --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.compiled.css @@ -0,0 +1 @@ +.__local__abc {} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.css new file mode 100644 index 00000000000..955e078e608 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.css @@ -0,0 +1,4 @@ +:local(.abc) { + composes: def1 from "./file1.css"; + composes: def2 from "./file2.css"; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.imports.json new file mode 100644 index 00000000000..8d67dc95934 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.imports.json @@ -0,0 +1,4 @@ +[ + "./file1.css", + "./file2.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.transform.json new file mode 100644 index 00000000000..8d14fc78a9f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-multiple/source.transform.json @@ -0,0 +1,18 @@ +{ + "abc": [ + { + "type": "local", + "name": "__local__abc" + }, + { + "type": "import", + "name": "def1", + "from": "./file1.css" + }, + { + "type": "import", + "name": "def2", + "from": "./file2.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.compiled.css new file mode 100644 index 00000000000..3583f0fcd2a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.compiled.css @@ -0,0 +1,3 @@ +.__local__def { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.css new file mode 100644 index 00000000000..0101f9c3e61 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.css @@ -0,0 +1,3 @@ +:local(.def) { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.transform.json new file mode 100644 index 00000000000..a3fb99c6b43 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/file.transform.json @@ -0,0 +1,8 @@ +{ + "def": [ + { + "type": "local", + "name": "__local__def" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.compiled.css new file mode 100644 index 00000000000..434d0d60dfe --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.compiled.css @@ -0,0 +1 @@ +.__local__abc {} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.css new file mode 100644 index 00000000000..72156c3ad7c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.css @@ -0,0 +1,3 @@ +:local(.abc) { + composes: def from "./file.css"; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.imports.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.imports.json new file mode 100644 index 00000000000..fec663e32db --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.imports.json @@ -0,0 +1,3 @@ +[ + "./file.css" +] diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.transform.json new file mode 100644 index 00000000000..e4fbde532e2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes-with-importing/source.transform.json @@ -0,0 +1,13 @@ +{ + "abc": [ + { + "type": "local", + "name": "__local__abc" + }, + { + "type": "import", + "name": "def", + "from": "./file.css" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.compiled.css new file mode 100644 index 00000000000..63d60320784 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.compiled.css @@ -0,0 +1,6 @@ +.__local__c1 { + a: 1; +} +.__local__c2 { + b: 1; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.css new file mode 100644 index 00000000000..64a8f521f22 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.css @@ -0,0 +1,2 @@ +:local(.c1) { a: 1; } +:local(.c2) { composes: c1; b: 1; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.transform.json new file mode 100644 index 00000000000..8b8b2a7b617 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/composes/source.transform.json @@ -0,0 +1,18 @@ +{ + "c1": [ + { + "type": "local", + "name": "__local__c1" + } + ], + "c2": [ + { + "type": "local", + "name": "__local__c2" + }, + { + "type": "local", + "name": "__local__c1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.compiled.css new file mode 100644 index 00000000000..2b68e377566 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.compiled.css @@ -0,0 +1,4 @@ +@value blue: red; +.__local__a { + border: 1px solid blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.css new file mode 100644 index 00000000000..bd8987b12b9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.css @@ -0,0 +1,5 @@ +@value blue: red; + +.a { + border: 1px solid blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.transform.json new file mode 100644 index 00000000000..1d62625f4f0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/declaration-value/source.transform.json @@ -0,0 +1,8 @@ +{ + "a": [ + { + "type": "local", + "name": "__local__a" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.compiled.css new file mode 100644 index 00000000000..f3ed67a14f6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.compiled.css @@ -0,0 +1,4 @@ +body:before { + content: ''; + background: url('!!file-loader?esModule=false!./img.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.css new file mode 100644 index 00000000000..f3ed67a14f6 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/issue-589/source.css @@ -0,0 +1,4 @@ +body:before { + content: ''; + background: url('!!file-loader?esModule=false!./img.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.compiled.css new file mode 100644 index 00000000000..e30ba4589c9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.compiled.css @@ -0,0 +1,41 @@ +.__local__a { + color: green; +} +@keyframes __local__bounce { + 0% { + transform: translateY(-100%); + opacity: 0; + } + 5% { + transform: translateY(-100%); + opacity: 0; + } +} +@-webkit-keyframes __local__bounce2 { + 0% { + transform: translateY(-100%); + opacity: 0; + } + 5% { + transform: translateY(-100%); + opacity: 0; + } +} +.__local__bounce { + animation-name: __local__bounce; + animation: __local__bounce2 1s ease; +} +.__local__bounce2 { + color: green; + animation: __local__bounce 1s ease; + animation-name: __local__bounce2; +} +.__local__bounce3 { + animation: __local__bounce 1s ease, __local__bounce2; +} +.__local__bounce4 { + animation: __local__bounce 1s ease, __local__bounce2; +} +.__local__b { + color: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.css new file mode 100644 index 00000000000..5aa7d337def --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.css @@ -0,0 +1,48 @@ +.a { + color: green; +} + +@keyframes bounce { + 0% { + transform: translateY(-100%); + opacity: 0; + } + 5% { + transform: translateY(-100%); + opacity: 0; + } +} + +@-webkit-keyframes bounce2 { + 0% { + transform: translateY(-100%); + opacity: 0; + } + 5% { + transform: translateY(-100%); + opacity: 0; + } +} + +.bounce { + animation-name: bounce; + animation: bounce2 1s ease; +} + +.bounce2 { + color: green; + animation: bounce 1s ease; + animation-name: bounce2; +} + +.bounce3 { + animation: bounce 1s ease, bounce2 +} + +.bounce4 { + animation: bounce 1s ease, bounce2; +} + +.b { + color: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.transform.json new file mode 100644 index 00000000000..1c00c296a1b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/keyframes-and-animation/source.transform.json @@ -0,0 +1,38 @@ +{ + "b": [ + { + "type": "local", + "name": "__local__b" + } + ], + "bounce": [ + { + "type": "local", + "name": "__local__bounce" + } + ], + "bounce2": [ + { + "type": "local", + "name": "__local__bounce2" + } + ], + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "bounce3": [ + { + "type": "local", + "name": "__local__bounce3" + } + ], + "bounce4": [ + { + "type": "local", + "name": "__local__bounce4" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.compiled.css new file mode 100644 index 00000000000..2c1d10a75e0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.compiled.css @@ -0,0 +1,42 @@ +.__local__a { + color: green; + animation: __local__a; +} +@keyframes __local__b { + 0% { + left: 10px; + } + 100% { + left: 20px; + } +} +.__local__b { + animation: __local__b; +} +@keyframes :global(c) { + 0% { + left: 10px; + } + 100% { + left: 20px; + } +} +.__local__c { + animation: __local__c1; + animation: __local__c2, __local__c3, __local__c4; +} +@keyframes :global(d) { + 0% { + left: 10px; + } + 100% { + left: 20px; + } +} +:global .__local__d1 { + animation: __local__d1; + animation: __local__d2, __local__d3, __local__d4; +} +.d2 { + animation: __local__d2; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.css new file mode 100644 index 00000000000..586ef5e743a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.css @@ -0,0 +1,37 @@ +.a { + color: green; + animation: a; +} + +@keyframes b { + 0% { left: 10px; } + 100% { left: 20px; } +} + +.b { + animation: b; +} + +@keyframes :global(c) { + 0% { left: 10px; } + 100% { left: 20px; } +} + +.c { + animation: c1; + animation: c2, c3, c4; +} + +@keyframes :global(d) { + 0% { left: 10px; } + 100% { left: 20px; } +} + +:global .d1 { + animation: d1; + animation: d2, d3, d4; +} + +:global(.d2) { + animation: d2; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.transform.json new file mode 100644 index 00000000000..e27ca6f55a9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/leak-scope/source.transform.json @@ -0,0 +1,68 @@ +{ + "b": [ + { + "type": "local", + "name": "__local__b" + } + ], + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "c3": [ + { + "type": "local", + "name": "__local__c3" + } + ], + "c4": [ + { + "type": "local", + "name": "__local__c4" + } + ], + "c": [ + { + "type": "local", + "name": "__local__c" + } + ], + "c1": [ + { + "type": "local", + "name": "__local__c1" + } + ], + "c2": [ + { + "type": "local", + "name": "__local__c2" + } + ], + "d1": [ + { + "type": "local", + "name": "__local__d1" + } + ], + "d2": [ + { + "type": "local", + "name": "__local__d2" + } + ], + "d3": [ + { + "type": "local", + "name": "__local__d3" + } + ], + "d4": [ + { + "type": "local", + "name": "__local__d4" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.compiled.css new file mode 100644 index 00000000000..c17f1726d7e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.compiled.css @@ -0,0 +1,12 @@ +.__local__className { + background: red; +} +#__local__someId { + background: green; +} +.__local__className .__local__subClass { + color: green; +} +#__local__someId .__local__subClass { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.css new file mode 100644 index 00000000000..c3217975bad --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.css @@ -0,0 +1,4 @@ +:local(.className) { background: red; } +:local(#someId) { background: green; } +:local(.className .subClass) { color: green; } +:local(#someId .subClass) { color: blue; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.transform.json new file mode 100644 index 00000000000..a130fbcd906 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-2/source.transform.json @@ -0,0 +1,20 @@ +{ + "someId": [ + { + "type": "local", + "name": "__local__someId" + } + ], + "subClass": [ + { + "type": "local", + "name": "__local__subClass" + } + ], + "className": [ + { + "type": "local", + "name": "__local__className" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.compiled.css new file mode 100644 index 00000000000..525a612af9f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.compiled.css @@ -0,0 +1,6 @@ +.__local__abc { + color: red; +} +.__local__def { + background: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.css new file mode 100644 index 00000000000..50366086c2b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.css @@ -0,0 +1,7 @@ +:local(.abc) { + color: red; +} +:local(.def) { + composes: abc; + background: green; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.transform.json new file mode 100644 index 00000000000..d28fa6a2e43 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-and-composes/source.transform.json @@ -0,0 +1,18 @@ +{ + "abc": [ + { + "type": "local", + "name": "__local__abc" + } + ], + "def": [ + { + "type": "local", + "name": "__local__def" + }, + { + "type": "local", + "name": "__local__abc" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.compiled.css new file mode 100644 index 00000000000..eca5588ec22 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.compiled.css @@ -0,0 +1,3 @@ +.__local__c1[data-attr=".c2)]'"]:not(.__local__c3):not(.__local__c4) { + background: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.css new file mode 100644 index 00000000000..ded020d5f3c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.css @@ -0,0 +1,3 @@ +:local(.c1[data-attr=".c2)]'"]:not(.c3):not(.c4)) { + background: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.transform.json new file mode 100644 index 00000000000..955ecf556f4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local-with-string/source.transform.json @@ -0,0 +1,20 @@ +{ + "c3": [ + { + "type": "local", + "name": "__local__c3" + } + ], + "c4": [ + { + "type": "local", + "name": "__local__c4" + } + ], + "c1": [ + { + "type": "local", + "name": "__local__c1" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.compiled.css new file mode 100644 index 00000000000..03c61ecb98f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.compiled.css @@ -0,0 +1,6 @@ +.__local__abc .__local__def { + color: red; +} +:local .__local__ghi .__local__jkl { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.css new file mode 100644 index 00000000000..ca4a0ac541e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.css @@ -0,0 +1,7 @@ +.abc :local(.def) { + color: red; +} + +:local .ghi .jkl { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.transform.json new file mode 100644 index 00000000000..cca9e1cecb9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/local/source.transform.json @@ -0,0 +1,26 @@ +{ + "jkl": [ + { + "type": "local", + "name": "__local__jkl" + } + ], + "abc": [ + { + "type": "local", + "name": "__local__abc" + } + ], + "def": [ + { + "type": "local", + "name": "__local__def" + } + ], + "ghi": [ + { + "type": "local", + "name": "__local__ghi" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.compiled.css new file mode 100644 index 00000000000..1f9fb325c80 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.compiled.css @@ -0,0 +1 @@ +@value small: (max-width: 599px); diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.css new file mode 100644 index 00000000000..1f9fb325c80 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/file.css @@ -0,0 +1 @@ +@value small: (max-width: 599px); diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.compiled.css new file mode 100644 index 00000000000..77097548093 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.compiled.css @@ -0,0 +1,6 @@ +@value small from './file.css'; +@media small { + .__local__header { + box-shadow: 0 0 4px #1F4F7F; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.css new file mode 100644 index 00000000000..e284fc6f6a9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.css @@ -0,0 +1,6 @@ +@value small from './file.css'; +@media small { + .header { + box-shadow: 0 0 4px #1F4F7F; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.transform.json new file mode 100644 index 00000000000..886875f6cae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media-2/source.transform.json @@ -0,0 +1,8 @@ +{ + "header": [ + { + "type": "local", + "name": "__local__header" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.compiled.css new file mode 100644 index 00000000000..b982461b3c7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.compiled.css @@ -0,0 +1,6 @@ +@value small: (max-width: 599px); +@media small { + .__local__header { + box-shadow: 0 0 4px #1F4F7F; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.css new file mode 100644 index 00000000000..08b97c6e63c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.css @@ -0,0 +1,7 @@ +@value small: (max-width: 599px); + +@media small { + .header { + box-shadow: 0 0 4px #1F4F7F; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.transform.json new file mode 100644 index 00000000000..886875f6cae --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/media/source.transform.json @@ -0,0 +1,8 @@ +{ + "header": [ + { + "type": "local", + "name": "__local__header" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.compiled.css new file mode 100644 index 00000000000..638c582b95b --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.compiled.css @@ -0,0 +1,7 @@ +.__local__c1 :local .__local__c2 .__local__c3 :global .__local__c4 :local .__local__c5, +.__local__c6 :local .__local__c7 { + background: red; +} +.__local__c8 { + background: red; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.css new file mode 100644 index 00000000000..71acd66b8cb --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.css @@ -0,0 +1,2 @@ +.c1 :local .c2 .c3 :global .c4 :local .c5, .c6 :local .c7 { background: red; } +.c8 { background: red; } diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.transform.json new file mode 100644 index 00000000000..7750066cfda --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/mode-switching/source.transform.json @@ -0,0 +1,50 @@ +{ + "c4": [ + { + "type": "local", + "name": "__local__c4" + } + ], + "c5": [ + { + "type": "local", + "name": "__local__c5" + } + ], + "c6": [ + { + "type": "local", + "name": "__local__c6" + } + ], + "c7": [ + { + "type": "local", + "name": "__local__c7" + } + ], + "c1": [ + { + "type": "local", + "name": "__local__c1" + } + ], + "c2": [ + { + "type": "local", + "name": "__local__c2" + } + ], + "c3": [ + { + "type": "local", + "name": "__local__c3" + } + ], + "c8": [ + { + "type": "local", + "name": "__local__c8" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.compiled.css new file mode 100644 index 00000000000..f16019b21c4 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.compiled.css @@ -0,0 +1,15 @@ +.__local__a .__local__b, +.__local__c .__local__d, +#__local__id { + color: green; + font-size: 1.5pt; +} +a[href="#b.c"].__local__x.__local__y { + color: green; + font-size: 1.5pt; +} +@keyframes __local__z { + 2.5% { + color: green; + } +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.css new file mode 100644 index 00000000000..e928aaf7fed --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.css @@ -0,0 +1,11 @@ +.a .b, .c .d, #id { + color: green; + font-size: 1.5pt; +} +a[href="#b.c"].x.y { + color: green; + font-size: 1.5pt; +} +@keyframes z { + 2.5% {color: green;} +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.transform.json new file mode 100644 index 00000000000..a7d359ee071 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/simple/source.transform.json @@ -0,0 +1,50 @@ +{ + "b": [ + { + "type": "local", + "name": "__local__b" + } + ], + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "c": [ + { + "type": "local", + "name": "__local__c" + } + ], + "d": [ + { + "type": "local", + "name": "__local__d" + } + ], + "y": [ + { + "type": "local", + "name": "__local__y" + } + ], + "z": [ + { + "type": "local", + "name": "__local__z" + } + ], + "id": [ + { + "type": "local", + "name": "__local__id" + } + ], + "x": [ + { + "type": "local", + "name": "__local__x" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.compiled.css new file mode 100644 index 00000000000..20d3722a140 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.compiled.css @@ -0,0 +1,14 @@ +.__local__a { + background: url(./img.png); + background: url("./img.png"); + background: url("./img img.png"); + background: url('./img img.png'); + background: url('./img.png'); + background: url("./img.png#?iefix"); + background: url("#hash"); + background: url("#"); + background: url(data:image/png;base64,AAA); + background: url(http://example.com/image.jpg); + background: url(//example.com/image.png); + background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) url(./img.png) url('./img img.png') xyz; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.css b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.css new file mode 100644 index 00000000000..3865420ed59 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.css @@ -0,0 +1,14 @@ +.a { + background: url(./img.png); + background: url("./img.png"); + background: url("./img img.png"); + background: url('./img img.png'); + background: url('./img.png'); + background: url("./img.png#?iefix"); + background: url("#hash"); + background: url("#"); + background: url(data:image/png;base64,AAA); + background: url(http://example.com/image.jpg); + background: url(//example.com/image.png); + background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) url(./img.png) url('./img img.png') xyz; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.transform.json new file mode 100644 index 00000000000..1d62625f4f0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/tests-cases/urls/source.transform.json @@ -0,0 +1,8 @@ +{ + "a": [ + { + "type": "local", + "name": "__local__a" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/unresolved/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.compiled.css new file mode 100644 index 00000000000..0a514e6bd39 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.compiled.css @@ -0,0 +1,4 @@ +@value foo from './unresolved.css'; +.__local__className { + color: foo; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/unresolved/source.css b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.css new file mode 100644 index 00000000000..964b60b47dc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.css @@ -0,0 +1,6 @@ +@value foo from './unresolved.css'; + +.className { + color: foo; +} + diff --git a/crates/swc_css_modules/tests/fixture/modules/unresolved/source.transform.json b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.transform.json new file mode 100644 index 00000000000..6e33c82e5c7 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/unresolved/source.transform.json @@ -0,0 +1,8 @@ +{ + "className": [ + { + "type": "local", + "name": "__local__className" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/modules/url/shared.compiled.css b/crates/swc_css_modules/tests/fixture/modules/url/shared.compiled.css new file mode 100644 index 00000000000..7662cfb536d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/url/shared.compiled.css @@ -0,0 +1 @@ +@value v-url-other: url('./img.png'); diff --git a/crates/swc_css_modules/tests/fixture/modules/url/shared.css b/crates/swc_css_modules/tests/fixture/modules/url/shared.css new file mode 100644 index 00000000000..7662cfb536d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/url/shared.css @@ -0,0 +1 @@ +@value v-url-other: url('./img.png'); diff --git a/crates/swc_css_modules/tests/fixture/modules/url/source.compiled.css b/crates/swc_css_modules/tests/fixture/modules/url/source.compiled.css new file mode 100644 index 00000000000..190f647cfac --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/url/source.compiled.css @@ -0,0 +1,8 @@ +@value v-url: url('./img.png'); +@value v-url-other from './shared.css'; +a { + background: v-url; +} +body { + background: v-url-other; +} diff --git a/crates/swc_css_modules/tests/fixture/modules/url/source.css b/crates/swc_css_modules/tests/fixture/modules/url/source.css new file mode 100644 index 00000000000..44c9cc8a418 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/modules/url/source.css @@ -0,0 +1,10 @@ +@value v-url: url('./img.png'); +@value v-url-other from './shared.css'; + +a { + background: v-url; +} + +body { + background: v-url-other; +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/imported.compiled.css b/crates/swc_css_modules/tests/fixture/nested-import/imported.compiled.css new file mode 100644 index 00000000000..009acaeed0d --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/imported.compiled.css @@ -0,0 +1,4 @@ +.__local__bar { + color: blue; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/imported.css b/crates/swc_css_modules/tests/fixture/nested-import/imported.css new file mode 100644 index 00000000000..fb5bac7b007 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/imported.css @@ -0,0 +1,4 @@ +.bar { + color: blue; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/imported.transform.json b/crates/swc_css_modules/tests/fixture/nested-import/imported.transform.json new file mode 100644 index 00000000000..f595edbe3de --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/imported.transform.json @@ -0,0 +1,8 @@ +{ + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/other-imported.compiled.css b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.compiled.css new file mode 100644 index 00000000000..c9d389536ba --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.compiled.css @@ -0,0 +1,4 @@ +.__local__baz { + color: green; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/other-imported.css b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.css new file mode 100644 index 00000000000..051e9d940a1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.css @@ -0,0 +1,4 @@ +.baz { + color: green; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/other-imported.transform.json b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.transform.json new file mode 100644 index 00000000000..a66ded61c6c --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/other-imported.transform.json @@ -0,0 +1,8 @@ +{ + "baz": [ + { + "type": "local", + "name": "__local__baz" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/source.compiled.css b/crates/swc_css_modules/tests/fixture/nested-import/source.compiled.css new file mode 100644 index 00000000000..7709b85ad20 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/source.compiled.css @@ -0,0 +1,6 @@ +@import './imported.css'; +@import './other-imported.css'; +.__local__foo { + color: red; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/source.css b/crates/swc_css_modules/tests/fixture/nested-import/source.css new file mode 100644 index 00000000000..6aeedd42516 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/source.css @@ -0,0 +1,7 @@ +@import './imported.css'; +@import './other-imported.css'; + +.foo { + color: red; + color: rgb(0 0 100% / 90%); +} diff --git a/crates/swc_css_modules/tests/fixture/nested-import/source.imports.json b/crates/swc_css_modules/tests/fixture/nested-import/source.imports.json new file mode 100644 index 00000000000..460f409c895 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/source.imports.json @@ -0,0 +1,4 @@ +[ + "./imported.css", + "./other-imported.css" +] diff --git a/crates/swc_css_modules/tests/fixture/nested-import/source.transform.json b/crates/swc_css_modules/tests/fixture/nested-import/source.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/nested-import/source.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/other-loader-query.compiled.css b/crates/swc_css_modules/tests/fixture/other-loader-query.compiled.css new file mode 100644 index 00000000000..2e3c2142b23 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/other-loader-query.compiled.css @@ -0,0 +1,3 @@ +.__local__example { + background-image: url('./url/image.svg?color=%23BAAFDB%3F#foo'); +} diff --git a/crates/swc_css_modules/tests/fixture/other-loader-query.css b/crates/swc_css_modules/tests/fixture/other-loader-query.css new file mode 100644 index 00000000000..bf6816c5dea --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/other-loader-query.css @@ -0,0 +1,3 @@ +.example { + background-image: url('./url/image.svg?color=%23BAAFDB%3F#foo'); +} diff --git a/crates/swc_css_modules/tests/fixture/other-loader-query.transform.json b/crates/swc_css_modules/tests/fixture/other-loader-query.transform.json new file mode 100644 index 00000000000..1ed641ef7f5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/other-loader-query.transform.json @@ -0,0 +1,8 @@ +{ + "example": [ + { + "type": "local", + "name": "__local__example" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/postcss-present-env/source.compiled.css b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.compiled.css new file mode 100644 index 00000000000..da5242a1c64 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.compiled.css @@ -0,0 +1,32 @@ +@custom-media --viewport-medium (width <= 50rem); +@custom-selector :--heading h1, h2, h3, h4, h5, h6; +:root { + --fontSize: 1rem; + --mainColor: #12345678; + --secondaryColor: lab(32.5 38.5 -47.6 / 90%); +} +html { + overflow: hidden auto; +} +@media (--viewport-medium) { + body { + color: var(--mainColor); + font-family: system-ui; + font-size: var(--fontSize); + line-height: calc(var(--fontSize) * 1.5); + overflow-wrap: break-word; + padding-inline: calc(var(--fontSize) / 2 + 1px); + } +} +:--heading { + margin-block: 0; +} +.__local__hero:matches(main, .__local__main) { + background-image: image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); +} +a { + color: rgb(0 0 100% / 90%); + &:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/postcss-present-env/source.css b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.css new file mode 100644 index 00000000000..54be34bdb9e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.css @@ -0,0 +1,39 @@ +@custom-media --viewport-medium (width <= 50rem); +@custom-selector :--heading h1, h2, h3, h4, h5, h6; + +:root { + --fontSize: 1rem; + --mainColor: #12345678; + --secondaryColor: lab(32.5 38.5 -47.6 / 90%); +} + +html { + overflow: hidden auto; +} + +@media (--viewport-medium) { + body { + color: var(--mainColor); + font-family: system-ui; + font-size: var(--fontSize); + line-height: calc(var(--fontSize) * 1.5); + overflow-wrap: break-word; + padding-inline: calc(var(--fontSize) / 2 + 1px); + } +} + +:--heading { + margin-block: 0; +} + +.hero:matches(main, .main) { + background-image: image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); +} + +a { + color: rgb(0 0 100% / 90%); + + &:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/postcss-present-env/source.transform.json b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.transform.json new file mode 100644 index 00000000000..de1c48ecb75 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/postcss-present-env/source.transform.json @@ -0,0 +1,14 @@ +{ + "hero": [ + { + "type": "local", + "name": "__local__hero" + } + ], + "main": [ + { + "type": "local", + "name": "__local__main" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/simple-1.compiled.css b/crates/swc_css_modules/tests/fixture/simple-1.compiled.css new file mode 100644 index 00000000000..e69fdcde2e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple-1.compiled.css @@ -0,0 +1,3 @@ +.__local__some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/simple-1.css b/crates/swc_css_modules/tests/fixture/simple-1.css new file mode 100644 index 00000000000..b58cc07a481 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple-1.css @@ -0,0 +1,3 @@ +.some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/simple-1.transform.json b/crates/swc_css_modules/tests/fixture/simple-1.transform.json new file mode 100644 index 00000000000..8305c2964d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple-1.transform.json @@ -0,0 +1,8 @@ +{ + "some-class": [ + { + "type": "local", + "name": "__local__some-class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/simple.compiled.css b/crates/swc_css_modules/tests/fixture/simple.compiled.css new file mode 100644 index 00000000000..e69fdcde2e9 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple.compiled.css @@ -0,0 +1,3 @@ +.__local__some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/simple.css b/crates/swc_css_modules/tests/fixture/simple.css new file mode 100644 index 00000000000..b58cc07a481 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple.css @@ -0,0 +1,3 @@ +.some-class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/simple.transform.json b/crates/swc_css_modules/tests/fixture/simple.transform.json new file mode 100644 index 00000000000..8305c2964d2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/simple.transform.json @@ -0,0 +1,8 @@ +{ + "some-class": [ + { + "type": "local", + "name": "__local__some-class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.compiled.css b/crates/swc_css_modules/tests/fixture/source-map/basic.compiled.css new file mode 100644 index 00000000000..aa04f0e40d1 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.compiled.css @@ -0,0 +1,4 @@ +@import "./nested/nested.css"; +.__local__class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.css b/crates/swc_css_modules/tests/fixture/source-map/basic.css new file mode 100644 index 00000000000..f125bf87e18 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.css @@ -0,0 +1,5 @@ +@import "./nested/nested.css"; + +.class { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.imports.json b/crates/swc_css_modules/tests/fixture/source-map/basic.imports.json new file mode 100644 index 00000000000..98a28f5317e --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.imports.json @@ -0,0 +1,3 @@ +[ + "./nested/nested.css" +] diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.compiled.css b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.compiled.css new file mode 100644 index 00000000000..21f7d7c3795 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.compiled.css @@ -0,0 +1,30 @@ +@import "./nested/nested.postcss.css"; +@custom-media --viewport-medium (width <= 50rem); +@custom-selector :--heading h1, h2, h3, h4, h5, h6; +:root { + --fontSize: 1rem; + --mainColor: #12345678; + --secondaryColor: lab(32.5 38.5 -47.6 / 90%); +} +html { + overflow: hidden auto; +} +@media (--viewport-medium) { + body { + color: var(--mainColor); + font-family: system-ui; + font-size: var(--fontSize); + line-height: calc(var(--fontSize) * 1.5); + overflow-wrap: break-word; + padding-inline: calc(var(--fontSize) / 2 + 1px); + } +} +:--heading { + margin-block: 0; +} +a { + color: rgb(0 0 100% / 90%); + &:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.css b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.css new file mode 100644 index 00000000000..8da555904ed --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.css @@ -0,0 +1,37 @@ +@import "./nested/nested.postcss.css"; + +@custom-media --viewport-medium (width <= 50rem); +@custom-selector :--heading h1, h2, h3, h4, h5, h6; + +:root { + --fontSize: 1rem; + --mainColor: #12345678; + --secondaryColor: lab(32.5 38.5 -47.6 / 90%); +} + +html { + overflow: hidden auto; +} + +@media (--viewport-medium) { + body { + color: var(--mainColor); + font-family: system-ui; + font-size: var(--fontSize); + line-height: calc(var(--fontSize) * 1.5); + overflow-wrap: break-word; + padding-inline: calc(var(--fontSize) / 2 + 1px); + } +} + +:--heading { + margin-block: 0; +} + +a { + color: rgb(0 0 100% / 90%); + +&:hover { + color: rebeccapurple; + } +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.imports.json b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.imports.json new file mode 100644 index 00000000000..ab963eb9f4f --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.postcss.imports.json @@ -0,0 +1,3 @@ +[ + "./nested/nested.postcss.css" +] diff --git a/crates/swc_css_modules/tests/fixture/source-map/basic.transform.json b/crates/swc_css_modules/tests/fixture/source-map/basic.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/basic.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.compiled.css b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.compiled.css new file mode 100644 index 00000000000..0b2d421d231 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.compiled.css @@ -0,0 +1,3 @@ +.__local__nested { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.css b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.css new file mode 100644 index 00000000000..c4313d19af2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.css @@ -0,0 +1,3 @@ +.nested { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.compiled.css b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.compiled.css new file mode 100644 index 00000000000..0b2d421d231 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.compiled.css @@ -0,0 +1,3 @@ +.__local__nested { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.css b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.css new file mode 100644 index 00000000000..c4313d19af2 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.css @@ -0,0 +1,3 @@ +.nested { + color: blue; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.transform.json b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.transform.json new file mode 100644 index 00000000000..4f42cbc3d16 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.postcss.transform.json @@ -0,0 +1,8 @@ +{ + "nested": [ + { + "type": "local", + "name": "__local__nested" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/nested/nested.transform.json b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.transform.json new file mode 100644 index 00000000000..4f42cbc3d16 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/nested/nested.transform.json @@ -0,0 +1,8 @@ +{ + "nested": [ + { + "type": "local", + "name": "__local__nested" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/with-query.compiled.css b/crates/swc_css_modules/tests/fixture/source-map/with-query.compiled.css new file mode 100644 index 00000000000..50f5c47de37 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/with-query.compiled.css @@ -0,0 +1,3 @@ +.__local__foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/with-query.css b/crates/swc_css_modules/tests/fixture/source-map/with-query.css new file mode 100644 index 00000000000..a15c877ac01 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/with-query.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/crates/swc_css_modules/tests/fixture/source-map/with-query.transform.json b/crates/swc_css_modules/tests/fixture/source-map/with-query.transform.json new file mode 100644 index 00000000000..2d47f5c5a11 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/source-map/with-query.transform.json @@ -0,0 +1,8 @@ +{ + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/url/absolute-url.compiled.css b/crates/swc_css_modules/tests/fixture/url/absolute-url.compiled.css new file mode 100644 index 00000000000..6e01c4f3d54 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/absolute-url.compiled.css @@ -0,0 +1,3 @@ +a { + background: url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/absolute-url.css b/crates/swc_css_modules/tests/fixture/url/absolute-url.css new file mode 100644 index 00000000000..058c94b2afc --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/absolute-url.css @@ -0,0 +1,3 @@ +a { + background: url("https://raw.githubusercontent.com/webpack-contrib/css-loader/master/test/fixtures/url/img.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/false-alias.compiled.css b/crates/swc_css_modules/tests/fixture/url/false-alias.compiled.css new file mode 100644 index 00000000000..8802e3261d5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/false-alias.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + background-image: url(/logo.png); +} diff --git a/crates/swc_css_modules/tests/fixture/url/false-alias.css b/crates/swc_css_modules/tests/fixture/url/false-alias.css new file mode 100644 index 00000000000..cbe79121554 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/false-alias.css @@ -0,0 +1,3 @@ +.class { + background-image: url(/logo.png); +} \ No newline at end of file diff --git a/crates/swc_css_modules/tests/fixture/url/false-alias.transform.json b/crates/swc_css_modules/tests/fixture/url/false-alias.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/false-alias.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/url/ignore-plugin.compiled.css b/crates/swc_css_modules/tests/fixture/url/ignore-plugin.compiled.css new file mode 100644 index 00000000000..1fb0b3dd3b0 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/ignore-plugin.compiled.css @@ -0,0 +1,45 @@ +div { + background: url("/assets/unknown.png"); +} +div { + background: url("./assets/unknown.png"); +} +div { + background: url("assets/unknown.png"); +} +div { + background: url("/unknwon.png"); +} +div { + background: url("./unknwon.png"); +} +div { + background: url("unknwon.png"); +} +div { + background: url("/nested/img.png"); +} +div { + background: url("./nested/img.png"); +} +div { + background: url("./nested/img.png"); +} +div { + background: url("/img.png"); +} +div { + background: url("./img.png"); +} +div { + background: url("img.png"); +} +div { + background: url("/directory/unknown.png"); +} +div { + background: url("./directory/unknown.png"); +} +div { + background: url("directory/unknown.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/ignore-plugin.css b/crates/swc_css_modules/tests/fixture/url/ignore-plugin.css new file mode 100644 index 00000000000..8553bebeb6a --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/ignore-plugin.css @@ -0,0 +1,70 @@ +/* + Unknown + */ +div { + background: url("/assets/unknown.png"); +} + +div { + background: url("./assets/unknown.png"); +} + +div { + background: url("assets/unknown.png"); +} + +div { + background: url("/unknwon.png"); +} + +div { + background: url("./unknwon.png"); +} + +div { + background: url("unknwon.png"); +} + +/* + Known + */ + +div { + background: url("/nested/img.png"); +} + +div { + background: url("./nested/img.png"); +} + +div { + background: url("./nested/img.png"); +} + +div { + background: url("/img.png"); +} + +div { + background: url("./img.png"); +} + +div { + background: url("img.png"); +} + +/* + Directory + */ + +div { + background: url("/directory/unknown.png"); +} + +div { + background: url("./directory/unknown.png"); +} + +div { + background: url("directory/unknown.png"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/imported.compiled.css b/crates/swc_css_modules/tests/fixture/url/imported.compiled.css new file mode 100644 index 00000000000..132ad339268 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/imported.compiled.css @@ -0,0 +1,3 @@ +.__local__bar { + background: url('./img-from-imported.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/imported.css b/crates/swc_css_modules/tests/fixture/url/imported.css new file mode 100644 index 00000000000..c86f4d06a85 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/imported.css @@ -0,0 +1,3 @@ +.bar { + background: url('./img-from-imported.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/imported.transform.json b/crates/swc_css_modules/tests/fixture/url/imported.transform.json new file mode 100644 index 00000000000..f595edbe3de --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/imported.transform.json @@ -0,0 +1,8 @@ +{ + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/url/resolve-extensions.compiled.css b/crates/swc_css_modules/tests/fixture/url/resolve-extensions.compiled.css new file mode 100644 index 00000000000..2a7dce480db --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/resolve-extensions.compiled.css @@ -0,0 +1,3 @@ +div { + background: url("./image"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/resolve-extensions.css b/crates/swc_css_modules/tests/fixture/url/resolve-extensions.css new file mode 100644 index 00000000000..02eb0d34442 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/resolve-extensions.css @@ -0,0 +1,3 @@ +div { + background: url("./image"); +} diff --git a/crates/swc_css_modules/tests/fixture/url/url-unresolved.compiled.css b/crates/swc_css_modules/tests/fixture/url/url-unresolved.compiled.css new file mode 100644 index 00000000000..231b288a488 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url-unresolved.compiled.css @@ -0,0 +1,3 @@ +.__local__class { + background: url('unresolved.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/url-unresolved.css b/crates/swc_css_modules/tests/fixture/url/url-unresolved.css new file mode 100644 index 00000000000..7d046c99469 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url-unresolved.css @@ -0,0 +1,3 @@ +.class { + background: url('unresolved.png'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/url-unresolved.transform.json b/crates/swc_css_modules/tests/fixture/url/url-unresolved.transform.json new file mode 100644 index 00000000000..d750cebed88 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url-unresolved.transform.json @@ -0,0 +1,8 @@ +{ + "class": [ + { + "type": "local", + "name": "__local__class" + } + ] +} diff --git a/crates/swc_css_modules/tests/fixture/url/url.compiled.css b/crates/swc_css_modules/tests/fixture/url/url.compiled.css new file mode 100644 index 00000000000..0f44fdcd8d5 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url.compiled.css @@ -0,0 +1,303 @@ +@import "./imported.css"; +.__local__class { + background: url('./img.png'); +} +.__local__class { + background: url("./img.png"); +} +.__local__class { + background: url(./img.png); +} +.__local__class { + background: url("./img.png#hash"); +} +.__local__class { + background: url("./img.png"); +} +.__local__class { + background: green url('./img.png') xyz; +} +.__local__class { + background: green url("./img.png") xyz; +} +.__local__class { + background: green url( ./img.png ) xyz; +} +.__local__class { + background: green url(~package/img.png) url(./other-img.png) xyz; +} +.__local__class { + background: green url("./img img.png") xyz; +} +.__local__class { + background: green url('./img img.png') xyz; +} +.__local__class { + background: green url(/img.png) xyz; +} +.__local__class { + background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz; +} +.__local__class { + background-image: url("data:image/svg+xml;charset=utf-8,"); +} +.__local__class { + background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2042%2026%27%20fill%3D%27%2523007aff%27%3E%3Crect%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%271%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2711%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2712%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2722%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2723%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3C%2Fsvg%3E"); +} +.__local__class { + filter: url('data:image/svg+xml;charset=utf-8,#filter'); +} +.__local__class { + filter: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%5C%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%5C%22%3E%3Cfilter%20id%3D%5C%22filter%5C%22%3E%3CfeGaussianBlur%20in%3D%5C%22SourceAlpha%5C%22%20stdDeviation%3D%5C%220%5C%22%20%2F%3E%3CfeOffset%20dx%3D%5C%221%5C%22%20dy%3D%5C%222%5C%22%20result%3D%5C%22offsetblur%5C%22%20%2F%3E%3CfeFlood%20flood-color%3D%5C%22rgba(255%2C255%2C255%2C1)%5C%22%20%2F%3E%3CfeComposite%20in2%3D%5C%22offsetblur%5C%22%20operator%3D%5C%22in%5C%22%20%2F%3E%3CfeMerge%3E%3CfeMergeNode%20%2F%3E%3CfeMergeNode%20in%3D%5C%22SourceGraphic%5C%22%20%2F%3E%3C%2FfeMerge%3E%3C%2Ffilter%3E%3C%2Fsvg%3E%23filter'); +} +.__local__highlight { + filter: url(#highlight); +} +.__local__highlight { + filter: url('#line-marker'); +} +@font-face{ + src: url(./font.woff) format('woff'), url('./font.woff2') format('woff2'), url("./font.eot") format('eot'), url(~package/font.ttf) format('truetype'), url("./font with spaces.eot") format("embedded-opentype"), url('./font.svg#svgFontName') format('svg'), url('./font.woff2?foo=bar') format('woff2'), url("./font.eot?#iefix") format('embedded-opentype'), url("./font with spaces.eot?#iefix") format('embedded-opentype'); +} +@media (min-width: 500px) { + body { + background: url("./img.png"); + } +} +a { + content: "do not use url(path)"; +} +b { + content: 'do not "use" url(path)'; +} +@keyframes __local__anim { + background: green url('./img.png') xyz; +} +.__local__a { + background-image: -webkit-image-set(url('./img1x.png') 1x, url('./img2x.png') 2x); +} +.__local__a { + background-image: image-set(url('./img1x.png') 1x, url('./img2x.png') 2x); +} +.__local__class { + background: green url() xyz; +} +.__local__class { + background: green url('') xyz; +} +.__local__class { + background: green url("") xyz; +} +.__local__class { + background: green url(' ') xyz; +} +.__local__class { + background: green url( + ) xyz; +} +.__local__class { + background: green url(https://raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz; +} +.__local__class { + background: green url(//raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz; +} +.__local__class { + background: url("./img.png?foo"); +} +.__local__class { + background: url("./img.png?foo=bar"); +} +.__local__class { + background: url("./img.png?foo=bar#hash"); +} +.__local__class { + background: url("./img.png?foo=bar#hash"); +} +.__local__class { + background: url("./img.png?"); +} +.__local__class { + background-image: url('./img.png') url("data:image/svg+xml;charset=utf-8,") url('./img.png'); +} +.__local__class { + background: ___CSS_LOADER_URL___; + background: ___CSS_LOADER_URL___INDEX___; + background: ___CSS_LOADER_URL___99999___; + background: ___CSS_LOADER_IMPORT___; + background: ___CSS_LOADER_IMPORT___INDEX___; + background: ___CSS_LOADER_IMPORT___99999___; +} +.__local__pure-url { + background: url('img-simple.png'); +} +.__local__root-relative { + background: url('/url/img-simple.png'); +} +.__local__above-below { + background: url('../url/img-simple.png'); +} +.__local__tilde { + background: url('~package/img.png'); +} +.__local__aliases { + background: url('~aliasesImg/img.png'); +} +a { + background: url(./nested/img.png); +} +a { + background: url(nested/img.png); +} +@font-face{ + src: url("//at.alicdn.com/t/font_515771_emcns5054x3whfr.eot"); +} +.__local__class { + background-image: -webkit-image-set(); + background-image: -webkit-image-set(''); + background-image: image-set(); + background-image: image-set(''); + background-image: image-set(""); + background-image: image-set("" 1x); + background-image: image-set(url()); + background-image: image-set(url()); + background-image: image-set(URL()); + background-image: image-set(url('')); + background-image: image-set(url("")); + background-image: image-set(url('') 1x); + background-image: image-set(1x); + background-image: image-set(1x); + background: image-set(calc(1rem + 1px) 1x); + background-image: -webkit-image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set("./img1x.png" 1x); + background-image: image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set("./img img.png" 1x, "./img img.png" 2x); + background-image: image-set("./img1x.png" 1x, "./img2x.png" 2x), image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set("./img1x.png" 1x, "./img2x.png" 2x, "./img3x.png" 600dpi); + background-image: image-set("./img1x.png?foo=bar" 1x); + background-image: image-set("./img1x.png#hash" 1x); + background-image: image-set("./img1x.png?#iefix" 1x); + background-image: -webkit-image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); + background-image: -webkit-image-set(url("./img1x.png") 1x); + background-image: -webkit-image-set(url("./img1x.png") 1x); + background-image: image-set(url(./img1x.png) 1x); + background-image: image-set(url(./img1x.png) 1x); + background-image: image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); + background-image: image-set(url(./img1x.png) 1x, url(./img2x.png) 2x, url(./img3x.png) 600dpi); + background-image: image-set(url("./img img.png") 1x, url("./img img.png") 2x); + background-image: image-set(url("./img1x.png") 1x, "./img2x.png" 2x); +} +.__local__class { + background: url(./img\'img.png); + background: url(./img\'\'\'img.png); + background: url(./img\(img.png); + background: url(./img\)img.png); + background: url(./img\ img.png); + background: url(./img\'\(\)\ img.png); + background-image: image-set(url(./img\'\'\'img.png) 2x, url(./img\'img.png) 3x, url(./img\(img.png) 4x, url(./img\)img.png) 5x, url(./img\ img.png) 6x, url(./img\'\(\)\ img.png) 7x); +} +.__local__class-class-class { + background: url("./img'''img.png"); + background: url("./img'() img.png"); + background: url("./img'img.png"); + background: url("./img(img.png"); + background: url("./img)img.png"); + background: url('./img img.png'); + background: url("./img img.png"); +} +.__local__class.__local__class.__local__class { + background: url('./img\ +(img.png'); + background: url('./img\ +(img.png'); + background: url('./img\ +(img.png'); + background: url('./img\ +\ +\ +\ +(img.png'); +} +.__local__other-test-case { + background: url("./img%27%27%27img.png"); + background: url("./img%27%28%29%20img.png"); + background: url("./img%27img.png"); + background: url("./img%28img.png"); + background: url("./img%29img.png"); + background: url("./img%20img.png"); + background: url(./img%27%27%27img.png); + background: url(./img%27%28%29%20img.png); + background: url(./img%27img.png); + background: url(./img%28img.png); + background: url(./img%29img.png); + background: url(./img%20img.png); +} +.__local__qqq { + background: url('img.png'); +} +.__local__www { + background: url("./img\'\'\'img.png"); + background: url("./img\'\(\)\ img.png"); + background: url("./img\'img.png"); + background: url("./img\(img.png"); + background: url("./img\)img.png"); + background: url("./img\ img.png"); + background: url("./\69\6D\67.png"); + background: url(./\69\6D\67.png); + background: url("./img\27img.png"); + background: url("./img\'\28%29 img.png"); + background: url(./img\'\28%29\ img.png); +} +.__local__class { + background: url('./something.png'); + background: url('./something.png'); + background: url('./something.png?foo=bar'); + background: url('./something.png?foo=bar'); + background: url('./something.png?foo=bar#hash'); + background: url('./something.png?foo=bar#hash'); + background: url('./something.png?foo=bar'); + background: url('./something.png?bar=foo'); + background: url('./something.png?foo=bar#foo'); + background: url('./something.png?bar=foo#bar'); + background: url('./something.png?foo=1&bar=2'); + background: url('./something.png?foo=2&bar=1'); +} +.__local__base { + background: url("data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%0A%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20width%3D%22191px%22%20height%3D%22191px%22%20viewBox%3D%220%200%20191%20191%22%20enable-background%3D%22new%200%200%20191%20191%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M95.5%2C0C42.8%2C0%2C0%2C42.8%2C0%2C95.5S42.8%2C191%2C95.5%2C191S191%2C148.2%2C191%2C95.5S148.2%2C0%2C95.5%2C0z%20M95.5%2C187.6%0A%09c-50.848%2C0-92.1-41.25-92.1-92.1c0-50.848%2C41.252-92.1%2C92.1-92.1c50.85%2C0%2C92.1%2C41.252%2C92.1%2C92.1%0A%09C187.6%2C146.35%2C146.35%2C187.6%2C95.5%2C187.6z%22%2F%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M92.9%2C10v8.6H91v-6.5c-0.1%2C0.1-0.2%2C0.2-0.4%2C0.3c-0.2%2C0.1-0.3%2C0.2-0.4%2C0.2c-0.1%2C0-0.3%2C0.1-0.5%2C0.2%0A%09%09c-0.2%2C0.1-0.3%2C0.1-0.5%2C0.1v-1.6c0.5-0.1%2C0.9-0.3%2C1.4-0.5c0.5-0.2%2C0.8-0.5%2C1.2-0.7h1.1V10z%22%2F%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M97.1%2C17.1h3.602v1.5h-5.6V18c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.6%2C0.5-0.9c0.2-0.3%2C0.5-0.5%2C0.7-0.7%0A%09%09c0.2-0.2%2C0.5-0.4%2C0.7-0.6c0.199-0.2%2C0.5-0.3%2C0.6-0.5c0.102-0.2%2C0.301-0.3%2C0.5-0.5c0.2-0.2%2C0.2-0.3%2C0.301-0.5%0A%09%09c0.101-0.2%2C0.101-0.3%2C0.101-0.5c0-0.4-0.101-0.6-0.3-0.8c-0.2-0.2-0.4-0.3-0.801-0.3c-0.699%2C0-1.399%2C0.3-2.101%2C0.9v-1.6%0A%09%09c0.7-0.5%2C1.5-0.7%2C2.5-0.7c0.399%2C0%2C0.8%2C0.1%2C1.101%2C0.2c0.301%2C0.1%2C0.601%2C0.3%2C0.899%2C0.5c0.3%2C0.2%2C0.399%2C0.5%2C0.5%2C0.8%0A%09%09c0.101%2C0.3%2C0.2%2C0.6%2C0.2%2C1s-0.102%2C0.7-0.2%2C1c-0.099%2C0.3-0.3%2C0.6-0.5%2C0.8c-0.2%2C0.2-0.399%2C0.5-0.7%2C0.7c-0.3%2C0.2-0.5%2C0.4-0.8%2C0.6%0A%09%09c-0.2%2C0.1-0.399%2C0.3-0.5%2C0.4s-0.3%2C0.3-0.5%2C0.4s-0.2%2C0.3-0.3%2C0.4C97.1%2C17%2C97.1%2C17%2C97.1%2C17.1z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M15%2C95.4c0%2C0.7-0.1%2C1.4-0.2%2C2c-0.1%2C0.6-0.4%2C1.1-0.7%2C1.5C13.8%2C99.3%2C13.4%2C99.6%2C12.9%2C99.8s-1%2C0.3-1.5%2C0.3%0A%09%09c-0.7%2C0-1.3-0.1-1.8-0.3v-1.5c0.4%2C0.3%2C1%2C0.4%2C1.6%2C0.4c0.6%2C0%2C1.1-0.2%2C1.5-0.7c0.4-0.5%2C0.5-1.1%2C0.5-1.9l0%2C0%0A%09%09C12.8%2C96.7%2C12.3%2C96.9%2C11.5%2C96.9c-0.3%2C0-0.7-0.102-1-0.2c-0.3-0.101-0.5-0.3-0.8-0.5c-0.3-0.2-0.4-0.5-0.5-0.8%0A%09%09c-0.1-0.3-0.2-0.7-0.2-1c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.7%2C0.6-0.9c0.3-0.2%2C0.6-0.5%2C0.9-0.6c0.3-0.1%2C0.8-0.2%2C1.2-0.2%0A%09%09c0.5%2C0%2C0.9%2C0.1%2C1.2%2C0.3c0.3%2C0.2%2C0.7%2C0.4%2C0.9%2C0.8s0.5%2C0.7%2C0.6%2C1.2S15%2C94.8%2C15%2C95.4z%20M13.1%2C94.4c0-0.2%2C0-0.4-0.1-0.6%0A%09%09c-0.1-0.2-0.1-0.4-0.2-0.5c-0.1-0.1-0.2-0.2-0.4-0.3c-0.2-0.1-0.3-0.1-0.5-0.1c-0.2%2C0-0.3%2C0-0.4%2C0.1s-0.3%2C0.2-0.3%2C0.3%0A%09%09c0%2C0.1-0.2%2C0.3-0.2%2C0.4c0%2C0.1-0.1%2C0.4-0.1%2C0.6c0%2C0.2%2C0%2C0.4%2C0.1%2C0.6c0.1%2C0.2%2C0.1%2C0.3%2C0.2%2C0.4c0.1%2C0.1%2C0.2%2C0.2%2C0.4%2C0.3%0A%09%09c0.2%2C0.1%2C0.3%2C0.1%2C0.5%2C0.1c0.2%2C0%2C0.3%2C0%2C0.4-0.1s0.2-0.2%2C0.3-0.3c0.1-0.1%2C0.2-0.2%2C0.2-0.4C13%2C94.7%2C13.1%2C94.6%2C13.1%2C94.4z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M176%2C99.7V98.1c0.6%2C0.4%2C1.2%2C0.602%2C2%2C0.602c0.5%2C0%2C0.8-0.102%2C1.1-0.301c0.301-0.199%2C0.4-0.5%2C0.4-0.801%0A%09%09c0-0.398-0.2-0.699-0.5-0.898c-0.3-0.2-0.8-0.301-1.3-0.301h-0.802V95h0.701c1.101%2C0%2C1.601-0.4%2C1.601-1.1c0-0.7-0.4-1-1.302-1%0A%09%09c-0.6%2C0-1.1%2C0.2-1.6%2C0.5v-1.5c0.6-0.3%2C1.301-0.4%2C2.1-0.4c0.9%2C0%2C1.5%2C0.2%2C2%2C0.6s0.701%2C0.9%2C0.701%2C1.5c0%2C1.1-0.601%2C1.8-1.701%2C2.1l0%2C0%0A%09%09c0.602%2C0.1%2C1.102%2C0.3%2C1.4%2C0.6s0.5%2C0.8%2C0.5%2C1.3c0%2C0.801-0.3%2C1.4-0.9%2C1.9c-0.6%2C0.5-1.398%2C0.7-2.398%2C0.7%0A%09%09C177.2%2C100.1%2C176.5%2C100%2C176%2C99.7z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M98.5%2C179.102c0%2C0.398-0.1%2C0.799-0.2%2C1.199C98.2%2C180.7%2C98%2C181%2C97.7%2C181.2s-0.601%2C0.5-0.9%2C0.601%0A%09%09c-0.3%2C0.1-0.7%2C0.199-1.2%2C0.199c-0.5%2C0-0.9-0.1-1.3-0.3c-0.4-0.2-0.7-0.399-0.9-0.8c-0.2-0.4-0.5-0.7-0.6-1.2%0A%09%09c-0.1-0.5-0.2-1-0.2-1.601c0-0.699%2C0.1-1.399%2C0.3-2c0.2-0.601%2C0.4-1.101%2C0.8-1.5c0.4-0.399%2C0.7-0.699%2C1.2-1c0.5-0.3%2C1-0.3%2C1.6-0.3%0A%09%09c0.6%2C0%2C1.2%2C0.101%2C1.5%2C0.199v1.5c-0.4-0.199-0.9-0.399-1.4-0.399c-0.3%2C0-0.6%2C0.101-0.8%2C0.2c-0.2%2C0.101-0.5%2C0.3-0.7%2C0.5%0A%09%09c-0.2%2C0.199-0.3%2C0.5-0.4%2C0.8c-0.1%2C0.301-0.2%2C0.7-0.2%2C1.101l0%2C0c0.4-0.601%2C1-0.8%2C1.8-0.8c0.3%2C0%2C0.7%2C0.1%2C0.9%2C0.199%0A%09%09c0.2%2C0.101%2C0.5%2C0.301%2C0.7%2C0.5c0.199%2C0.2%2C0.398%2C0.5%2C0.5%2C0.801C98.5%2C178.2%2C98.5%2C178.7%2C98.5%2C179.102z%20M96.7%2C179.2%0A%09%09c0-0.899-0.4-1.399-1.1-1.399c-0.2%2C0-0.3%2C0-0.5%2C0.1c-0.2%2C0.101-0.3%2C0.201-0.4%2C0.301c-0.1%2C0.101-0.2%2C0.199-0.2%2C0.4%0A%09%09c0%2C0.199-0.1%2C0.299-0.1%2C0.5c0%2C0.199%2C0%2C0.398%2C0.1%2C0.6s0.1%2C0.3%2C0.2%2C0.5c0.1%2C0.199%2C0.2%2C0.199%2C0.4%2C0.3c0.2%2C0.101%2C0.3%2C0.101%2C0.5%2C0.101%0A%09%09c0.2%2C0%2C0.3%2C0%2C0.5-0.101c0.2-0.101%2C0.301-0.199%2C0.301-0.3c0-0.1%2C0.199-0.301%2C0.199-0.399C96.6%2C179.7%2C96.7%2C179.4%2C96.7%2C179.2z%22%2F%3E%0A%3C%2Fg%3E%0A%3Ccircle%20fill%3D%22%23636363%22%20cx%3D%2295%22%20cy%3D%2295%22%20r%3D%227%22%2F%3E%0A%3C%2Fsvg%3E%0A") 50% 50% / 191px no-repeat; +} +.__local__strange { + background: url('%2E/img.png'); +} +.__local__my-background { + background-image: url("/guide/img/banWord/addCoinDialogTitleBg.png"); +} +.__local__class { + background: url('./img.png', 'foo', './img.png', url('./img.png')); + background-image: image-set(url('./img.png', 'foo', './img.png', url('./img.png')) 1x, url("./img2x.png") 2x); +} +.__local__button { + background-image: url('data:image/svg+xml;utf8,'); +} +.__local__qqq { + background: url('!!../../helpers/url-loader.js?esModule=false!~package/img-single.png?ignore-asset-modules'); +} +.__local__class { + background: url("img.png"); +} +.__local__class { + background: url("~img.png"); +} +.__local__class { + background: url("nested/img.png"); +} +.__local__class { + background: url("nested/other.png"); +} +.__local__class { + background: url("package/img.png"); +} +.__local__foo { + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e"); +} +.__local__bar { + background-image: url('data:image/svg+xml;utf8,'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/url.css b/crates/swc_css_modules/tests/fixture/url/url.css new file mode 100644 index 00000000000..09d8478a502 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url.css @@ -0,0 +1,430 @@ +@import "./imported.css"; + +.class { + background: url('./img.png'); +} + +.class { + background: url("./img.png"); +} + +.class { + background: url(./img.png); +} + +.class { + background: url("./img.png#hash"); +} + +.class { + background: url( + "./img.png" + ); +} + +.class { + background: green url( './img.png' ) xyz; +} + +.class { + background: green url( "./img.png" ) xyz; +} + +.class { + background: green url( ./img.png ) xyz; +} + +.class { + background: green url(~package/img.png) url(./other-img.png) xyz; +} + +.class { + background: green url( "./img img.png" ) xyz; +} + +.class { + background: green url( './img img.png' ) xyz; +} + +.class { + background: green url(/img.png) xyz; +} + +.class { + background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz; +} + +.class { + background-image: url("data:image/svg+xml;charset=utf-8,"); +} + +.class { + background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2042%2026%27%20fill%3D%27%2523007aff%27%3E%3Crect%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%271%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2711%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2712%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2722%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2723%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3C%2Fsvg%3E"); +} + +.class { + filter: url('data:image/svg+xml;charset=utf-8,#filter'); +} + +.class { + filter: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%5C%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%5C%22%3E%3Cfilter%20id%3D%5C%22filter%5C%22%3E%3CfeGaussianBlur%20in%3D%5C%22SourceAlpha%5C%22%20stdDeviation%3D%5C%220%5C%22%20%2F%3E%3CfeOffset%20dx%3D%5C%221%5C%22%20dy%3D%5C%222%5C%22%20result%3D%5C%22offsetblur%5C%22%20%2F%3E%3CfeFlood%20flood-color%3D%5C%22rgba(255%2C255%2C255%2C1)%5C%22%20%2F%3E%3CfeComposite%20in2%3D%5C%22offsetblur%5C%22%20operator%3D%5C%22in%5C%22%20%2F%3E%3CfeMerge%3E%3CfeMergeNode%20%2F%3E%3CfeMergeNode%20in%3D%5C%22SourceGraphic%5C%22%20%2F%3E%3C%2FfeMerge%3E%3C%2Ffilter%3E%3C%2Fsvg%3E%23filter'); +} + +.highlight { + filter: url(#highlight); +} + +.highlight { + filter: url('#line-marker'); +} + +@font-face { + src: url(./font.woff) format('woff'), + url('./font.woff2') format('woff2'), + url("./font.eot") format('eot'), + url(~package/font.ttf) format('truetype'), + url("./font with spaces.eot") format("embedded-opentype"), + url('./font.svg#svgFontName') format('svg'), + url('./font.woff2?foo=bar') format('woff2'), + url("./font.eot?#iefix") format('embedded-opentype'), + url("./font with spaces.eot?#iefix") format('embedded-opentype'); +} + +@media (min-width: 500px) { + body { + background: url("./img.png"); + } +} + +a { + content: "do not use url(path)"; +} + +b { + content: 'do not "use" url(path)'; +} + +@keyframes anim { + background: green url('./img.png') xyz; +} + +.a { + background-image: -webkit-image-set(url('./img1x.png') 1x, url('./img2x.png') 2x) +} + +.a { + background-image: image-set(url('./img1x.png') 1x, url('./img2x.png') 2x) +} + +.class { + background: green url() xyz; +} + +.class { + background: green url('') xyz; +} + +.class { + background: green url("") xyz; +} + +.class { + background: green url(' ') xyz; +} + +.class { + background: green url( + ) xyz; +} + +.class { + background: green url(https://raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz; +} + +.class { + background: green url(//raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz; +} + +.class { + background: url("./img.png?foo"); +} + +.class { + background: url("./img.png?foo=bar"); +} + +.class { + background: url("./img.png?foo=bar#hash"); +} + +.class { + background: url("./img.png?foo=bar#hash"); +} + +.class { + background: url("./img.png?"); +} + +.class { + background-image: url('./img.png') url("data:image/svg+xml;charset=utf-8,") url('./img.png'); +} + +.class { + background: ___CSS_LOADER_URL___; + background: ___CSS_LOADER_URL___INDEX___; + background: ___CSS_LOADER_URL___99999___; + background: ___CSS_LOADER_IMPORT___; + background: ___CSS_LOADER_IMPORT___INDEX___; + background: ___CSS_LOADER_IMPORT___99999___; +} + +.pure-url { + background: url('img-simple.png'); +} + +.root-relative { + background: url('/url/img-simple.png'); +} + +.above-below { + background: url('../url/img-simple.png'); +} + +.tilde { + background: url('~package/img.png'); +} + +.aliases { + background: url('~aliasesImg/img.png') ; +} + +a { + background: url(./nested/img.png); +} + +a { + background: url(nested/img.png); +} + +@font-face { + src: url("//at.alicdn.com/t/font_515771_emcns5054x3whfr.eot"); +} + +.class { + /* Broken */ + background-image: -webkit-image-set(); + background-image: -webkit-image-set(''); + background-image: image-set(); + background-image: image-set(''); + background-image: image-set(""); + background-image: image-set("" 1x); + background-image: image-set(url()); + background-image: image-set( + url() + ); + background-image: image-set(URL()); + background-image: image-set(url('')); + background-image: image-set(url("")); + background-image: image-set(url('') 1x); + background-image: image-set(1x); + background-image: image-set( + 1x + ); + background: image-set(calc(1rem + 1px) 1x); + + /* Strings */ + background-image: -webkit-image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set("./img1x.png" 1x); + background-image: image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set("./img img.png" 1x, "./img img.png" 2x); + background-image: image-set("./img1x.png" 1x, "./img2x.png" 2x), + image-set("./img1x.png" 1x, "./img2x.png" 2x); + background-image: image-set( + "./img1x.png" 1x, + "./img2x.png" 2x, + "./img3x.png" 600dpi + ); + background-image: image-set("./img1x.png?foo=bar" 1x); + background-image: image-set("./img1x.png#hash" 1x); + background-image: image-set("./img1x.png?#iefix" 1x); + + /* With `url` function */ + background-image: -webkit-image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); + background-image: -webkit-image-set(url("./img1x.png") 1x); + background-image: -webkit-image-set( + url("./img1x.png") 1x + ); + background-image: image-set(url(./img1x.png) 1x); + background-image: image-set( + url(./img1x.png) 1x + ); + background-image: image-set(url("./img1x.png") 1x, url("./img2x.png") 2x); + background-image: image-set( + url(./img1x.png) 1x, + url(./img2x.png) 2x, + url(./img3x.png) 600dpi + ); + background-image: image-set(url("./img img.png") 1x, url("./img img.png") 2x); + + background-image: image-set(url("./img1x.png") 1x, "./img2x.png" 2x); +} + +.class { + /* Not allowed on windows */ + /* background: url(./img\"img.png); */ + background: url(./img\'img.png); + background: url(./img\'\'\'img.png); + background: url(./img\(img.png); + background: url(./img\)img.png); + background: url(./img\ img.png); + background: url(./img\'\(\)\ img.png); + + background-image: image-set( + /* Not allowed on windows */ + /* url(./img\"img.png) 1x, */ + url(./img\'\'\'img.png) 2x, + url(./img\'img.png) 3x, + url(./img\(img.png) 4x, + url(./img\)img.png) 5x, + url(./img\ img.png) 6x, + url(./img\'\(\)\ img.png) 7x + ); +} + +.class-class-class { + background: url("./img'''img.png"); + background: url("./img'() img.png"); + background: url("./img'img.png"); + background: url("./img(img.png"); + background: url("./img)img.png"); + background: url('./img img.png'); + background: url("./img img.png"); +} + +/* Comment */ + +.class.class.class { + background: url('./img\ +(img.png'); + background: url('./img\ +(img.png'); + background: url('./img\ +(img.png'); + background: url('./img\ +\ +\ +\ +(img.png'); +} + +.other-test-case { + background: url("./img%27%27%27img.png"); + background: url("./img%27%28%29%20img.png"); + background: url("./img%27img.png"); + background: url("./img%28img.png"); + background: url("./img%29img.png"); + background: url("./img%20img.png"); + background: url(./img%27%27%27img.png); + background: url(./img%27%28%29%20img.png); + background: url(./img%27img.png); + background: url(./img%28img.png); + background: url(./img%29img.png); + background: url(./img%20img.png); +} + +.qqq { + background: url('img.png'); +} + +.www { + background: url("./img\'\'\'img.png"); + background: url("./img\'\(\)\ img.png"); + background: url("./img\'img.png"); + background: url("./img\(img.png"); + background: url("./img\)img.png"); + background: url("./img\ img.png"); + background: url("./\69\6D\67.png"); + background: url(./\69\6D\67.png); + background: url("./img\27img.png"); + background: url("./img\'\28%29 img.png"); + background: url(./img\'\28%29\ img.png); +} + +.class { + /* Should be one import */ + background: url('./something.png'); + background: url('./something.png'); + + background: url('./something.png?foo=bar'); + background: url('./something.png?foo=bar'); + + background: url('./something.png?foo=bar#hash'); + background: url('./something.png?foo=bar#hash'); + + /* Should be two imports */ + background: url('./something.png?foo=bar'); + background: url('./something.png?bar=foo'); + + background: url('./something.png?foo=bar#foo'); + background: url('./something.png?bar=foo#bar'); + + background: url('./something.png?foo=1&bar=2'); + background: url('./something.png?foo=2&bar=1'); +} + +.base { + background: url("data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%0A%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20width%3D%22191px%22%20height%3D%22191px%22%20viewBox%3D%220%200%20191%20191%22%20enable-background%3D%22new%200%200%20191%20191%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M95.5%2C0C42.8%2C0%2C0%2C42.8%2C0%2C95.5S42.8%2C191%2C95.5%2C191S191%2C148.2%2C191%2C95.5S148.2%2C0%2C95.5%2C0z%20M95.5%2C187.6%0A%09c-50.848%2C0-92.1-41.25-92.1-92.1c0-50.848%2C41.252-92.1%2C92.1-92.1c50.85%2C0%2C92.1%2C41.252%2C92.1%2C92.1%0A%09C187.6%2C146.35%2C146.35%2C187.6%2C95.5%2C187.6z%22%2F%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M92.9%2C10v8.6H91v-6.5c-0.1%2C0.1-0.2%2C0.2-0.4%2C0.3c-0.2%2C0.1-0.3%2C0.2-0.4%2C0.2c-0.1%2C0-0.3%2C0.1-0.5%2C0.2%0A%09%09c-0.2%2C0.1-0.3%2C0.1-0.5%2C0.1v-1.6c0.5-0.1%2C0.9-0.3%2C1.4-0.5c0.5-0.2%2C0.8-0.5%2C1.2-0.7h1.1V10z%22%2F%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M97.1%2C17.1h3.602v1.5h-5.6V18c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.6%2C0.5-0.9c0.2-0.3%2C0.5-0.5%2C0.7-0.7%0A%09%09c0.2-0.2%2C0.5-0.4%2C0.7-0.6c0.199-0.2%2C0.5-0.3%2C0.6-0.5c0.102-0.2%2C0.301-0.3%2C0.5-0.5c0.2-0.2%2C0.2-0.3%2C0.301-0.5%0A%09%09c0.101-0.2%2C0.101-0.3%2C0.101-0.5c0-0.4-0.101-0.6-0.3-0.8c-0.2-0.2-0.4-0.3-0.801-0.3c-0.699%2C0-1.399%2C0.3-2.101%2C0.9v-1.6%0A%09%09c0.7-0.5%2C1.5-0.7%2C2.5-0.7c0.399%2C0%2C0.8%2C0.1%2C1.101%2C0.2c0.301%2C0.1%2C0.601%2C0.3%2C0.899%2C0.5c0.3%2C0.2%2C0.399%2C0.5%2C0.5%2C0.8%0A%09%09c0.101%2C0.3%2C0.2%2C0.6%2C0.2%2C1s-0.102%2C0.7-0.2%2C1c-0.099%2C0.3-0.3%2C0.6-0.5%2C0.8c-0.2%2C0.2-0.399%2C0.5-0.7%2C0.7c-0.3%2C0.2-0.5%2C0.4-0.8%2C0.6%0A%09%09c-0.2%2C0.1-0.399%2C0.3-0.5%2C0.4s-0.3%2C0.3-0.5%2C0.4s-0.2%2C0.3-0.3%2C0.4C97.1%2C17%2C97.1%2C17%2C97.1%2C17.1z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M15%2C95.4c0%2C0.7-0.1%2C1.4-0.2%2C2c-0.1%2C0.6-0.4%2C1.1-0.7%2C1.5C13.8%2C99.3%2C13.4%2C99.6%2C12.9%2C99.8s-1%2C0.3-1.5%2C0.3%0A%09%09c-0.7%2C0-1.3-0.1-1.8-0.3v-1.5c0.4%2C0.3%2C1%2C0.4%2C1.6%2C0.4c0.6%2C0%2C1.1-0.2%2C1.5-0.7c0.4-0.5%2C0.5-1.1%2C0.5-1.9l0%2C0%0A%09%09C12.8%2C96.7%2C12.3%2C96.9%2C11.5%2C96.9c-0.3%2C0-0.7-0.102-1-0.2c-0.3-0.101-0.5-0.3-0.8-0.5c-0.3-0.2-0.4-0.5-0.5-0.8%0A%09%09c-0.1-0.3-0.2-0.7-0.2-1c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.7%2C0.6-0.9c0.3-0.2%2C0.6-0.5%2C0.9-0.6c0.3-0.1%2C0.8-0.2%2C1.2-0.2%0A%09%09c0.5%2C0%2C0.9%2C0.1%2C1.2%2C0.3c0.3%2C0.2%2C0.7%2C0.4%2C0.9%2C0.8s0.5%2C0.7%2C0.6%2C1.2S15%2C94.8%2C15%2C95.4z%20M13.1%2C94.4c0-0.2%2C0-0.4-0.1-0.6%0A%09%09c-0.1-0.2-0.1-0.4-0.2-0.5c-0.1-0.1-0.2-0.2-0.4-0.3c-0.2-0.1-0.3-0.1-0.5-0.1c-0.2%2C0-0.3%2C0-0.4%2C0.1s-0.3%2C0.2-0.3%2C0.3%0A%09%09c0%2C0.1-0.2%2C0.3-0.2%2C0.4c0%2C0.1-0.1%2C0.4-0.1%2C0.6c0%2C0.2%2C0%2C0.4%2C0.1%2C0.6c0.1%2C0.2%2C0.1%2C0.3%2C0.2%2C0.4c0.1%2C0.1%2C0.2%2C0.2%2C0.4%2C0.3%0A%09%09c0.2%2C0.1%2C0.3%2C0.1%2C0.5%2C0.1c0.2%2C0%2C0.3%2C0%2C0.4-0.1s0.2-0.2%2C0.3-0.3c0.1-0.1%2C0.2-0.2%2C0.2-0.4C13%2C94.7%2C13.1%2C94.6%2C13.1%2C94.4z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M176%2C99.7V98.1c0.6%2C0.4%2C1.2%2C0.602%2C2%2C0.602c0.5%2C0%2C0.8-0.102%2C1.1-0.301c0.301-0.199%2C0.4-0.5%2C0.4-0.801%0A%09%09c0-0.398-0.2-0.699-0.5-0.898c-0.3-0.2-0.8-0.301-1.3-0.301h-0.802V95h0.701c1.101%2C0%2C1.601-0.4%2C1.601-1.1c0-0.7-0.4-1-1.302-1%0A%09%09c-0.6%2C0-1.1%2C0.2-1.6%2C0.5v-1.5c0.6-0.3%2C1.301-0.4%2C2.1-0.4c0.9%2C0%2C1.5%2C0.2%2C2%2C0.6s0.701%2C0.9%2C0.701%2C1.5c0%2C1.1-0.601%2C1.8-1.701%2C2.1l0%2C0%0A%09%09c0.602%2C0.1%2C1.102%2C0.3%2C1.4%2C0.6s0.5%2C0.8%2C0.5%2C1.3c0%2C0.801-0.3%2C1.4-0.9%2C1.9c-0.6%2C0.5-1.398%2C0.7-2.398%2C0.7%0A%09%09C177.2%2C100.1%2C176.5%2C100%2C176%2C99.7z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M98.5%2C179.102c0%2C0.398-0.1%2C0.799-0.2%2C1.199C98.2%2C180.7%2C98%2C181%2C97.7%2C181.2s-0.601%2C0.5-0.9%2C0.601%0A%09%09c-0.3%2C0.1-0.7%2C0.199-1.2%2C0.199c-0.5%2C0-0.9-0.1-1.3-0.3c-0.4-0.2-0.7-0.399-0.9-0.8c-0.2-0.4-0.5-0.7-0.6-1.2%0A%09%09c-0.1-0.5-0.2-1-0.2-1.601c0-0.699%2C0.1-1.399%2C0.3-2c0.2-0.601%2C0.4-1.101%2C0.8-1.5c0.4-0.399%2C0.7-0.699%2C1.2-1c0.5-0.3%2C1-0.3%2C1.6-0.3%0A%09%09c0.6%2C0%2C1.2%2C0.101%2C1.5%2C0.199v1.5c-0.4-0.199-0.9-0.399-1.4-0.399c-0.3%2C0-0.6%2C0.101-0.8%2C0.2c-0.2%2C0.101-0.5%2C0.3-0.7%2C0.5%0A%09%09c-0.2%2C0.199-0.3%2C0.5-0.4%2C0.8c-0.1%2C0.301-0.2%2C0.7-0.2%2C1.101l0%2C0c0.4-0.601%2C1-0.8%2C1.8-0.8c0.3%2C0%2C0.7%2C0.1%2C0.9%2C0.199%0A%09%09c0.2%2C0.101%2C0.5%2C0.301%2C0.7%2C0.5c0.199%2C0.2%2C0.398%2C0.5%2C0.5%2C0.801C98.5%2C178.2%2C98.5%2C178.7%2C98.5%2C179.102z%20M96.7%2C179.2%0A%09%09c0-0.899-0.4-1.399-1.1-1.399c-0.2%2C0-0.3%2C0-0.5%2C0.1c-0.2%2C0.101-0.3%2C0.201-0.4%2C0.301c-0.1%2C0.101-0.2%2C0.199-0.2%2C0.4%0A%09%09c0%2C0.199-0.1%2C0.299-0.1%2C0.5c0%2C0.199%2C0%2C0.398%2C0.1%2C0.6s0.1%2C0.3%2C0.2%2C0.5c0.1%2C0.199%2C0.2%2C0.199%2C0.4%2C0.3c0.2%2C0.101%2C0.3%2C0.101%2C0.5%2C0.101%0A%09%09c0.2%2C0%2C0.3%2C0%2C0.5-0.101c0.2-0.101%2C0.301-0.199%2C0.301-0.3c0-0.1%2C0.199-0.301%2C0.199-0.399C96.6%2C179.7%2C96.7%2C179.4%2C96.7%2C179.2z%22%2F%3E%0A%3C%2Fg%3E%0A%3Ccircle%20fill%3D%22%23636363%22%20cx%3D%2295%22%20cy%3D%2295%22%20r%3D%227%22%2F%3E%0A%3C%2Fsvg%3E%0A") 50% 50%/191px no-repeat; +} + +.strange { + background: url('%2E/img.png'); +} + +.my-background { + background-image: url("/guide/img/banWord/addCoinDialogTitleBg.png"); +} + +.class { + background: url('./img.png', 'foo', './img.png', url('./img.png')); + background-image: image-set(url('./img.png', 'foo', './img.png', url('./img.png')) 1x, url("./img2x.png") 2x); +} + +.button { + background-image: url('data:image/svg+xml;utf8,'); +} + +/* We need to use `resourceQuery: /inline/` */ +/* Hard to test on webpack v4 */ +.qqq { + background: url('!!../../helpers/url-loader.js?esModule=false!~package/img-single.png?ignore-asset-modules') +} + +.class { + background: url("img.png"); +} + +.class { + background: url("~img.png"); +} + +/** Prefer relative **/ +.class { + background: url("nested/img.png"); +} + +/** Prefer from modules **/ +.class { + background: url("nested/other.png"); +} + +.class { + background: url("package/img.png"); +} + +.foo { + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e"); +} + +.bar { + background-image: url('data:image/svg+xml;utf8,'); +} diff --git a/crates/swc_css_modules/tests/fixture/url/url.imports.json b/crates/swc_css_modules/tests/fixture/url/url.imports.json new file mode 100644 index 00000000000..f2d9bde50c3 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url.imports.json @@ -0,0 +1,3 @@ +[ + "./imported.css" +] diff --git a/crates/swc_css_modules/tests/fixture/url/url.transform.json b/crates/swc_css_modules/tests/fixture/url/url.transform.json new file mode 100644 index 00000000000..0856c180f98 --- /dev/null +++ b/crates/swc_css_modules/tests/fixture/url/url.transform.json @@ -0,0 +1,116 @@ +{ + "a": [ + { + "type": "local", + "name": "__local__a" + } + ], + "class": [ + { + "type": "local", + "name": "__local__class" + } + ], + "qqq": [ + { + "type": "local", + "name": "__local__qqq" + } + ], + "www": [ + { + "type": "local", + "name": "__local__www" + } + ], + "above-below": [ + { + "type": "local", + "name": "__local__above-below" + } + ], + "foo": [ + { + "type": "local", + "name": "__local__foo" + } + ], + "bar": [ + { + "type": "local", + "name": "__local__bar" + } + ], + "class-class-class": [ + { + "type": "local", + "name": "__local__class-class-class" + } + ], + "root-relative": [ + { + "type": "local", + "name": "__local__root-relative" + } + ], + "my-background": [ + { + "type": "local", + "name": "__local__my-background" + } + ], + "aliases": [ + { + "type": "local", + "name": "__local__aliases" + } + ], + "strange": [ + { + "type": "local", + "name": "__local__strange" + } + ], + "other-test-case": [ + { + "type": "local", + "name": "__local__other-test-case" + } + ], + "button": [ + { + "type": "local", + "name": "__local__button" + } + ], + "tilde": [ + { + "type": "local", + "name": "__local__tilde" + } + ], + "base": [ + { + "type": "local", + "name": "__local__base" + } + ], + "anim": [ + { + "type": "local", + "name": "__local__anim" + } + ], + "pure-url": [ + { + "type": "local", + "name": "__local__pure-url" + } + ], + "highlight": [ + { + "type": "local", + "name": "__local__highlight" + } + ] +} diff --git a/crates/testing/Cargo.toml b/crates/testing/Cargo.toml index b6f41050d12..9a5cfc64623 100644 --- a/crates/testing/Cargo.toml +++ b/crates/testing/Cargo.toml @@ -1,12 +1,12 @@ [package] -authors = ["강동윤 "] -description = "Testing utilities for the swc project." +authors = ["강동윤 "] +description = "Testing utilities for the swc project." documentation = "https://rustdoc.swc.rs/testing/" -edition = "2021" -license = "Apache-2.0" -name = "testing" -repository = "https://github.com/swc-project/swc.git" -version = "0.31.4" +edition = "2021" +license = "Apache-2.0" +name = "testing" +repository = "https://github.com/swc-project/swc.git" +version = "0.31.4" [lib] bench = false @@ -18,10 +18,10 @@ once_cell = "1.10.0" pretty_assertions = "1.1" regex = "1" serde_json = "1.0.71" -swc_common = { version = "0.29.4", path = "../swc_common", features = [ +swc_common = {version = "0.29.4", path = "../swc_common", features = [ "tty-emitter", -] } -swc_error_reporters = { version = "0.13.4", path = "../swc_error_reporters" } -testing_macros = { version = "0.2.0", path = "../testing_macros" } +]} +swc_error_reporters = {version = "0.13.4", path = "../swc_error_reporters"} +testing_macros = {version = "0.2.0", path = "../testing_macros"} tracing = "0.1.32" -tracing-subscriber = { version = "0.3.9", features = ["env-filter"] } +tracing-subscriber = {version = "0.3.9", features = ["env-filter"]} diff --git a/crates/testing/src/lib.rs b/crates/testing/src/lib.rs index dc9aba9bc02..467f1181d50 100644 --- a/crates/testing/src/lib.rs +++ b/crates/testing/src/lib.rs @@ -15,7 +15,7 @@ pub use pretty_assertions::{assert_eq, assert_ne}; use regex::Regex; use swc_common::{ collections::AHashMap, - errors::{Diagnostic, Handler}, + errors::{Diagnostic, Handler, HANDLER}, sync::Lrc, FilePathMapping, SourceMap, }; @@ -90,7 +90,9 @@ where let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let (handler, errors) = self::string_errors::new_handler(cm.clone(), treat_err_as_bug); - let result = swc_common::GLOBALS.set(&swc_common::Globals::new(), || op(cm, &handler)); + let result = swc_common::GLOBALS.set(&swc_common::Globals::new(), || { + HANDLER.set(&handler, || op(cm, &handler)) + }); match result { Ok(res) => Ok(res),