@vitejs/plugin-react 2.1.0 → 2.2.0-beta.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/dist/index.cjs +44 -8
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +44 -8
- package/package.json +4 -4
- package/src/fast-refresh.ts +46 -8
- package/src/index.ts +7 -1
package/dist/index.cjs
CHANGED
@@ -76,21 +76,56 @@ if (import.meta.hot) {
|
|
76
76
|
};
|
77
77
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
78
78
|
}`.replace(/[\n]+/gm, "");
|
79
|
-
const
|
80
|
-
if (import.meta.hot) {
|
81
|
-
window.$RefreshReg$ = prevRefreshReg;
|
82
|
-
window.$RefreshSig$ = prevRefreshSig;
|
83
|
-
|
84
|
-
__ACCEPT__
|
79
|
+
const timeout = `
|
85
80
|
if (!window.__vite_plugin_react_timeout) {
|
86
81
|
window.__vite_plugin_react_timeout = setTimeout(() => {
|
87
82
|
window.__vite_plugin_react_timeout = 0;
|
88
83
|
RefreshRuntime.performReactRefresh();
|
89
84
|
}, 30);
|
90
85
|
}
|
86
|
+
`;
|
87
|
+
const footer = `
|
88
|
+
if (import.meta.hot) {
|
89
|
+
window.$RefreshReg$ = prevRefreshReg;
|
90
|
+
window.$RefreshSig$ = prevRefreshSig;
|
91
|
+
|
92
|
+
__ACCEPT__
|
91
93
|
}`;
|
94
|
+
const checkAndAccept = `
|
95
|
+
function isReactRefreshBoundary(mod) {
|
96
|
+
if (mod == null || typeof mod !== 'object') {
|
97
|
+
return false;
|
98
|
+
}
|
99
|
+
let hasExports = false;
|
100
|
+
let areAllExportsComponents = true;
|
101
|
+
for (const exportName in mod) {
|
102
|
+
hasExports = true;
|
103
|
+
if (exportName === '__esModule') {
|
104
|
+
continue;
|
105
|
+
}
|
106
|
+
const desc = Object.getOwnPropertyDescriptor(mod, exportName);
|
107
|
+
if (desc && desc.get) {
|
108
|
+
// Don't invoke getters as they may have side effects.
|
109
|
+
return false;
|
110
|
+
}
|
111
|
+
const exportValue = mod[exportName];
|
112
|
+
if (!RefreshRuntime.isLikelyComponentType(exportValue)) {
|
113
|
+
areAllExportsComponents = false;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
return hasExports && areAllExportsComponents;
|
117
|
+
}
|
118
|
+
|
119
|
+
import.meta.hot.accept(mod => {
|
120
|
+
if (isReactRefreshBoundary(mod)) {
|
121
|
+
${timeout}
|
122
|
+
} else {
|
123
|
+
import.meta.hot.invalidate();
|
124
|
+
}
|
125
|
+
});
|
126
|
+
`;
|
92
127
|
function addRefreshWrapper(code, id, accept) {
|
93
|
-
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ?
|
128
|
+
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ? checkAndAccept : timeout);
|
94
129
|
}
|
95
130
|
function isRefreshBoundary(ast) {
|
96
131
|
return ast.program.body.every((node) => {
|
@@ -305,7 +340,8 @@ function viteReact(opts = {}) {
|
|
305
340
|
{
|
306
341
|
runtime: "automatic",
|
307
342
|
importSource: opts.jsxImportSource,
|
308
|
-
pure: opts.jsxPure !== false
|
343
|
+
pure: opts.jsxPure !== false,
|
344
|
+
throwIfNamespace: opts.jsxThrowIfNamespace
|
309
345
|
}
|
310
346
|
]);
|
311
347
|
if (isCommonJS) {
|
package/dist/index.d.ts
CHANGED
@@ -26,6 +26,11 @@ interface Options {
|
|
26
26
|
* @default true
|
27
27
|
*/
|
28
28
|
jsxPure?: boolean;
|
29
|
+
/**
|
30
|
+
* Toggles whether or not to throw an error if an XML namespaced tag name is used.
|
31
|
+
* @default true
|
32
|
+
*/
|
33
|
+
jsxThrowIfNamespace?: boolean;
|
29
34
|
/**
|
30
35
|
* Babel configuration applied in both dev and prod.
|
31
36
|
*/
|
package/dist/index.mjs
CHANGED
@@ -55,21 +55,56 @@ if (import.meta.hot) {
|
|
55
55
|
};
|
56
56
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
57
57
|
}`.replace(/[\n]+/gm, "");
|
58
|
-
const
|
59
|
-
if (import.meta.hot) {
|
60
|
-
window.$RefreshReg$ = prevRefreshReg;
|
61
|
-
window.$RefreshSig$ = prevRefreshSig;
|
62
|
-
|
63
|
-
__ACCEPT__
|
58
|
+
const timeout = `
|
64
59
|
if (!window.__vite_plugin_react_timeout) {
|
65
60
|
window.__vite_plugin_react_timeout = setTimeout(() => {
|
66
61
|
window.__vite_plugin_react_timeout = 0;
|
67
62
|
RefreshRuntime.performReactRefresh();
|
68
63
|
}, 30);
|
69
64
|
}
|
65
|
+
`;
|
66
|
+
const footer = `
|
67
|
+
if (import.meta.hot) {
|
68
|
+
window.$RefreshReg$ = prevRefreshReg;
|
69
|
+
window.$RefreshSig$ = prevRefreshSig;
|
70
|
+
|
71
|
+
__ACCEPT__
|
70
72
|
}`;
|
73
|
+
const checkAndAccept = `
|
74
|
+
function isReactRefreshBoundary(mod) {
|
75
|
+
if (mod == null || typeof mod !== 'object') {
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
let hasExports = false;
|
79
|
+
let areAllExportsComponents = true;
|
80
|
+
for (const exportName in mod) {
|
81
|
+
hasExports = true;
|
82
|
+
if (exportName === '__esModule') {
|
83
|
+
continue;
|
84
|
+
}
|
85
|
+
const desc = Object.getOwnPropertyDescriptor(mod, exportName);
|
86
|
+
if (desc && desc.get) {
|
87
|
+
// Don't invoke getters as they may have side effects.
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
const exportValue = mod[exportName];
|
91
|
+
if (!RefreshRuntime.isLikelyComponentType(exportValue)) {
|
92
|
+
areAllExportsComponents = false;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
return hasExports && areAllExportsComponents;
|
96
|
+
}
|
97
|
+
|
98
|
+
import.meta.hot.accept(mod => {
|
99
|
+
if (isReactRefreshBoundary(mod)) {
|
100
|
+
${timeout}
|
101
|
+
} else {
|
102
|
+
import.meta.hot.invalidate();
|
103
|
+
}
|
104
|
+
});
|
105
|
+
`;
|
71
106
|
function addRefreshWrapper(code, id, accept) {
|
72
|
-
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ?
|
107
|
+
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ? checkAndAccept : timeout);
|
73
108
|
}
|
74
109
|
function isRefreshBoundary(ast) {
|
75
110
|
return ast.program.body.every((node) => {
|
@@ -284,7 +319,8 @@ function viteReact(opts = {}) {
|
|
284
319
|
{
|
285
320
|
runtime: "automatic",
|
286
321
|
importSource: opts.jsxImportSource,
|
287
|
-
pure: opts.jsxPure !== false
|
322
|
+
pure: opts.jsxPure !== false,
|
323
|
+
throwIfNamespace: opts.jsxThrowIfNamespace
|
288
324
|
}
|
289
325
|
]);
|
290
326
|
if (isCommonJS) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.2.0-beta.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"contributors": [
|
@@ -39,12 +39,12 @@
|
|
39
39
|
},
|
40
40
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme",
|
41
41
|
"dependencies": {
|
42
|
-
"@babel/core": "^7.
|
43
|
-
"@babel/plugin-transform-react-jsx": "^7.
|
42
|
+
"@babel/core": "^7.19.3",
|
43
|
+
"@babel/plugin-transform-react-jsx": "^7.19.0",
|
44
44
|
"@babel/plugin-transform-react-jsx-development": "^7.18.6",
|
45
45
|
"@babel/plugin-transform-react-jsx-self": "^7.18.6",
|
46
46
|
"@babel/plugin-transform-react-jsx-source": "^7.18.6",
|
47
|
-
"magic-string": "^0.26.
|
47
|
+
"magic-string": "^0.26.5",
|
48
48
|
"react-refresh": "^0.14.0"
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
package/src/fast-refresh.ts
CHANGED
@@ -58,20 +58,57 @@ if (import.meta.hot) {
|
|
58
58
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
59
59
|
}`.replace(/[\n]+/gm, '')
|
60
60
|
|
61
|
-
const
|
62
|
-
if (import.meta.hot) {
|
63
|
-
window.$RefreshReg$ = prevRefreshReg;
|
64
|
-
window.$RefreshSig$ = prevRefreshSig;
|
65
|
-
|
66
|
-
__ACCEPT__
|
61
|
+
const timeout = `
|
67
62
|
if (!window.__vite_plugin_react_timeout) {
|
68
63
|
window.__vite_plugin_react_timeout = setTimeout(() => {
|
69
64
|
window.__vite_plugin_react_timeout = 0;
|
70
65
|
RefreshRuntime.performReactRefresh();
|
71
66
|
}, 30);
|
72
67
|
}
|
68
|
+
`
|
69
|
+
|
70
|
+
const footer = `
|
71
|
+
if (import.meta.hot) {
|
72
|
+
window.$RefreshReg$ = prevRefreshReg;
|
73
|
+
window.$RefreshSig$ = prevRefreshSig;
|
74
|
+
|
75
|
+
__ACCEPT__
|
73
76
|
}`
|
74
77
|
|
78
|
+
const checkAndAccept = `
|
79
|
+
function isReactRefreshBoundary(mod) {
|
80
|
+
if (mod == null || typeof mod !== 'object') {
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
let hasExports = false;
|
84
|
+
let areAllExportsComponents = true;
|
85
|
+
for (const exportName in mod) {
|
86
|
+
hasExports = true;
|
87
|
+
if (exportName === '__esModule') {
|
88
|
+
continue;
|
89
|
+
}
|
90
|
+
const desc = Object.getOwnPropertyDescriptor(mod, exportName);
|
91
|
+
if (desc && desc.get) {
|
92
|
+
// Don't invoke getters as they may have side effects.
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
const exportValue = mod[exportName];
|
96
|
+
if (!RefreshRuntime.isLikelyComponentType(exportValue)) {
|
97
|
+
areAllExportsComponents = false;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return hasExports && areAllExportsComponents;
|
101
|
+
}
|
102
|
+
|
103
|
+
import.meta.hot.accept(mod => {
|
104
|
+
if (isReactRefreshBoundary(mod)) {
|
105
|
+
${timeout}
|
106
|
+
} else {
|
107
|
+
import.meta.hot.invalidate();
|
108
|
+
}
|
109
|
+
});
|
110
|
+
`
|
111
|
+
|
75
112
|
export function addRefreshWrapper(
|
76
113
|
code: string,
|
77
114
|
id: string,
|
@@ -80,12 +117,13 @@ export function addRefreshWrapper(
|
|
80
117
|
return (
|
81
118
|
header.replace('__SOURCE__', JSON.stringify(id)) +
|
82
119
|
code +
|
83
|
-
footer.replace('__ACCEPT__', accept ?
|
120
|
+
footer.replace('__ACCEPT__', accept ? checkAndAccept : timeout)
|
84
121
|
)
|
85
122
|
}
|
86
123
|
|
87
124
|
export function isRefreshBoundary(ast: t.File): boolean {
|
88
|
-
// Every export must be a React component.
|
125
|
+
// Every export must be a potential React component.
|
126
|
+
// We'll also perform a runtime check that's more robust as well (isLikelyComponentType).
|
89
127
|
return ast.program.body.every((node) => {
|
90
128
|
if (node.type !== 'ExportNamedDeclaration') {
|
91
129
|
return true
|
package/src/index.ts
CHANGED
@@ -40,6 +40,11 @@ export interface Options {
|
|
40
40
|
* @default true
|
41
41
|
*/
|
42
42
|
jsxPure?: boolean
|
43
|
+
/**
|
44
|
+
* Toggles whether or not to throw an error if an XML namespaced tag name is used.
|
45
|
+
* @default true
|
46
|
+
*/
|
47
|
+
jsxThrowIfNamespace?: boolean
|
43
48
|
/**
|
44
49
|
* Babel configuration applied in both dev and prod.
|
45
50
|
*/
|
@@ -248,7 +253,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
|
|
248
253
|
{
|
249
254
|
runtime: 'automatic',
|
250
255
|
importSource: opts.jsxImportSource,
|
251
|
-
pure: opts.jsxPure !== false
|
256
|
+
pure: opts.jsxPure !== false,
|
257
|
+
throwIfNamespace: opts.jsxThrowIfNamespace
|
252
258
|
}
|
253
259
|
])
|
254
260
|
|