Skip to content

Commit 07800de

Browse files
authored
fix(transformer-attributify-jsx): improve error message (#5156)
1 parent c55339c commit 07800de

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

packages-presets/transformer-attributify-jsx/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function transformerAttributifyJsx(options: TransformerAttributif
9898
}
9999
catch (error) {
100100
console.warn(
101-
`[@unocss/transformer-attributify-jsx]: Oxc resolver failed for "${id}", falling back to regex resolver:`,
101+
`[@unocss/transformer-attributify-jsx]: Oxc resolver failed for "${id}", falling back to regex resolver:\n`,
102102
error,
103103
)
104104
await attributifyJsxRegexResolver(params)

packages-presets/transformer-attributify-jsx/src/resolver/oxc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function attributifyJsxOxcResolver(params: AttributifyResolverParam
1010
})
1111

1212
if (ast.errors?.length) {
13-
throw new Error(`Oxc parse errors:\n${ast.errors.join('\n')}`)
13+
throw new Error(`Oxc parse errors:\n${ast.errors.map(err => err.codeframe ?? err.helpMessage ?? err.message).join(('\n'))}`)
1414
}
1515

1616
walk(ast.program, {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createGenerator } from '@unocss/core'
2+
import MagicString from 'magic-string'
3+
import { describe, expect, it } from 'vitest'
4+
import { attributifyJsxOxcResolver } from '../src/resolver/oxc'
5+
6+
describe('resolver-oxc', async () => {
7+
const uno = await createGenerator()
8+
9+
it('error', async () => {
10+
const errorCode = '<d iv></div>'
11+
const code = new MagicString(errorCode)
12+
const transform = attributifyJsxOxcResolver({ code, id: 'app.tsx', uno: { uno, tokens: new Set() } as any, isBlocked: () => false })
13+
await expect(transform).rejects.toThrowErrorMatchingInlineSnapshot(`
14+
[Error: Oxc parse errors:
15+
16+
x Expected corresponding JSX closing tag for 'd'.
17+
,-[app.tsx:1:9]
18+
1 | <d iv></div>
19+
: | ^|^
20+
: | \`-- Expected \`</d>\`
21+
: \`-- Opened here
22+
\`----
23+
]
24+
`)
25+
})
26+
})

0 commit comments

Comments
 (0)