@vitejs/plugin-react 1.3.1 → 2.0.0-alpha.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.
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * https://github.com/flying-sheep/babel-plugin-transform-react-createelement-to-jsx
5
+ * @license GNU General Public License v3.0
6
+ */
7
+ function babelRestoreJsx({ types: t }) {
8
+ function getJSXNode(node) {
9
+ if (!isReactCreateElement(node)) {
10
+ return null;
11
+ }
12
+ const [nameNode, propsNode, ...childNodes] = node.arguments;
13
+ const name = getJSXName(nameNode);
14
+ if (name == null) {
15
+ return null;
16
+ }
17
+ const props = getJSXProps(propsNode);
18
+ if (props == null) {
19
+ return null;
20
+ }
21
+ const children = getJSXChildren(childNodes);
22
+ if (children == null) {
23
+ return null;
24
+ }
25
+ if (t.isJSXMemberExpression(name) && t.isJSXIdentifier(name.object) && name.object.name === "React" && name.property.name === "Fragment") {
26
+ return t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), children);
27
+ }
28
+ const selfClosing = children.length === 0;
29
+ const startTag = t.jsxOpeningElement(name, props, selfClosing);
30
+ startTag.loc = node.loc;
31
+ const endTag = selfClosing ? null : t.jsxClosingElement(name);
32
+ return t.jsxElement(startTag, endTag, children, selfClosing);
33
+ }
34
+ function getJSXName(node) {
35
+ if (node == null) {
36
+ return null;
37
+ }
38
+ const name = getJSXIdentifier(node, true);
39
+ if (name != null) {
40
+ return name;
41
+ }
42
+ if (!t.isMemberExpression(node)) {
43
+ return null;
44
+ }
45
+ const object = getJSXName(node.object);
46
+ const property = getJSXName(node.property);
47
+ if (object == null || property == null) {
48
+ return null;
49
+ }
50
+ return t.jsxMemberExpression(object, property);
51
+ }
52
+ function getJSXProps(node) {
53
+ if (node == null || isNullLikeNode(node)) {
54
+ return [];
55
+ }
56
+ if (t.isCallExpression(node) && t.isIdentifier(node.callee, { name: "_extends" })) {
57
+ const props = node.arguments.map(getJSXProps);
58
+ if (props.every((prop) => prop != null)) {
59
+ return [].concat(...props);
60
+ }
61
+ }
62
+ if (!t.isObjectExpression(node) && t.isExpression(node))
63
+ return [t.jsxSpreadAttribute(node)];
64
+ if (!isPlainObjectExpression(node)) {
65
+ return null;
66
+ }
67
+ return node.properties.map((prop) => t.isObjectProperty(prop) ? t.jsxAttribute(getJSXIdentifier(prop.key), getJSXAttributeValue(prop.value)) : t.jsxSpreadAttribute(prop.argument));
68
+ }
69
+ function getJSXChild(node) {
70
+ if (t.isStringLiteral(node)) {
71
+ return t.jsxText(node.value);
72
+ }
73
+ if (isReactCreateElement(node)) {
74
+ return getJSXNode(node);
75
+ }
76
+ if (t.isExpression(node)) {
77
+ return t.jsxExpressionContainer(node);
78
+ }
79
+ return null;
80
+ }
81
+ function getJSXChildren(nodes) {
82
+ const children = nodes.filter((node) => !isNullLikeNode(node)).map(getJSXChild);
83
+ if (children.some((child) => child == null)) {
84
+ return null;
85
+ }
86
+ return children;
87
+ }
88
+ function getJSXIdentifier(node, tag = false) {
89
+ if (t.isIdentifier(node) && (!tag || node.name.match(/^[A-Z]/))) {
90
+ return t.jsxIdentifier(node.name);
91
+ }
92
+ if (t.isStringLiteral(node)) {
93
+ return t.jsxIdentifier(node.value);
94
+ }
95
+ return null;
96
+ }
97
+ function getJSXAttributeValue(node) {
98
+ if (t.isStringLiteral(node)) {
99
+ return node;
100
+ }
101
+ if (t.isJSXElement(node)) {
102
+ return node;
103
+ }
104
+ if (t.isExpression(node)) {
105
+ return t.jsxExpressionContainer(node);
106
+ }
107
+ return null;
108
+ }
109
+ const isReactCreateElement = (node) => t.isCallExpression(node) && t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object, { name: "React" }) && t.isIdentifier(node.callee.property, { name: "createElement" }) && !node.callee.computed;
110
+ const isNullLikeNode = (node) => t.isNullLiteral(node) || t.isIdentifier(node, { name: "undefined" });
111
+ const isPlainObjectExpression = (node) => t.isObjectExpression(node) && node.properties.every((property) => t.isSpreadElement(property) || t.isObjectProperty(property, { computed: false }) && getJSXIdentifier(property.key) != null && getJSXAttributeValue(property.value) != null);
112
+ return {
113
+ visitor: {
114
+ CallExpression(path) {
115
+ const node = getJSXNode(path.node);
116
+ if (node == null) {
117
+ return null;
118
+ }
119
+ path.replaceWith(node);
120
+ }
121
+ }
122
+ };
123
+ }
124
+
125
+ exports["default"] = babelRestoreJsx;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * https://github.com/flying-sheep/babel-plugin-transform-react-createelement-to-jsx
3
+ * @license GNU General Public License v3.0
4
+ */
5
+ function babelRestoreJsx({ types: t }) {
6
+ function getJSXNode(node) {
7
+ if (!isReactCreateElement(node)) {
8
+ return null;
9
+ }
10
+ const [nameNode, propsNode, ...childNodes] = node.arguments;
11
+ const name = getJSXName(nameNode);
12
+ if (name == null) {
13
+ return null;
14
+ }
15
+ const props = getJSXProps(propsNode);
16
+ if (props == null) {
17
+ return null;
18
+ }
19
+ const children = getJSXChildren(childNodes);
20
+ if (children == null) {
21
+ return null;
22
+ }
23
+ if (t.isJSXMemberExpression(name) && t.isJSXIdentifier(name.object) && name.object.name === "React" && name.property.name === "Fragment") {
24
+ return t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), children);
25
+ }
26
+ const selfClosing = children.length === 0;
27
+ const startTag = t.jsxOpeningElement(name, props, selfClosing);
28
+ startTag.loc = node.loc;
29
+ const endTag = selfClosing ? null : t.jsxClosingElement(name);
30
+ return t.jsxElement(startTag, endTag, children, selfClosing);
31
+ }
32
+ function getJSXName(node) {
33
+ if (node == null) {
34
+ return null;
35
+ }
36
+ const name = getJSXIdentifier(node, true);
37
+ if (name != null) {
38
+ return name;
39
+ }
40
+ if (!t.isMemberExpression(node)) {
41
+ return null;
42
+ }
43
+ const object = getJSXName(node.object);
44
+ const property = getJSXName(node.property);
45
+ if (object == null || property == null) {
46
+ return null;
47
+ }
48
+ return t.jsxMemberExpression(object, property);
49
+ }
50
+ function getJSXProps(node) {
51
+ if (node == null || isNullLikeNode(node)) {
52
+ return [];
53
+ }
54
+ if (t.isCallExpression(node) && t.isIdentifier(node.callee, { name: "_extends" })) {
55
+ const props = node.arguments.map(getJSXProps);
56
+ if (props.every((prop) => prop != null)) {
57
+ return [].concat(...props);
58
+ }
59
+ }
60
+ if (!t.isObjectExpression(node) && t.isExpression(node))
61
+ return [t.jsxSpreadAttribute(node)];
62
+ if (!isPlainObjectExpression(node)) {
63
+ return null;
64
+ }
65
+ return node.properties.map((prop) => t.isObjectProperty(prop) ? t.jsxAttribute(getJSXIdentifier(prop.key), getJSXAttributeValue(prop.value)) : t.jsxSpreadAttribute(prop.argument));
66
+ }
67
+ function getJSXChild(node) {
68
+ if (t.isStringLiteral(node)) {
69
+ return t.jsxText(node.value);
70
+ }
71
+ if (isReactCreateElement(node)) {
72
+ return getJSXNode(node);
73
+ }
74
+ if (t.isExpression(node)) {
75
+ return t.jsxExpressionContainer(node);
76
+ }
77
+ return null;
78
+ }
79
+ function getJSXChildren(nodes) {
80
+ const children = nodes.filter((node) => !isNullLikeNode(node)).map(getJSXChild);
81
+ if (children.some((child) => child == null)) {
82
+ return null;
83
+ }
84
+ return children;
85
+ }
86
+ function getJSXIdentifier(node, tag = false) {
87
+ if (t.isIdentifier(node) && (!tag || node.name.match(/^[A-Z]/))) {
88
+ return t.jsxIdentifier(node.name);
89
+ }
90
+ if (t.isStringLiteral(node)) {
91
+ return t.jsxIdentifier(node.value);
92
+ }
93
+ return null;
94
+ }
95
+ function getJSXAttributeValue(node) {
96
+ if (t.isStringLiteral(node)) {
97
+ return node;
98
+ }
99
+ if (t.isJSXElement(node)) {
100
+ return node;
101
+ }
102
+ if (t.isExpression(node)) {
103
+ return t.jsxExpressionContainer(node);
104
+ }
105
+ return null;
106
+ }
107
+ const isReactCreateElement = (node) => t.isCallExpression(node) && t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object, { name: "React" }) && t.isIdentifier(node.callee.property, { name: "createElement" }) && !node.callee.computed;
108
+ const isNullLikeNode = (node) => t.isNullLiteral(node) || t.isIdentifier(node, { name: "undefined" });
109
+ const isPlainObjectExpression = (node) => t.isObjectExpression(node) && node.properties.every((property) => t.isSpreadElement(property) || t.isObjectProperty(property, { computed: false }) && getJSXIdentifier(property.key) != null && getJSXAttributeValue(property.value) != null);
110
+ return {
111
+ visitor: {
112
+ CallExpression(path) {
113
+ const node = getJSXNode(path.node);
114
+ if (node == null) {
115
+ return null;
116
+ }
117
+ path.replaceWith(node);
118
+ }
119
+ }
120
+ };
121
+ }
122
+
123
+ export { babelRestoreJsx as default };
package/dist/index.cjs ADDED
@@ -0,0 +1,401 @@
1
+ 'use strict';
2
+
3
+ const babel = require('@babel/core');
4
+ const pluginutils = require('@rollup/pluginutils');
5
+ const resolve = require('resolve');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const module$1 = require('module');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ const n = Object.create(null);
15
+ if (e) {
16
+ for (const k in e) {
17
+ n[k] = e[k];
18
+ }
19
+ }
20
+ n["default"] = e;
21
+ return n;
22
+ }
23
+
24
+ const babel__namespace = /*#__PURE__*/_interopNamespace(babel);
25
+ const resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve);
26
+ const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
27
+ const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
28
+
29
+ const runtimePublicPath = "/@react-refresh";
30
+ const _require = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
31
+ const reactRefreshDir = path__default.dirname(_require.resolve("react-refresh/package.json"));
32
+ const runtimeFilePath = path__default.join(reactRefreshDir, "cjs/react-refresh-runtime.development.js");
33
+ const runtimeCode = `
34
+ const exports = {}
35
+ ${fs__default.readFileSync(runtimeFilePath, "utf-8")}
36
+ function debounce(fn, delay) {
37
+ let handle
38
+ return () => {
39
+ clearTimeout(handle)
40
+ handle = setTimeout(fn, delay)
41
+ }
42
+ }
43
+ exports.performReactRefresh = debounce(exports.performReactRefresh, 16)
44
+ export default exports
45
+ `;
46
+ const preambleCode = `
47
+ import RefreshRuntime from "__BASE__${runtimePublicPath.slice(1)}"
48
+ RefreshRuntime.injectIntoGlobalHook(window)
49
+ window.$RefreshReg$ = () => {}
50
+ window.$RefreshSig$ = () => (type) => type
51
+ window.__vite_plugin_react_preamble_installed__ = true
52
+ `;
53
+ const header = `
54
+ import RefreshRuntime from "${runtimePublicPath}";
55
+
56
+ let prevRefreshReg;
57
+ let prevRefreshSig;
58
+
59
+ if (import.meta.hot) {
60
+ if (!window.__vite_plugin_react_preamble_installed__) {
61
+ throw new Error(
62
+ "@vitejs/plugin-react can't detect preamble. Something is wrong. " +
63
+ "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201"
64
+ );
65
+ }
66
+
67
+ prevRefreshReg = window.$RefreshReg$;
68
+ prevRefreshSig = window.$RefreshSig$;
69
+ window.$RefreshReg$ = (type, id) => {
70
+ RefreshRuntime.register(type, __SOURCE__ + " " + id)
71
+ };
72
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
73
+ }`.replace(/[\n]+/gm, "");
74
+ const footer = `
75
+ if (import.meta.hot) {
76
+ window.$RefreshReg$ = prevRefreshReg;
77
+ window.$RefreshSig$ = prevRefreshSig;
78
+
79
+ __ACCEPT__
80
+ if (!window.__vite_plugin_react_timeout) {
81
+ window.__vite_plugin_react_timeout = setTimeout(() => {
82
+ window.__vite_plugin_react_timeout = 0;
83
+ RefreshRuntime.performReactRefresh();
84
+ }, 30);
85
+ }
86
+ }`;
87
+ function addRefreshWrapper(code, id, accept) {
88
+ return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer.replace("__ACCEPT__", accept ? "import.meta.hot.accept();" : "");
89
+ }
90
+ function isRefreshBoundary(ast) {
91
+ return ast.program.body.every((node) => {
92
+ if (node.type !== "ExportNamedDeclaration") {
93
+ return true;
94
+ }
95
+ const { declaration, specifiers } = node;
96
+ if (declaration) {
97
+ if (declaration.type === "VariableDeclaration") {
98
+ return declaration.declarations.every((variable) => isComponentLikeIdentifier(variable.id));
99
+ }
100
+ if (declaration.type === "FunctionDeclaration") {
101
+ return !!declaration.id && isComponentLikeIdentifier(declaration.id);
102
+ }
103
+ }
104
+ return specifiers.every((spec) => {
105
+ return isComponentLikeIdentifier(spec.exported);
106
+ });
107
+ });
108
+ }
109
+ function isComponentLikeIdentifier(node) {
110
+ return node.type === "Identifier" && isComponentLikeName(node.name);
111
+ }
112
+ function isComponentLikeName(name) {
113
+ return typeof name === "string" && name[0] >= "A" && name[0] <= "Z";
114
+ }
115
+
116
+ function babelImportToRequire({ types: t }) {
117
+ return {
118
+ visitor: {
119
+ ImportDeclaration(path) {
120
+ const decl = path.node;
121
+ const spec = decl.specifiers[0];
122
+ path.replaceWith(t.variableDeclaration("var", [
123
+ t.variableDeclarator(spec.local, t.memberExpression(t.callExpression(t.identifier("require"), [decl.source]), spec.imported))
124
+ ]));
125
+ }
126
+ }
127
+ };
128
+ }
129
+
130
+ let babelRestoreJSX;
131
+ const jsxNotFound = [null, false];
132
+ async function getBabelRestoreJSX() {
133
+ if (!babelRestoreJSX)
134
+ babelRestoreJSX = import('./chunks/babel-restore-jsx.cjs').then((r) => {
135
+ const fn = r.default;
136
+ if ("default" in fn)
137
+ return fn.default;
138
+ return fn;
139
+ });
140
+ return babelRestoreJSX;
141
+ }
142
+ async function restoreJSX(babel, code, filename) {
143
+ if (filename.includes("/.vite/react-dom.js")) {
144
+ return jsxNotFound;
145
+ }
146
+ const [reactAlias, isCommonJS] = parseReactAlias(code);
147
+ if (!reactAlias) {
148
+ return jsxNotFound;
149
+ }
150
+ let hasCompiledJsx = false;
151
+ const fragmentPattern = `\\b${reactAlias}\\.Fragment\\b`;
152
+ const createElementPattern = `\\b${reactAlias}\\.createElement\\(\\s*([A-Z"'][\\w$.]*["']?)`;
153
+ code = code.replace(new RegExp(fragmentPattern, "g"), () => {
154
+ hasCompiledJsx = true;
155
+ return "React.Fragment";
156
+ }).replace(new RegExp(createElementPattern, "g"), (original, component) => {
157
+ if (/^[a-z][\w$]*$/.test(component)) {
158
+ return original;
159
+ }
160
+ hasCompiledJsx = true;
161
+ return "React.createElement(" + (component === "Fragment" ? "React.Fragment" : component);
162
+ });
163
+ if (!hasCompiledJsx) {
164
+ return jsxNotFound;
165
+ }
166
+ const result = await babel.transformAsync(code, {
167
+ babelrc: false,
168
+ configFile: false,
169
+ ast: true,
170
+ code: false,
171
+ filename,
172
+ parserOpts: {
173
+ plugins: ["jsx"]
174
+ },
175
+ plugins: [await getBabelRestoreJSX()]
176
+ });
177
+ return [result?.ast, isCommonJS];
178
+ }
179
+ function parseReactAlias(code) {
180
+ let match = code.match(/\b(var|let|const) +(\w+) *= *require\(["']react["']\)/);
181
+ if (match) {
182
+ return [match[2], true];
183
+ }
184
+ match = code.match(/^import (\w+).+? from ["']react["']/m);
185
+ if (match) {
186
+ return [match[1], false];
187
+ }
188
+ return [void 0, false];
189
+ }
190
+
191
+ function viteReact(opts = {}) {
192
+ var _a;
193
+ let base = "/";
194
+ let filter = pluginutils.createFilter(opts.include, opts.exclude);
195
+ let isProduction = true;
196
+ let projectRoot = process.cwd();
197
+ let skipFastRefresh = opts.fastRefresh === false;
198
+ let skipReactImport = false;
199
+ const useAutomaticRuntime = opts.jsxRuntime !== "classic";
200
+ const babelOptions = {
201
+ babelrc: false,
202
+ configFile: false,
203
+ ...opts.babel
204
+ };
205
+ babelOptions.plugins || (babelOptions.plugins = []);
206
+ babelOptions.presets || (babelOptions.presets = []);
207
+ babelOptions.overrides || (babelOptions.overrides = []);
208
+ babelOptions.parserOpts || (babelOptions.parserOpts = {});
209
+ (_a = babelOptions.parserOpts).plugins || (_a.plugins = []);
210
+ const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
211
+ const fileExtensionRE = /\.[^\/\s\?]+$/;
212
+ const viteBabel = {
213
+ name: "vite:react-babel",
214
+ enforce: "pre",
215
+ configResolved(config) {
216
+ base = config.base;
217
+ projectRoot = config.root;
218
+ filter = pluginutils.createFilter(opts.include, opts.exclude, {
219
+ resolve: projectRoot
220
+ });
221
+ isProduction = config.isProduction;
222
+ skipFastRefresh || (skipFastRefresh = isProduction || config.command === "build");
223
+ const jsxInject = config.esbuild && config.esbuild.jsxInject;
224
+ if (jsxInject && importReactRE.test(jsxInject)) {
225
+ skipReactImport = true;
226
+ config.logger.warn("[@vitejs/plugin-react] This plugin imports React for you automatically, so you can stop using `esbuild.jsxInject` for that purpose.");
227
+ }
228
+ config.plugins.forEach((plugin) => {
229
+ const hasConflict = plugin.name === "react-refresh" || plugin !== viteReactJsx && plugin.name === "vite:react-jsx";
230
+ if (hasConflict)
231
+ return config.logger.warn(`[@vitejs/plugin-react] You should stop using "${plugin.name}" since this plugin conflicts with it.`);
232
+ if (plugin.api?.reactBabel) {
233
+ plugin.api.reactBabel(babelOptions, config);
234
+ }
235
+ });
236
+ },
237
+ async transform(code, id, options) {
238
+ const ssr = typeof options === "boolean" ? options : options?.ssr === true;
239
+ const [filepath, querystring = ""] = id.split("?");
240
+ const [extension = ""] = querystring.match(fileExtensionRE) || filepath.match(fileExtensionRE) || [];
241
+ if (/\.(mjs|[tj]sx?)$/.test(extension)) {
242
+ const isJSX = extension.endsWith("x");
243
+ const isNodeModules = id.includes("/node_modules/");
244
+ const isProjectFile = !isNodeModules && (id[0] === "\0" || id.startsWith(projectRoot + "/"));
245
+ const plugins = isProjectFile ? [...babelOptions.plugins] : [];
246
+ let useFastRefresh = false;
247
+ if (!skipFastRefresh && !ssr && !isNodeModules) {
248
+ const isReactModule = isJSX || importReactRE.test(code);
249
+ if (isReactModule && filter(id)) {
250
+ useFastRefresh = true;
251
+ plugins.push([
252
+ await loadPlugin("react-refresh/babel"),
253
+ { skipEnvCheck: true }
254
+ ]);
255
+ }
256
+ }
257
+ let ast;
258
+ if (!isProjectFile || isJSX) {
259
+ if (useAutomaticRuntime) {
260
+ const [restoredAst, isCommonJS] = !isProjectFile && !isJSX ? await restoreJSX(babel__namespace, code, id) : [null, false];
261
+ if (isJSX || (ast = restoredAst)) {
262
+ plugins.push([
263
+ await loadPlugin("@babel/plugin-transform-react-jsx" + (isProduction ? "" : "-development")),
264
+ {
265
+ runtime: "automatic",
266
+ importSource: opts.jsxImportSource,
267
+ pure: opts.jsxPure !== false
268
+ }
269
+ ]);
270
+ if (isCommonJS) {
271
+ plugins.push(babelImportToRequire);
272
+ }
273
+ }
274
+ } else if (isProjectFile) {
275
+ if (!isProduction) {
276
+ plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
277
+ }
278
+ if (!skipReactImport && !importReactRE.test(code)) {
279
+ code = `import React from 'react'; ` + code;
280
+ }
281
+ }
282
+ }
283
+ const shouldSkip = !plugins.length && !babelOptions.configFile && !(isProjectFile && babelOptions.babelrc);
284
+ if (shouldSkip) {
285
+ return;
286
+ }
287
+ const parserPlugins = [
288
+ ...babelOptions.parserOpts.plugins,
289
+ "importMeta",
290
+ "topLevelAwait",
291
+ "classProperties",
292
+ "classPrivateProperties",
293
+ "classPrivateMethods"
294
+ ];
295
+ if (!extension.endsWith(".ts")) {
296
+ parserPlugins.push("jsx");
297
+ }
298
+ if (/\.tsx?$/.test(extension)) {
299
+ parserPlugins.push("typescript");
300
+ }
301
+ const transformAsync = ast ? babel__namespace.transformFromAstAsync.bind(babel__namespace, ast, code) : babel__namespace.transformAsync.bind(babel__namespace, code);
302
+ const isReasonReact = extension.endsWith(".bs.js");
303
+ const result = await transformAsync({
304
+ ...babelOptions,
305
+ ast: !isReasonReact,
306
+ root: projectRoot,
307
+ filename: id,
308
+ sourceFileName: filepath,
309
+ parserOpts: {
310
+ ...babelOptions.parserOpts,
311
+ sourceType: "module",
312
+ allowAwaitOutsideFunction: true,
313
+ plugins: parserPlugins
314
+ },
315
+ generatorOpts: {
316
+ ...babelOptions.generatorOpts,
317
+ decoratorsBeforeExport: true
318
+ },
319
+ plugins,
320
+ sourceMaps: true,
321
+ inputSourceMap: false
322
+ });
323
+ if (result) {
324
+ let code2 = result.code;
325
+ if (useFastRefresh && /\$RefreshReg\$\(/.test(code2)) {
326
+ const accept = isReasonReact || isRefreshBoundary(result.ast);
327
+ code2 = addRefreshWrapper(code2, id, accept);
328
+ }
329
+ return {
330
+ code: code2,
331
+ map: result.map
332
+ };
333
+ }
334
+ }
335
+ }
336
+ };
337
+ const viteReactRefresh = {
338
+ name: "vite:react-refresh",
339
+ enforce: "pre",
340
+ config: () => ({
341
+ resolve: {
342
+ dedupe: ["react", "react-dom"]
343
+ }
344
+ }),
345
+ resolveId(id) {
346
+ if (id === runtimePublicPath) {
347
+ return id;
348
+ }
349
+ },
350
+ load(id) {
351
+ if (id === runtimePublicPath) {
352
+ return runtimeCode;
353
+ }
354
+ },
355
+ transformIndexHtml() {
356
+ if (!skipFastRefresh)
357
+ return [
358
+ {
359
+ tag: "script",
360
+ attrs: { type: "module" },
361
+ children: preambleCode.replace(`__BASE__`, base)
362
+ }
363
+ ];
364
+ }
365
+ };
366
+ const runtimeId = "react/jsx-runtime";
367
+ const viteReactJsx = {
368
+ name: "vite:react-jsx",
369
+ enforce: "pre",
370
+ config() {
371
+ return {
372
+ optimizeDeps: {
373
+ include: ["react/jsx-dev-runtime"]
374
+ }
375
+ };
376
+ },
377
+ resolveId(id) {
378
+ return id === runtimeId ? id : null;
379
+ },
380
+ load(id) {
381
+ if (id === runtimeId) {
382
+ const runtimePath = resolve__default.sync(runtimeId, {
383
+ basedir: projectRoot
384
+ });
385
+ const exports = ["jsx", "jsxs", "Fragment"];
386
+ return [
387
+ `import * as jsxRuntime from ${JSON.stringify(runtimePath)}`,
388
+ ...exports.map((name) => `export const ${name} = jsxRuntime.${name}`)
389
+ ].join("\n");
390
+ }
391
+ }
392
+ };
393
+ return [viteBabel, viteReactRefresh, useAutomaticRuntime && viteReactJsx];
394
+ }
395
+ viteReact.preambleCode = preambleCode;
396
+ function loadPlugin(path) {
397
+ return import(path).then((module) => module.default || module);
398
+ }
399
+
400
+ module.exports = viteReact;
401
+ module.exports["default"] = viteReact;