Parcel: `codeHighlights` is sometimes an object and sometimes an array of objects

Created on 27 Aug 2020  ยท  1Comment  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

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.

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

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();

๐Ÿค” Expected Behavior

codeHighlights should always be an array.

๐Ÿ˜ฏ Current Behavior

codeHighlights is sometimes an object.

๐Ÿ’ Possible Solution

Always make codeHighlights an array.

๐Ÿ”ฆ Context

We're doing some custom error handling and manipulation in order to present a specifically crafted error message to users of our build service.

๐Ÿ’ป Code Sample

https://github.com/Aaronius/parcel2bug/tree/code-highlights. Just follow the readme.

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-nightly.385
| Node | 12.12.0
| npm/Yarn | npm 6.13.4
| Operating System | Mac Mojave

Bug โœจ Parcel 2

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

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings