Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(styled-jsx): Allow importing styled from styled-components #225

Merged
merged 26 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c323090
Add a test for #224
kdy1 Oct 30, 2023
425a5c2
fixup
kdy1 Oct 30, 2023
56f854d
fix
kdy1 Oct 30, 2023
4599a15
Update test refs
kdy1 Oct 30, 2023
f5a3ba1
Bump npm package: ./packages/constify
kdy1 Oct 30, 2023
76d9c8e
Bump npm package: ./packages/emotion
kdy1 Oct 30, 2023
e588dbb
Bump npm package: ./packages/jest
kdy1 Oct 30, 2023
2c0268e
Bump npm package: ./packages/loadable-components
kdy1 Oct 30, 2023
ef05377
Bump npm package: ./packages/noop
kdy1 Oct 30, 2023
bd4ce38
Bump npm package: ./packages/react-remove-properties
kdy1 Oct 30, 2023
cdb8fa8
Bump npm package: ./packages/relay
kdy1 Oct 30, 2023
6c3564b
Bump npm package: ./packages/remove-console
kdy1 Oct 30, 2023
4921c7b
Bump npm package: ./packages/styled-components
kdy1 Oct 30, 2023
3a6ebc9
Bump npm package: ./packages/styled-jsx
kdy1 Oct 30, 2023
7ab132c
Bump npm package: ./packages/swc-magic
kdy1 Oct 30, 2023
d8701c2
Bump npm package: ./packages/transform-imports
kdy1 Oct 30, 2023
5dcf674
Bump cargo crate: modularize_imports
kdy1 Oct 30, 2023
6275fe0
Bump cargo crate: react_remove_properties
kdy1 Oct 30, 2023
dd0b198
Bump cargo crate: remove_console
kdy1 Oct 30, 2023
0bb076c
Bump cargo crate: styled_components
kdy1 Oct 30, 2023
2440b08
Bump cargo crate: styled_jsx
kdy1 Oct 30, 2023
4f23ea2
Bump cargo crate: swc_constify
kdy1 Oct 30, 2023
1bfd0e3
Bump cargo crate: swc_emotion
kdy1 Oct 30, 2023
6c9356f
Bump cargo crate: swc_magic
kdy1 Oct 30, 2023
0398745
Bump cargo crate: swc_relay
kdy1 Oct 30, 2023
21f9482
xtask
kdy1 Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/constify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-constify",
"version": "0.1.24",
"version": "0.1.25",
"description": "SWC plugin for optimization",
"main": "swc_plugin_constify.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/constify/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_constify"
repository = "https://github.com/swc-project/plugins.git"
version = "0.19.0"
version = "0.20.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-emotion",
"version": "2.5.94",
"version": "2.5.95",
"description": "SWC plugin for emotion css-in-js library",
"main": "swc_plugin_emotion.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_emotion"
repository = "https://github.com/swc-project/plugins.git"
version = "0.55.0"
version = "0.56.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-jest",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for jest",
"main": "swc_plugin_jest.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/loadable-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-loadable-components",
"version": "0.3.94",
"version": "0.3.95",
"description": "SWC plugin for `@loadable/components`",
"main": "swc_plugin_loadable_components.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/noop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-noop",
"version": "1.5.92",
"version": "1.5.93",
"description": "Noop SWC plugin, for debugging",
"main": "swc_plugin_noop.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-react-remove-properties",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-react-remove-properties",
"main": "swc_plugin_react_remove_properties.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "react_remove_properties"
repository = "https://github.com/swc-project/plugins.git"
version = "0.7.0"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-relay",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for relay",
"main": "swc_plugin_relay.wasm",
"types": "./types.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_relay"
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

Expand Down
2 changes: 1 addition & 1 deletion packages/remove-console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-remove-console",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-remove-console",
"main": "swc_plugin_remove_console.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remove-console/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "remove_console"
repository = "https://github.com/swc-project/plugins.git"
version = "0.8.0"
version = "0.9.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/styled-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-styled-components",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for styled-components",
"main": "swc_plugin_styled_components.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-components/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.79.0"
version = "0.80.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
19 changes: 8 additions & 11 deletions packages/styled-components/transform/src/utils/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ impl Visit for Analyzer<'_> {
}

fn visit_import_decl(&mut self, i: &ImportDecl) {
let is_custom = !self.config.top_level_import_paths.is_empty();

let is_styled = if self.config.top_level_import_paths.is_empty() {
&*i.src.value == "styled-components" || i.src.value.starts_with("styled-components/")
} else {
Expand All @@ -105,15 +103,14 @@ impl Visit for Analyzer<'_> {
for s in &i.specifiers {
match s {
ImportSpecifier::Named(s) => {
if is_custom
&& s.imported
.as_ref()
.map(|v| match v {
ModuleExportName::Ident(v) => &*v.sym,
ModuleExportName::Str(v) => &*v.value,
})
.unwrap_or(&*s.local.sym)
== "styled"
if s.imported
.as_ref()
.map(|v| match v {
ModuleExportName::Ident(v) => &*v.sym,
ModuleExportName::Str(v) => &*v.value,
})
.unwrap_or(&*s.local.sym)
== "styled"
{
self.state.imported_local_name = Some(s.local.to_id());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { styled } from 'styled-components';


const Test = styled.div`
width: 100%;
`
const Test2 = true ? styled.div`` : styled.div``
const styles = { One: styled.div`` }
let Component
Component = styled.div``
const WrappedComponent = styled(Inner)``
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { styled } from 'styled-components';
const Test = styled.div.withConfig({
displayName: "code__Test",
componentId: "sc-8043c6cb-0"
})`
width: 100%;
`;
const Test2 = true ? styled.div.withConfig({
displayName: "code__Test2",
componentId: "sc-8043c6cb-1"
})`` : styled.div.withConfig({
displayName: "code__Test2",
componentId: "sc-8043c6cb-2"
})``;
const styles = {
One: styled.div.withConfig({
displayName: "code__One",
componentId: "sc-8043c6cb-3"
})``
};
let Component;
Component = styled.div.withConfig({
displayName: "code__Component",
componentId: "sc-8043c6cb-4"
})``;
const WrappedComponent = styled(Inner).withConfig({
displayName: "code__WrappedComponent",
componentId: "sc-8043c6cb-5"
})``;
2 changes: 1 addition & 1 deletion packages/styled-jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-styled-jsx",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for styled-jsx",
"main": "swc_plugin_styled_jsx.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-jsx/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "AST transforms visitor for styled-jsx"
edition = "2021"
license = "Apache-2.0"
name = "styled_jsx"
version = "0.56.0"
version = "0.57.0"

[features]
custom_transform = ["swc_common/concurrent"]
Expand Down
2 changes: 1 addition & 1 deletion packages/swc-magic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-swc-magic",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for swc-magic",
"main": "swc_plugin_swc_magic.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/swc-magic/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "AST transforms visitor for swc-magic"
edition = "2021"
license = "Apache-2.0"
name = "swc_magic"
version = "0.2.0"
version = "0.3.0"

[dependencies]
serde = { version = "1.0.189", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/transform-imports/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-transform-imports",
"version": "1.5.94",
"version": "1.5.95",
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-transform-imports",
"main": "swc_plugin_transform_imports.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/transform-imports/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "modularize_imports"
repository = "https://github.com/swc-project/plugins.git"
version = "0.52.0"
version = "0.53.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "xtask"
version = "0.2.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
Loading