Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c699da

Browse files
authored
fix: avoid loop at call TransformPluginContext#error (#2332)
<!-- Thank you for contributing! --> ### Description close #2326 <!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
1 parent a03a0d7 commit 7c699da

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

packages/rolldown/src/plugin/transform-plugin-context.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
import type { LoggingFunctionWithPosition, RollupError } from '../rollup'
66
import { normalizeLog } from '../log/logHandler'
77
import { PluginContext } from './plugin-context'
8-
import { augmentCodeLocation } from '../log/logs'
8+
import { augmentCodeLocation, error, logPluginError } from '../log/logs'
99
import { PluginContextData } from './plugin-context-data'
1010
import { NormalizedInputOptions } from '..'
1111
import type { Plugin } from './index'
@@ -41,14 +41,14 @@ export class TransformPluginContext extends PluginContext {
4141
this.warn = getLogHandler(this.warn)
4242
this.info = getLogHandler(this.info)
4343
this.error = (
44-
error: RollupError | string,
44+
e: RollupError | string,
4545
pos?: number | { column: number; line: number },
4646
): never => {
47-
if (typeof error === 'string') error = { message: error }
48-
if (pos) augmentCodeLocation(error, pos, moduleSource, moduleId)
49-
error.id = moduleId
50-
error.hook = 'transform'
51-
return this.error(error)
47+
if (typeof e === 'string') e = { message: e }
48+
if (pos) augmentCodeLocation(e, pos, moduleSource, moduleId)
49+
e.id = moduleId
50+
e.hook = 'transform'
51+
return error(logPluginError(normalizeLog(e), plugin.name || 'unknown'))
5252
}
5353
// this.getCombinedSourcemap = () => JSON.parse(inner.getCombinedSourcemap())
5454
}

packages/rolldown/tests/plugin/plugin.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,24 @@ describe('Plugin closeBundle hook', async () => {
105105
}
106106
})
107107
})
108+
109+
test('call transformContext error', async () => {
110+
try {
111+
const build = await rolldown({
112+
input: './main.js',
113+
cwd: import.meta.dirname,
114+
plugins: [
115+
{
116+
transform() {
117+
this.error('transform hook error')
118+
},
119+
},
120+
],
121+
})
122+
await build.write({})
123+
} catch (error: any) {
124+
expect(error.message).toMatchInlineSnapshot(
125+
`"Rolldown internal error: GenericFailure, RollupError: transform hook error"`,
126+
)
127+
}
128+
})

0 commit comments

Comments
 (0)