123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- import {stringifyPosition} from 'unist-util-stringify-position'
- export class VFileMessage extends Error {
-
-
- constructor(causeOrReason, optionsOrParentOrPlace, origin) {
- super()
- if (typeof optionsOrParentOrPlace === 'string') {
- origin = optionsOrParentOrPlace
- optionsOrParentOrPlace = undefined
- }
-
- let reason = ''
-
- let options = {}
- let legacyCause = false
- if (optionsOrParentOrPlace) {
-
- if (
- 'line' in optionsOrParentOrPlace &&
- 'column' in optionsOrParentOrPlace
- ) {
- options = {place: optionsOrParentOrPlace}
- }
-
- else if (
- 'start' in optionsOrParentOrPlace &&
- 'end' in optionsOrParentOrPlace
- ) {
- options = {place: optionsOrParentOrPlace}
- }
-
- else if ('type' in optionsOrParentOrPlace) {
- options = {
- ancestors: [optionsOrParentOrPlace],
- place: optionsOrParentOrPlace.position
- }
- }
-
- else {
- options = {...optionsOrParentOrPlace}
- }
- }
- if (typeof causeOrReason === 'string') {
- reason = causeOrReason
- }
-
- else if (!options.cause && causeOrReason) {
- legacyCause = true
- reason = causeOrReason.message
- options.cause = causeOrReason
- }
- if (!options.ruleId && !options.source && typeof origin === 'string') {
- const index = origin.indexOf(':')
- if (index === -1) {
- options.ruleId = origin
- } else {
- options.source = origin.slice(0, index)
- options.ruleId = origin.slice(index + 1)
- }
- }
- if (!options.place && options.ancestors && options.ancestors) {
- const parent = options.ancestors[options.ancestors.length - 1]
- if (parent) {
- options.place = parent.position
- }
- }
- const start =
- options.place && 'start' in options.place
- ? options.place.start
- : options.place
-
-
- this.ancestors = options.ancestors || undefined
-
- this.cause = options.cause || undefined
-
- this.column = start ? start.column : undefined
-
- this.fatal = undefined
-
- this.file
-
-
- this.message = reason
-
- this.line = start ? start.line : undefined
-
-
- this.name = stringifyPosition(options.place) || '1:1'
-
- this.place = options.place || undefined
-
- this.reason = this.message
-
- this.ruleId = options.ruleId || undefined
-
- this.source = options.source || undefined
-
-
- this.stack =
- legacyCause && options.cause && typeof options.cause.stack === 'string'
- ? options.cause.stack
- : ''
-
-
-
-
- this.actual
-
- this.expected
-
- this.note
-
- this.url
-
- }
- }
- VFileMessage.prototype.file = ''
- VFileMessage.prototype.name = ''
- VFileMessage.prototype.reason = ''
- VFileMessage.prototype.message = ''
- VFileMessage.prototype.stack = ''
- VFileMessage.prototype.column = undefined
- VFileMessage.prototype.line = undefined
- VFileMessage.prototype.ancestors = undefined
- VFileMessage.prototype.cause = undefined
- VFileMessage.prototype.fatal = undefined
- VFileMessage.prototype.place = undefined
- VFileMessage.prototype.ruleId = undefined
- VFileMessage.prototype.source = undefined
|