fix(ssr): format ssrTransform parse error #18644
Conversation
ssrTransform parse error
| err.id = url | ||
| err.loc = numberToPos(code, err.pos) | ||
| err.loc.file = url | ||
| err.frame = generateCodeFrame(code, err.pos) |
There was a problem hiding this comment.
I don't know when err.loc exsits (when it passes the previous code path) though.
There was a problem hiding this comment.
Right, it looks better to keep Parse failure: ... for clarity. I remembered esbuild transform error also includes location details in its message (cf. #18626).
I don't know when
err.locexsits (when it passes the previous code path) though.
Probably loc check was for acorn based parser error, so it's no longer relevant. Since Rollup 4, it now only has code, message, pos properties https://github.com/rollup/rollup/blob/42e587e0e37bc0661aa39fe7ad6f1d7fd33f825c/src/utils/bufferToAst.ts#L20-L22, so we only need to target these. It looks like pos is missing on rust side panic, so I covered that case too.
There was a problem hiding this comment.
Thanks for checking! That makes sense.
packages/vite/src/node/ssr/__tests__/__snapshots__/ssrLoadModule.spec.ts.snap
Outdated
Show resolved
Hide resolved
packages/vite/src/node/ssr/__tests__/__snapshots__/ssrLoadModule.spec.ts.snap
Outdated
Show resolved
Hide resolved
Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Bjorn Lu <[email protected]>
Description
(Recreated #18621 as I force-pushed the branch and Github won't let me reopen it)
It looks like this parse error handling code is obsolete and does nothing for current rollup parse error. For non-js file, esbuild transform in plugin pipeline normally catches a syntax error, but for js file,
ssrTransformneeds to throw an error. SincessrTransformis outside of transform plugin pipeline,Error.posdoesn't get prettified automatically, so I added a error processing inside the try/catch.reproduction: https://stackblitz.com/edit/vitest-dev-vitest-wpj5mg?file=vite.config.ts
Screenshots