|
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' |
| 4 | +import {fromJs} from 'esast-util-from-js' |
6 | 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 | 12 | toJs( |
14 | | - // @ts-expect-error it’s a program. |
15 | 13 | buildJsx( |
16 | | - // @ts-expect-error Acorn nodes are assignable to ESTree nodes. |
17 | | - Parser.extend(acornJsx()).parse( |
18 | | - doc.replace(/'name'/, "'jsx (estree-util-build-jsx, classic)'"), |
19 | | - // Note: different npms resolve this differently, so it may break or work, hence the ignore. |
20 | | - // @ts-ignore Hush, `2021` is fine. |
21 | | - {sourceType: 'module', ecmaVersion: 2021} |
22 | | - ), |
| 14 | + fromJs(doc.replace(/'name'/, "'jsx (estree-util-build-jsx, classic)'"), { |
| 15 | + plugins: [acornJsx()], |
| 16 | + module: true |
| 17 | + }), |
23 | 18 | {pragma: 'x', pragmaFrag: 'null'} |
24 | 19 | ) |
25 | | - // @ts-expect-error Some bug in `to-js` |
26 | 20 | ).value |
27 | 21 | ) |
28 | 22 |
|
29 | | -fs.writeFileSync( |
| 23 | +await fs.writeFile( |
30 | 24 | path.join('test', 'jsx-build-jsx-automatic.js'), |
31 | 25 | toJs( |
32 | | - // @ts-expect-error it’s a program. |
33 | 26 | buildJsx( |
34 | | - // @ts-expect-error Acorn nodes are assignable to ESTree nodes. |
35 | | - Parser.extend(acornJsx()).parse( |
| 27 | + fromJs( |
36 | 28 | doc.replace(/'name'/, "'jsx (estree-util-build-jsx, automatic)'"), |
37 | | - // Note: different npms resolve this differently, so it may break or work, hence the ignore. |
38 | | - // @ts-ignore Hush, `2021` is fine. |
39 | | - {sourceType: 'module', ecmaVersion: 2021} |
| 29 | + {plugins: [acornJsx()], module: true} |
40 | 30 | ), |
41 | 31 | {runtime: 'automatic', importSource: 'xastscript'} |
42 | 32 | ) |
43 | | - // @ts-expect-error Some bug in `to-js` |
44 | 33 | ).value |
45 | 34 | ) |
46 | 35 |
|
47 | | -fs.writeFileSync( |
| 36 | +await fs.writeFile( |
48 | 37 | path.join('test', 'jsx-build-jsx-automatic-development.js'), |
49 | 38 | toJs( |
50 | | - // @ts-expect-error it’s a program. |
51 | 39 | buildJsx( |
52 | | - // @ts-expect-error Acorn nodes are assignable to ESTree nodes. |
53 | | - Parser.extend(acornJsx()).parse( |
54 | | - doc.replace(/'name'/, "'jsx (estree-util-build-jsx, automatic)'"), |
55 | | - {sourceType: 'module', ecmaVersion: 2021} |
| 40 | + fromJs( |
| 41 | + doc.replace( |
| 42 | + /'name'/, |
| 43 | + "'jsx (estree-util-build-jsx, automatic, development)'" |
| 44 | + ), |
| 45 | + {plugins: [acornJsx()], module: true} |
56 | 46 | ), |
57 | 47 | {runtime: 'automatic', importSource: 'xastscript', development: true} |
58 | 48 | ) |
59 | | - // @ts-expect-error Some bug in `to-js` |
60 | 49 | ).value |
61 | 50 | ) |
62 | | - |
63 | | -fs.writeFileSync( |
64 | | - path.join('test', 'jsx-babel-automatic.js'), |
65 | | - // @ts-expect-error Result always given. |
66 | | - babel.transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { |
67 | | - plugins: [ |
68 | | - [ |
69 | | - '@babel/plugin-transform-react-jsx', |
70 | | - {runtime: 'automatic', importSource: 'xastscript'} |
71 | | - ] |
72 | | - ] |
73 | | - }).code |
74 | | -) |
75 | | - |
76 | | -fs.writeFileSync( |
77 | | - path.join('test', 'jsx-babel-automatic-development.js'), |
78 | | - // @ts-expect-error Result always given. |
79 | | - babel.transformSync(doc.replace(/'name'/, "'jsx (babel, automatic)'"), { |
80 | | - plugins: [ |
81 | | - [ |
82 | | - '@babel/plugin-transform-react-jsx', |
83 | | - {runtime: 'automatic', importSource: 'xastscript', development: true} |
84 | | - ] |
85 | | - ] |
86 | | - }).code |
87 | | -) |
0 commit comments