Skip to content

Commit 319fbe9

Browse files
committed
Add alias
1 parent a79609b commit 319fbe9

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"packages/bun-plugin/package.json":"Patch","packages/components/package.json":"Patch","packages/next-plugin/package.json":"Patch","packages/react/package.json":"Patch","bindings/devup-ui-wasm/package.json":"Patch","packages/plugin-utils/package.json":"Patch","packages/vite-plugin/package.json":"Patch","packages/webpack-plugin/package.json":"Patch","packages/rsbuild-plugin/package.json":"Patch"},"note":"Add importAlias option","date":"2026-01-14T11:03:40.943886300Z"}

libs/extractor/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12897,6 +12897,37 @@ const Button = myStyled.button({ bg: 'green', p: 2 })
1289712897
));
1289812898
}
1289912899

12900+
#[test]
12901+
#[serial]
12902+
fn test_import_alias_custom_named_export() {
12903+
// Test @emotion/styled default export → custom named export (emotionStyled, not styled)
12904+
// This tests when user configures alias to map to a non-standard named export
12905+
reset_class_map();
12906+
reset_file_map();
12907+
let mut aliases = HashMap::new();
12908+
aliases.insert(
12909+
"@emotion/styled".to_string(),
12910+
ImportAlias::DefaultToNamed("styled".to_string()),
12911+
);
12912+
12913+
assert_debug_snapshot!(ToBTreeSet::from(
12914+
extract(
12915+
"test.tsx",
12916+
r#"import emotionStyled from '@emotion/styled'
12917+
const Button = emotionStyled.button({ bg: 'purple', p: 3 })
12918+
"#,
12919+
ExtractOption {
12920+
package: "@devup-ui/react".to_string(),
12921+
css_dir: "@devup-ui/react".to_string(),
12922+
single_css: true,
12923+
import_main_css: false,
12924+
import_aliases: aliases,
12925+
},
12926+
)
12927+
.unwrap()
12928+
));
12929+
}
12930+
1290012931
#[test]
1290112932
#[serial]
1290212933
fn test_import_alias_multiple_aliases() {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import emotionStyled from '@emotion/styled'\nconst Button = emotionStyled.button({ bg: 'purple', p: 3 })\n\"#,\nExtractOption\n{\n package: \"@devup-ui/react\".to_string(), css_dir:\n \"@devup-ui/react\".to_string(), single_css: true, import_main_css: false,\n import_aliases: aliases,\n},).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "purple",
11+
level: 0,
12+
selector: None,
13+
style_order: None,
14+
layer: None,
15+
},
16+
),
17+
Static(
18+
ExtractStaticStyle {
19+
property: "padding",
20+
value: "12px",
21+
level: 0,
22+
selector: None,
23+
style_order: None,
24+
layer: None,
25+
},
26+
),
27+
},
28+
code: "import \"@devup-ui/react/devup-ui.css\";\nconst Button = ({ style, className, ...rest }) => <button {...rest} className={[\"a b\", className].filter(Boolean).join(\" \")} style={style} />;\n",
29+
}

0 commit comments

Comments
 (0)