swc-plugin-add-display-name 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # swc-plugin-add-display-name
2
2
 
3
- Automatically add `displayName` to *top-level* React *functional* components.
3
+ Automatically add `displayName` to *top-level* React *functional* components:
4
4
  - ✅ `const Component = () => <jsx />`
5
5
  - ✅ `function Component() { return <jsx /> }`
6
6
  - ✅ `const Component = () => jsx("div", { children: "hello" })` (Compiled JSX code)
7
7
  - ✅ `const Component = () => React.createElement("div", null, "hello")` (Compiled or hand-written JSX code)
8
- - ❌ `const Context = createContext()`
8
+
9
+ And some API calls that produce component:
10
+ - ✅ `const Context = createContext()` (React Context)
11
+ - ✅ `const StyledButton = styled.button` (Styled Components)
12
+ - ✅ `const ObservedComponent = observer(() => <jsx />)` (MobX observer)
13
+ - ✅ `const ConnectedComponent = connect(...)(() => <jsx />)` (Redux connect)
14
+
15
+ And even compiled code!
9
16
 
10
17
  > If you have other situations that needs to add `displayName`, feel free to open an issue or PR!
11
18
 
@@ -52,9 +59,9 @@ Add plugin to wherever you have an SWC config (e.g. `.swcrc` file, `swc-loader`
52
59
 
53
60
  ## Configuration
54
61
 
55
- This plugin currently has no configuration. However you have to leave an empty object to meet SWC's API schema.
62
+ This plugin currently has no configuration. However you have to pass an empty object to meet SWC's API schema.
56
63
 
57
- If you'd like to disable this plugin in production build, remove this plugin from the plugins list.
64
+ If you'd like to disable this plugin in production build, simply remove this plugin from the plugins list.
58
65
 
59
66
  ## Examples
60
67
 
@@ -94,6 +101,54 @@ export const Component = () => jsx("div", { children: "hello" });
94
101
  Component.displayName = "Component";
95
102
  ```
96
103
 
104
+ ```tsx
105
+ // Before
106
+ import { createContext } from 'react';
107
+ export const ThemeContext = createContext('light');
108
+
109
+ // After
110
+ import { createContext } from 'react';
111
+ export const ThemeContext = createContext('light');
112
+ ThemeContext.displayName = "ThemeContext";
113
+ ```
114
+
115
+ ```tsx
116
+ // Before
117
+ import styled from 'styled-components';
118
+ export const StyledButton = styled.button`
119
+ color: red;
120
+ `;
121
+
122
+ // After
123
+ import styled from 'styled-components';
124
+ export const StyledButton = styled.button`
125
+ color: red;
126
+ `;
127
+ StyledButton.displayName = "StyledButton";
128
+ ```
129
+
130
+ ```tsx
131
+ // Before
132
+ import { observer } from 'mobx-react-lite';
133
+ export const ObservedComponent = observer(() => <div />);
134
+
135
+ // After
136
+ import { observer } from 'mobx-react-lite';
137
+ export const ObservedComponent = observer(() => <div />);
138
+ ObservedComponent.displayName = "ObservedComponent";
139
+ ```
140
+
141
+ ```tsx
142
+ // Before
143
+ import { connect } from 'react-redux';
144
+ export const ConnectedComponent = connect(() => ({}))(() => null);
145
+
146
+ // After
147
+ import { connect } from 'react-redux';
148
+ export const ConnectedComponent = connect(() => ({}))(() => null);
149
+ ConnectedComponent.displayName = "ConnectedComponent";
150
+ ```
151
+
97
152
  ## License
98
153
 
99
154
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swc-plugin-add-display-name",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "An SWC plugin to add displayName to React components",
5
5
  "author": "hjkcai <huajingkun1214@gmail.com>",
6
6
  "license": "MIT",
@@ -16,10 +16,10 @@
16
16
  "prepublishOnly": "cargo build-wasi --release"
17
17
  },
18
18
  "peerDependencies": {
19
- "@swc/core": "^1.14.0"
19
+ "@swc/core": "^1.15.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@swc/cli": "^0.6.0",
23
- "@swc/core": "^1.14.0"
23
+ "@swc/core": "^1.15.0"
24
24
  }
25
25
  }