swc-plugin-add-display-name 0.7.0 → 0.8.1

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,9 +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
- - ❌ `const Context = createContext()`
6
+ - ✅ `const Component = () => jsx("div", { children: "hello" })` (Compiled JSX code)
7
+ - ✅ `const Component = () => React.createElement("div", null, "hello")` (Compiled or hand-written JSX code)
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!
7
16
 
8
17
  > If you have other situations that needs to add `displayName`, feel free to open an issue or PR!
9
18
 
@@ -50,9 +59,9 @@ Add plugin to wherever you have an SWC config (e.g. `.swcrc` file, `swc-loader`
50
59
 
51
60
  ## Configuration
52
61
 
53
- 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.
54
63
 
55
- 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.
56
65
 
57
66
  ## Examples
58
67
 
@@ -83,6 +92,63 @@ export function Component() { return <div />; }
83
92
  Component.displayName = "Component";
84
93
  ```
85
94
 
95
+ ```tsx
96
+ // Before
97
+ export const Component = () => jsx("div", { children: "hello" });
98
+
99
+ // After
100
+ export const Component = () => jsx("div", { children: "hello" });
101
+ Component.displayName = "Component";
102
+ ```
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
+
86
152
  ## License
87
153
 
88
154
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swc-plugin-add-display-name",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "An SWC plugin to add displayName to React components",
5
5
  "author": "hjkcai <huajingkun1214@gmail.com>",
6
6
  "license": "MIT",