parcel-bundler/parcel

Normalize code frames on thrown errors so that `code` always exists

开放

#5,115 创建于 2020年9月8日

 (3 条评论) (0 个反应) (0 位负责人)JavaScript (2,274 个派生)batch import
:raising_hand_woman: FeatureGood First Issue✨ Parcel 2

仓库指标

星标
 (44,030 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

🙋 feature request

When using the Parcel API and an error is thrown, there's no guarantee that error.diagnostics.*.codeFrame.code exists. If it doesn't then the consumer of the API has to duplicate this logic to retrieve the code pertaining to the code frame:

https://github.com/parcel-bundler/parcel/blob/c4e494f3b9fd0eac672edc1a27c6c9216182dd6b/packages/core/utils/src/prettyDiagnostic.js#L52-L55

This is kind of a pain. I would love to see Parcel normalize these errors so that when a consumer receives a code frame on an error, the code property always exists and the consumer doesn't have to bother with reading source files directly.

🤔 Expected Behavior

I would expect the code property to always exists on any code frame being reported by Parcel.

😯 Current Behavior

The code property only sometimes exists on a code frame.

💁 Possible Solution

If a plugin doesn't provide the code property, Parcel could add it before the error makes its way to the Parcel consumer.

🔦 Context

This is described in further detail in https://github.com/parcel-bundler/parcel/discussions/5081.

💻 Examples

贡献者指南