-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fix(ssr): format ssrTransform parse error
#18644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know when err.loc exsits (when it passes the previous code path) though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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