-
Hey there. I have a scenario where I'd like to create my own code frame based on error information coming from Parcel. When I say "code frame" here, I'm talking about the produced string that contains a snippet of problematic code; I'm not referring to a JS object containing location and code information that is used to produce a code frame. In other words, when an error is thrown from Parcel, I want to take information from that error and pass it through to Babel's code frame package to produce a code frame. You might ask why we're using Babel to create a code frame instead of using the code frame that Parcel provides. The primary reason is that, aside from Parcel, we have a few other actors in our system that can generate errors based on code (babel's parser being one of them, Terser being another). These errors are displayed to users of our build system and we want to produce consistent-looking messages and code frames (as close as possible) to present to users of our build system. Given an error coming from Parcel, I find it a bit burdensome to access what I need in order to create my own code frame. For example, it seems that parcel/packages/core/utils/src/prettyDiagnostic.js Lines 52 to 55 in c4e494f This puts the burden on me, the Parcel consumer, to basically duplicate this code ^^^ in my own code. It would make my life simpler if I could rely on I'm also not really sure if I'm guaranteed that parcel/packages/core/utils/src/prettyDiagnostic.js Lines 48 to 50 in c4e494f I've logged that particular issue here: #5078. Other questions that come up but I haven't found answers for in the docs: Will Thanks for any insights. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
That is actually why we did our own codeframe as well, to normalize Babel's and Terser's codeframe format into one 😉
I remember adding this behaviour and the reason is rather simple: if the function that wants to throw a diagnostic only knows the filepath and not the asset's code, it has to
A "normal" error doesn't have this property. Only if a
According to the Flow types, yes: |
Beta Was this translation helpful? Give feedback.
That is actually why we did our own codeframe as well, to normalize Babel's and Terser's codeframe format into one 😉