diff --git a/Cargo.lock b/Cargo.lock index 8f213d648..7ca339a5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,7 +1172,7 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.59.0" +version = "0.60.0" dependencies = [ "convert_case", "handlebars", @@ -1716,7 +1716,7 @@ dependencies = [ [[package]] name = "react_remove_properties" -version = "0.15.0" +version = "0.16.0" dependencies = [ "serde", "swc_atoms", @@ -1791,7 +1791,7 @@ checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" [[package]] name = "remove_console" -version = "0.16.0" +version = "0.17.0" dependencies = [ "serde", "swc_atoms", @@ -2167,7 +2167,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.87.0" +version = "0.88.0" dependencies = [ "Inflector", "once_cell", @@ -2188,7 +2188,7 @@ dependencies = [ [[package]] name = "styled_jsx" -version = "0.64.0" +version = "0.65.0" dependencies = [ "easy-error", "lightningcss", @@ -2329,7 +2329,7 @@ dependencies = [ [[package]] name = "swc_constify" -version = "0.27.0" +version = "0.28.0" dependencies = [ "once_cell", "rustc-hash", @@ -2794,7 +2794,7 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.63.0" +version = "0.64.0" dependencies = [ "base64", "byteorder", @@ -2870,7 +2870,7 @@ dependencies = [ [[package]] name = "swc_magic" -version = "0.10.0" +version = "0.11.0" dependencies = [ "serde", "swc_atoms", @@ -3107,7 +3107,7 @@ dependencies = [ [[package]] name = "swc_relay" -version = "0.35.0" +version = "0.36.0" dependencies = [ "once_cell", "regex", diff --git a/packages/constify/package.json b/packages/constify/package.json index 8693d9ba1..79e8871ce 100644 --- a/packages/constify/package.json +++ b/packages/constify/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-constify", - "version": "0.1.32", + "version": "0.1.33", "description": "SWC plugin for optimization", "main": "swc_plugin_constify.wasm", "scripts": { diff --git a/packages/constify/transform/Cargo.toml b/packages/constify/transform/Cargo.toml index cc41d1746..932d169c4 100644 --- a/packages/constify/transform/Cargo.toml +++ b/packages/constify/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "swc_constify" repository = "https://github.com/swc-project/plugins.git" -version = "0.27.0" +version = "0.28.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/emotion/package.json b/packages/emotion/package.json index bcd0a635d..37412e554 100644 --- a/packages/emotion/package.json +++ b/packages/emotion/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-emotion", - "version": "2.5.102", + "version": "2.5.103", "description": "SWC plugin for emotion css-in-js library", "main": "swc_plugin_emotion.wasm", "scripts": { diff --git a/packages/emotion/transform/Cargo.toml b/packages/emotion/transform/Cargo.toml index b576eee87..611ff2cdf 100644 --- a/packages/emotion/transform/Cargo.toml +++ b/packages/emotion/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "swc_emotion" repository = "https://github.com/swc-project/plugins.git" -version = "0.63.0" +version = "0.64.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/jest/package.json b/packages/jest/package.json index 3ec239f68..ce095162b 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-jest", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for jest", "main": "swc_plugin_jest.wasm", "scripts": { diff --git a/packages/loadable-components/package.json b/packages/loadable-components/package.json index 657bf990f..05345ad0f 100644 --- a/packages/loadable-components/package.json +++ b/packages/loadable-components/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-loadable-components", - "version": "0.3.102", + "version": "0.3.103", "description": "SWC plugin for `@loadable/components`", "main": "swc_plugin_loadable_components.wasm", "scripts": { diff --git a/packages/noop/package.json b/packages/noop/package.json index d12b1c421..ec118dfba 100644 --- a/packages/noop/package.json +++ b/packages/noop/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-noop", - "version": "1.5.100", + "version": "1.5.101", "description": "Noop SWC plugin, for debugging", "main": "swc_plugin_noop.wasm", "scripts": { diff --git a/packages/react-remove-properties/package.json b/packages/react-remove-properties/package.json index cd15c62bd..272b97bc3 100644 --- a/packages/react-remove-properties/package.json +++ b/packages/react-remove-properties/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-react-remove-properties", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-react-remove-properties", "main": "swc_plugin_react_remove_properties.wasm", "scripts": { diff --git a/packages/react-remove-properties/transform/Cargo.toml b/packages/react-remove-properties/transform/Cargo.toml index 22ee9d580..87c618c53 100644 --- a/packages/react-remove-properties/transform/Cargo.toml +++ b/packages/react-remove-properties/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "react_remove_properties" repository = "https://github.com/swc-project/plugins.git" -version = "0.15.0" +version = "0.16.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/relay/package.json b/packages/relay/package.json index 8d1e968d9..b654c03d0 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-relay", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for relay", "main": "swc_plugin_relay.wasm", "types": "./types.d.ts", diff --git a/packages/relay/transform/Cargo.toml b/packages/relay/transform/Cargo.toml index 6ace6caef..d14ddb293 100644 --- a/packages/relay/transform/Cargo.toml +++ b/packages/relay/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "swc_relay" repository = "https://github.com/swc-project/plugins.git" -version = "0.35.0" +version = "0.36.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/remove-console/package.json b/packages/remove-console/package.json index cb4c28686..a3677d9a3 100644 --- a/packages/remove-console/package.json +++ b/packages/remove-console/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-remove-console", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-remove-console", "main": "swc_plugin_remove_console.wasm", "scripts": { diff --git a/packages/remove-console/transform/Cargo.toml b/packages/remove-console/transform/Cargo.toml index 9fa43f686..fc0dfe118 100644 --- a/packages/remove-console/transform/Cargo.toml +++ b/packages/remove-console/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "remove_console" repository = "https://github.com/swc-project/plugins.git" -version = "0.16.0" +version = "0.17.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/styled-components/package.json b/packages/styled-components/package.json index 320996cf9..472490d58 100644 --- a/packages/styled-components/package.json +++ b/packages/styled-components/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-styled-components", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for styled-components", "main": "swc_plugin_styled_components.wasm", "scripts": { diff --git a/packages/styled-components/transform/Cargo.toml b/packages/styled-components/transform/Cargo.toml index 6e1397829..92a6532c4 100644 --- a/packages/styled-components/transform/Cargo.toml +++ b/packages/styled-components/transform/Cargo.toml @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0" name = "styled_components" repository = "https://github.com/swc-project/plugins.git" -version = "0.87.0" +version = "0.88.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/packages/styled-components/transform/src/utils/analyzer.rs b/packages/styled-components/transform/src/utils/analyzer.rs index 5434b219d..373019f98 100644 --- a/packages/styled-components/transform/src/utils/analyzer.rs +++ b/packages/styled-components/transform/src/utils/analyzer.rs @@ -111,13 +111,9 @@ impl Visit for Analyzer<'_> { ModuleExportName::Str(v) => &*v.value, }) .unwrap_or(&*s.local.sym); - if imported == "styled" { - self.state.imported_local_name = Some(s.local.to_id()); - } else { - self.state - .imported_local_named - .insert(imported.to_string(), s.local.to_id()); - } + self.state + .imported_local_named + .insert(imported.to_string(), s.local.to_id()); } ImportSpecifier::Default(s) => { self.state.imported_local_name = Some(s.local.to_id()); diff --git a/packages/styled-components/transform/src/utils/mod.rs b/packages/styled-components/transform/src/utils/mod.rs index 26e24ffe2..b49edc8c8 100644 --- a/packages/styled-components/transform/src/utils/mod.rs +++ b/packages/styled-components/transform/src/utils/mod.rs @@ -219,10 +219,19 @@ impl State { ) -> Option { if name == "default" { if self.imported_local_name.is_some() { + // import styled from 'styled-components' self.imported_local_name.clone() + } else if let Some(id) = self.imported_local_named.get("default") { + // import { default as styled } from 'styled-components' + Some(id.clone()) + } else if let Some(id) = self.imported_local_named.get("styled") { + // import { styled } from 'styled-components' + Some(id.clone()) } else if self.imported_local_ns.is_some() { + // import * as styled from 'styled-components' self.imported_local_ns.clone() } else if self.styled_required.is_some() { + // const styled = require('styled-components') Some(("styled".into(), self.unresolved_ctxt.unwrap_or_default())) } else { None @@ -230,8 +239,8 @@ impl State { } else { if self.imported_local_ns.is_some() { Some((name.into(), Default::default())) - } else if self.imported_local_named.contains_key(name) { - self.imported_local_named.get(name).cloned() + } else if let Some(id) = self.imported_local_named.get(name) { + Some(id.clone()) } else if self.styled_required.is_some() { Some((name.into(), self.unresolved_ctxt.unwrap_or_default())) } else { diff --git a/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc b/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc deleted file mode 100644 index 158460ca1..000000000 --- a/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "transpileTemplateLiterals": false, - "ssr": true - } - ] - ] -} \ No newline at end of file diff --git a/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/code.js b/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/code.js similarity index 100% rename from packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/code.js rename to packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/code.js diff --git a/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/config.json b/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/config.json new file mode 100644 index 000000000..91a67609f --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/config.json @@ -0,0 +1,4 @@ +{ + "transpileTemplateLiterals": false, + "minify": true +} diff --git a/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/output.js b/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/output.js similarity index 61% rename from packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/output.js rename to packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/output.js index 297e05c35..aeb045dea 100644 --- a/packages/styled-components/transform/tests/fixtures/.work-with-hoisted-default-as-import/output.js +++ b/packages/styled-components/transform/tests/fixtures/work-with-hoisted-default-as-import/output.js @@ -1,5 +1,5 @@ const Test = s.div.withConfig({ - displayName: "code__Test", - componentId: "sc-1dds9bl-0" + displayName: "code__Test", + componentId: "sc-cbecc97b-0" })`width:100%;`; import { default as s, css } from 'styled-components'; diff --git a/packages/styled-jsx/package.json b/packages/styled-jsx/package.json index db28613d7..9f5eb96fd 100644 --- a/packages/styled-jsx/package.json +++ b/packages/styled-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-styled-jsx", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for styled-jsx", "main": "swc_plugin_styled_jsx.wasm", "scripts": { diff --git a/packages/styled-jsx/transform/Cargo.toml b/packages/styled-jsx/transform/Cargo.toml index 8650312eb..6bb8b3d78 100644 --- a/packages/styled-jsx/transform/Cargo.toml +++ b/packages/styled-jsx/transform/Cargo.toml @@ -4,7 +4,7 @@ description = "AST transforms visitor for styled-jsx" edition = "2021" license = "Apache-2.0" name = "styled_jsx" -version = "0.64.0" +version = "0.65.0" [features] custom_transform = ["swc_common/concurrent"] diff --git a/packages/swc-magic/package.json b/packages/swc-magic/package.json index 117666d7a..1382cf184 100644 --- a/packages/swc-magic/package.json +++ b/packages/swc-magic/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-swc-magic", - "version": "1.5.102", + "version": "1.5.103", "description": "SWC plugin for swc-magic", "main": "swc_plugin_swc_magic.wasm", "scripts": { diff --git a/packages/swc-magic/transform/Cargo.toml b/packages/swc-magic/transform/Cargo.toml index 1af6f9dbc..2f5e3c17f 100644 --- a/packages/swc-magic/transform/Cargo.toml +++ b/packages/swc-magic/transform/Cargo.toml @@ -4,7 +4,7 @@ description = "AST transforms visitor for swc-magic" edition = "2021" license = "Apache-2.0" name = "swc_magic" -version = "0.10.0" +version = "0.11.0" [dependencies] serde = { version = "1.0.189", features = ["derive"] } diff --git a/packages/transform-imports/package.json b/packages/transform-imports/package.json index 3f9dd02d2..d5c10117d 100644 --- a/packages/transform-imports/package.json +++ b/packages/transform-imports/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-transform-imports", - "version": "1.5.102", + "version": "1.5.103", "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 10dfe2df6..b6d774904 100644 --- a/packages/transform-imports/transform/Cargo.toml +++ b/packages/transform-imports/transform/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "Apache-2.0" name = "modularize_imports" repository = "https://github.com/swc-project/plugins.git" -version = "0.59.0" +version = "0.60.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html