@@ -8,7 +8,13 @@ import type { RawSourceMap } from '@ampproject/remapping'
8
8
import type { SourceMap } from 'rolldown'
9
9
import type { FSWatcher } from 'dep-types/chokidar'
10
10
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'
12
18
import type { ResolvedConfig } from '../config'
13
19
import type { Plugin , PluginContext } from '../plugin'
14
20
import { cleanUrl } from '../../shared/utils'
@@ -158,7 +164,23 @@ export async function transformWithOxc(
158
164
const result = transform ( filename , code , resolvedOptions )
159
165
160
166
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
162
184
}
163
185
164
186
let map : SourceMap
0 commit comments