Skip to content

Commit 14189d9

Browse files
committed
chore: handle oxc errors
1 parent 36c73dd commit 14189d9

File tree

1 file changed

+24
-2
lines changed
  • packages/vite/src/node/plugins

1 file changed

+24
-2
lines changed

packages/vite/src/node/plugins/oxc.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import type { RawSourceMap } from '@ampproject/remapping'
88
import type { SourceMap } from 'rolldown'
99
import type { FSWatcher } from 'dep-types/chokidar'
1010
import { TSConfckParseError } from 'tsconfck'
11-
import { combineSourcemaps, createFilter, ensureWatchedFile } from '../utils'
11+
import type { RollupError } from 'rollup'
12+
import {
13+
combineSourcemaps,
14+
createFilter,
15+
ensureWatchedFile,
16+
generateCodeFrame,
17+
} from '../utils'
1218
import type { ResolvedConfig } from '../config'
1319
import type { Plugin, PluginContext } from '../plugin'
1420
import { cleanUrl } from '../../shared/utils'
@@ -158,7 +164,23 @@ export async function transformWithOxc(
158164
const result = transform(filename, code, resolvedOptions)
159165

160166
if (result.errors.length > 0) {
161-
throw new Error(result.errors[0])
167+
const firstError = result.errors[0]
168+
const error: RollupError = new Error(firstError.message)
169+
let frame = ''
170+
frame += firstError.labels
171+
.map(
172+
(l) =>
173+
(l.message ? `${l.message}\n` : '') +
174+
generateCodeFrame(code, l.start, l.end),
175+
)
176+
.join('\n')
177+
if (firstError.helpMessage) {
178+
frame += '\n' + firstError.helpMessage
179+
}
180+
error.frame = frame
181+
error.pos =
182+
firstError.labels.length > 0 ? firstError.labels[0].start : undefined
183+
throw error
162184
}
163185

164186
let map: SourceMap

0 commit comments

Comments
 (0)