-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest-jsx.mjs
More file actions
22 lines (19 loc) · 635 Bytes
/
test-jsx.mjs
File metadata and controls
22 lines (19 loc) · 635 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { parse } from '@babel/parser'
const code = '<div className="bg-red-500 text-white">Hello</div>'
console.log('Testing without jsx plugin:')
try {
const ast1 = parse(code, { sourceType: 'module' })
console.log('✓ Parsed without jsx plugin')
}
catch (e) {
console.log('✗ Failed:', e.code || e.message.split('\n')[0])
}
console.log('\nTesting with jsx plugin:')
try {
const ast2 = parse(code, { sourceType: 'module', plugins: ['jsx'] })
console.log('✓ Parsed with jsx plugin')
console.log('AST type:', ast2.program.body[0].type)
}
catch (e) {
console.log('✗ Failed:', e.code || e.message.split('\n')[0])
}