|
1 |
| -import fs from 'node:fs' |
| 1 | +import fs from 'node:fs/promises' |
2 | 2 | import path from 'node:path'
|
3 |
| -import babel from '@babel/core' |
4 |
| -import {Parser} from 'acorn' |
5 | 3 | import acornJsx from 'acorn-jsx'
|
6 |
| -import {generate} from 'astring' |
| 4 | +import {fromJs} from 'esast-util-from-js' |
| 5 | +import {toJs} from 'estree-util-to-js' |
7 | 6 | import {buildJsx} from 'estree-util-build-jsx'
|
8 | 7 |
|
9 |
| -const doc = String(fs.readFileSync(path.join('test', 'jsx.jsx'))) |
| 8 | +const doc = String(await fs.readFile(path.join('test', 'jsx.jsx'))) |
10 | 9 |
|
11 |
| -fs.writeFileSync( |
| 10 | +await fs.writeFile( |
12 | 11 | path.join('test', 'jsx-build-jsx-classic.js'),
|
13 |
| - generate( |
| 12 | + toJs( |
14 | 13 | buildJsx(
|
15 |
| - // @ts-expect-error Acorn nodes are assignable to ESTree nodes. |
16 |
| - Parser.extend(acornJsx()).parse( |
17 |
| - doc.replace(/'name'/, "'jsx (estree-util-build-jsx, classic)'"), |
18 |
| - {sourceType: 'module', ecmaVersion: 2021} |
19 |
| - ), |
| 14 | + fromJs(doc.replace(/'name'/, "'jsx (estree-util-build-jsx, classic)'"), { |
| 15 | + plugins: [acornJsx()], |
| 16 | + module: true |
| 17 | + }), |
20 | 18 | {pragma: 'h', pragmaFrag: 'null'}
|
21 | 19 | )
|
22 |
| - ) |
| 20 | + ).value |
23 | 21 | )
|
24 | 22 |
|
25 |
| -fs.writeFileSync( |
| 23 | +await fs.writeFile( |
26 | 24 | path.join('test', 'jsx-build-jsx-automatic.js'),
|
27 |
| - generate( |
| 25 | + toJs( |
28 | 26 | buildJsx(
|
29 |
| - // @ts-expect-error Acorn nodes are assignable to ESTree nodes. |
30 |
| - Parser.extend(acornJsx()).parse( |
| 27 | + fromJs( |
31 | 28 | doc.replace(/'name'/, "'jsx (estree-util-build-jsx, automatic)'"),
|
32 |
| - {sourceType: 'module', ecmaVersion: 2021} |
| 29 | + {plugins: [acornJsx()], module: true} |
33 | 30 | ),
|
34 |
| - {runtime: 'automatic', importSource: '.'} |
| 31 | + {runtime: 'automatic', importSource: 'hastscript'} |
35 | 32 | )
|
36 |
| - ).replace(/\/jsx-runtime(?=["'])/g, './lib/runtime-html.js') |
37 |
| -) |
38 |
| - |
39 |
| -fs.writeFileSync( |
40 |
| - path.join('test', 'jsx-babel-automatic.js'), |
41 |
| - // @ts-expect-error Result always given. |
42 |
| - babel |
43 |
| - .transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { |
44 |
| - plugins: [ |
45 |
| - [ |
46 |
| - '@babel/plugin-transform-react-jsx', |
47 |
| - {runtime: 'automatic', importSource: '.'} |
48 |
| - ] |
49 |
| - ] |
50 |
| - }) |
51 |
| - .code.replace(/\/jsx-runtime(?=["'])/g, './lib/runtime-html.js') |
| 33 | + ).value |
52 | 34 | )
|
0 commit comments