@vitejs/plugin-react 1.3.2 → 2.0.0-alpha.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.
@@ -1,9 +1,10 @@
1
- import { restoreJSX } from './restore-jsx'
2
1
  import * as babel from '@babel/core'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { restoreJSX } from './restore-jsx'
3
4
 
4
5
  async function jsx(sourceCode: string) {
5
6
  const [ast] = await restoreJSX(babel, sourceCode, 'test.js')
6
- if (ast === null) {
7
+ if (ast == null) {
7
8
  return ast
8
9
  }
9
10
  const { code } = await babel.transformFromAstAsync(ast, null, {
@@ -7,6 +7,18 @@ let babelRestoreJSX: Promise<PluginItem> | undefined
7
7
 
8
8
  const jsxNotFound: RestoredJSX = [null, false]
9
9
 
10
+ async function getBabelRestoreJSX() {
11
+ if (!babelRestoreJSX)
12
+ babelRestoreJSX = import('./babel-restore-jsx').then((r) => {
13
+ const fn = r.default
14
+ if ('default' in fn)
15
+ // @ts-expect-error
16
+ return fn.default
17
+ return fn
18
+ })
19
+ return babelRestoreJSX
20
+ }
21
+
10
22
  /** Restore JSX from `React.createElement` calls */
11
23
  export async function restoreJSX(
12
24
  babel: typeof babelCore,
@@ -56,8 +68,6 @@ export async function restoreJSX(
56
68
  return jsxNotFound
57
69
  }
58
70
 
59
- babelRestoreJSX ||= import('./babel-restore-jsx')
60
-
61
71
  const result = await babel.transformAsync(code, {
62
72
  babelrc: false,
63
73
  configFile: false,
@@ -67,8 +77,7 @@ export async function restoreJSX(
67
77
  parserOpts: {
68
78
  plugins: ['jsx']
69
79
  },
70
- // @ts-ignore
71
- plugins: [(await babelRestoreJSX).default]
80
+ plugins: [await getBabelRestoreJSX()]
72
81
  })
73
82
 
74
83
  return [result?.ast, isCommonJS]