If I'm reading the documentation right, it states that on a code frame, codeHighlights should be an array of code highlight objects. This seems to be true some of the time, but at other times, a code frame within a diagnostic within an error will contain codeHighlights whose value is a single code highlight object. This inconsistency makes handling code highlights objects on errors more complex than it really needs to be.
I have this set up as an isolated repo here: https://github.com/Aaronius/parcel2bug/tree/code-highlights. Just follow the readme.
.babelrc:
{
"bundler": "@parcel/bundler-default",
"transformers": {
"*.js": ["@parcel/transformer-babel","@parcel/transformer-js"]
},
"runtimes": {
"browser": ["@parcel/runtime-js"]
},
"packagers": {
"*.js": "@parcel/packager-js"
},
"namers": ["@parcel/namer-default"],
"resolvers": ["@parcel/resolver-default"],
"reporters": ["@parcel/reporter-cli"]
}
package.json:
{
"name": "parcel2bug",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"parcel": "^2.0.0-nightly.385"
}
}
build call:
const bundler = new Parcel({
entries: path.join(__dirname, 'src/index.js'),
sourceMaps: false,
patchConsole: false,
autoinstall: false,
scopeHoist: true,
disableCache: true,
inputFS,
outputFS,
workerFarm,
distDir: VIRTUAL_DIST_DIR,
});
await bundler.run();
codeHighlights should always be an array.
codeHighlights is sometimes an object.
Always make codeHighlights an array.
We're doing some custom error handling and manipulation in order to present a specifically crafted error message to users of our build service.
https://github.com/Aaronius/parcel2bug/tree/code-highlights. Just follow the readme.
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-nightly.385
| Node | 12.12.0
| npm/Yarn | npm 6.13.4
| Operating System | Mac Mojave
This is not really a bug, both array and single value are allowed, this was to create a simpler API but in the end it actually made it more complex as you've mentioned... I should probably require an array everywhere.
Will update this
Most helpful comment
This is not really a bug, both array and single value are allowed, this was to create a simpler API but in the end it actually made it more complex as you've mentioned... I should probably require an array everywhere.
Will update this