3 var stringify = require('unist-util-stringify-position')
5 module.exports = VMessage
7 // Inherit from `Error#`.
8 function VMessagePrototype() {}
9 VMessagePrototype.prototype = Error.prototype
10 VMessage.prototype = new VMessagePrototype()
12 // Message properties.
13 var proto = VMessage.prototype
24 // Construct a new VMessage.
26 // Note: We cannot invoke `Error` on the created context, as that adds readonly
27 // `line` and `column` attributes on Safari 9, thus throwing and failing the
29 function VMessage(reason, position, origin) {
34 if (typeof position === 'string') {
39 parts = parseOrigin(origin)
40 range = stringify(position) || '1:1'
43 start: {line: null, column: null},
44 end: {line: null, column: null}
48 if (position && position.position) {
49 position = position.position
56 position = position.start
59 location.start = position
64 this.stack = reason.stack
65 reason = reason.message
71 this.line = position ? position.line : null
72 this.column = position ? position.column : null
73 this.location = location
74 this.source = parts[0]
75 this.ruleId = parts[1]
78 function parseOrigin(origin) {
79 var result = [null, null]
82 if (typeof origin === 'string') {
83 index = origin.indexOf(':')
88 result[0] = origin.slice(0, index)
89 result[1] = origin.slice(index + 1)