Skip to content

Commit

Permalink
Add support for passing VFileMessage in types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 17, 2022
1 parent 87c8401 commit 0739c72
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class VFileMessage extends Error {
* Create a message for `reason` at `place` from `origin`.
* When an error is passed in as `reason`, the `stack` is copied.
*
* @param {string|Error} reason
* @param {string|Error|VFileMessage} reason
* Reason for message.
* Uses the stack and message of the error if given.
* @param {Node|NodeLike|Position|Point} [place]
Expand Down Expand Up @@ -70,8 +70,14 @@ export class VFileMessage extends Error {

// Fields from `Error`
this.name = stringifyPosition(place) || '1:1'
/** @type {string} */
this.message = typeof reason === 'object' ? reason.message : reason
this.stack = typeof reason === 'object' ? reason.stack : ''
/** @type {string} */
this.stack = ''

if (typeof reason === 'object' && reason.stack) {
this.stack = reason.stack
}

/**
* Reason for message.
Expand Down

0 comments on commit 0739c72

Please sign in to comment.