diff --git a/Cargo.lock b/Cargo.lock index b942c96db..44558817a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1240,7 +1240,7 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.68.18" +version = "0.68.19" dependencies = [ "convert_case", "handlebars", diff --git a/packages/emotion/transform/src/lib.rs b/packages/emotion/transform/src/lib.rs index 94dae6b8e..50bf65a1c 100644 --- a/packages/emotion/transform/src/lib.rs +++ b/packages/emotion/transform/src/lib.rs @@ -219,8 +219,8 @@ impl EmotionTransformer { .and_then(|s| { s.rfind('\\') .map(|pos| &s[pos + 1..]) // if backslashes are found, take the last part - .or(Some(s)) // otherwise use the whole path - }) + .or(Some(s)) // otherwise use the whole path + }) .map(|s| s.to_owned()), cm, comments, diff --git a/packages/transform-imports/CHANGELOG.md b/packages/transform-imports/CHANGELOG.md index 539402222..93a2886cc 100644 --- a/packages/transform-imports/CHANGELOG.md +++ b/packages/transform-imports/CHANGELOG.md @@ -1,5 +1,11 @@ # @swc/plugin-transform-imports +## 2.0.9 + +### Patch Changes + +- f39705a: Disable default/namespace import handling by default + ## 2.0.8 ### Patch Changes diff --git a/packages/transform-imports/README.md b/packages/transform-imports/README.md index 12ae78314..2e55d0001 100644 --- a/packages/transform-imports/README.md +++ b/packages/transform-imports/README.md @@ -18,6 +18,12 @@ # @swc/plugin-transform-imports +## 2.0.9 + +### Patch Changes + +- f39705a: Disable default/namespace import handling by default + ## 2.0.8 ### Patch Changes diff --git a/packages/transform-imports/package.json b/packages/transform-imports/package.json index fdbf7a6e2..d20296246 100644 --- a/packages/transform-imports/package.json +++ b/packages/transform-imports/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-transform-imports", - "version": "2.0.8", + "version": "2.0.9", "description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-transform-imports", "main": "swc_plugin_transform_imports.wasm", "scripts": { diff --git a/packages/transform-imports/transform/Cargo.toml b/packages/transform-imports/transform/Cargo.toml index 051d898b9..006c0ae32 100644 --- a/packages/transform-imports/transform/Cargo.toml +++ b/packages/transform-imports/transform/Cargo.toml @@ -11,7 +11,7 @@ homepage = { workspace = true } license = { workspace = true } repository = { workspace = true } rust-version = { workspace = true } -version = "0.68.18" +version = "0.68.19" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/transform-imports/transform/src/lib.rs b/packages/transform-imports/transform/src/lib.rs index a0290b121..4c861b504 100644 --- a/packages/transform-imports/transform/src/lib.rs +++ b/packages/transform-imports/transform/src/lib.rs @@ -26,6 +26,10 @@ pub struct PackageConfig { #[serde(default)] pub prevent_full_import: bool, #[serde(default)] + pub handle_default_import: bool, + #[serde(default)] + pub handle_namespace_import: bool, + #[serde(default)] pub skip_default_conversion: bool, } @@ -185,7 +189,7 @@ impl<'a> Rewriter<'a> { with: None, }); } - ExportSpecifier::Namespace(ns_spec) if !self.config.prevent_full_import => { + ExportSpecifier::Namespace(ns_spec) if self.config.handle_namespace_import => { let name_str = match &ns_spec.name { ModuleExportName::Ident(x) => x.as_ref(), ModuleExportName::Str(x) => x.value.as_ref(), @@ -253,7 +257,7 @@ impl<'a> Rewriter<'a> { phase: Default::default(), }); } - ImportSpecifier::Namespace(ns_spec) if !self.config.prevent_full_import => { + ImportSpecifier::Namespace(ns_spec) if self.config.handle_namespace_import => { let name_str = ns_spec.local.as_ref(); let new_path = self.new_path(Some(name_str)); let specifier = ImportSpecifier::Namespace(ns_spec.clone()); @@ -266,7 +270,7 @@ impl<'a> Rewriter<'a> { phase: Default::default(), }); } - ImportSpecifier::Default(def_spec) if !self.config.prevent_full_import => { + ImportSpecifier::Default(def_spec) if self.config.handle_default_import => { let name_str = def_spec.local.as_ref(); let new_path = self.new_path(Some(name_str)); let specifier = ImportSpecifier::Default(def_spec.clone()); diff --git a/packages/transform-imports/transform/tests/fixture.rs b/packages/transform-imports/transform/tests/fixture.rs index 2c8f529fa..d3c5a995e 100644 --- a/packages/transform-imports/transform/tests/fixture.rs +++ b/packages/transform-imports/transform/tests/fixture.rs @@ -26,6 +26,8 @@ fn modularize_imports_fixture(input: PathBuf) { transform: "react-bootstrap/lib/{{member}}".into(), prevent_full_import: false, skip_default_conversion: false, + handle_default_import: true, + handle_namespace_import: true, }, ), ( @@ -34,6 +36,8 @@ fn modularize_imports_fixture(input: PathBuf) { transform: "my-library/{{ matches.[1] }}/{{member}}".into(), prevent_full_import: false, skip_default_conversion: false, + handle_default_import: true, + handle_namespace_import: true, }, ), ( @@ -42,6 +46,8 @@ fn modularize_imports_fixture(input: PathBuf) { transform: "my-library-2/{{ camelCase member }}".into(), prevent_full_import: false, skip_default_conversion: true, + handle_default_import: true, + handle_namespace_import: true, }, ), ( @@ -50,6 +56,8 @@ fn modularize_imports_fixture(input: PathBuf) { transform: "my-library-3/{{ kebabCase member }}".into(), prevent_full_import: false, skip_default_conversion: true, + handle_default_import: true, + handle_namespace_import: true, }, ), ( @@ -76,6 +84,8 @@ fn modularize_imports_fixture(input: PathBuf) { .into(), prevent_full_import: false, skip_default_conversion: true, + handle_default_import: true, + handle_namespace_import: true, }, ), ( @@ -84,6 +94,8 @@ fn modularize_imports_fixture(input: PathBuf) { transform: "transformed-{{matches.[1]}}".into(), prevent_full_import: false, skip_default_conversion: true, + handle_default_import: true, + handle_namespace_import: true, }, ), ]