index.js 1010 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict'
  2. var VMessage = require('vfile-message')
  3. var VFile = require('./core.js')
  4. module.exports = VFile
  5. var proto = VFile.prototype
  6. proto.message = message
  7. proto.info = info
  8. proto.fail = fail
  9. // Create a message with `reason` at `position`.
  10. // When an error is passed in as `reason`, copies the stack.
  11. function message(reason, position, origin) {
  12. var filePath = this.path
  13. var message = new VMessage(reason, position, origin)
  14. if (filePath) {
  15. message.name = filePath + ':' + message.name
  16. message.file = filePath
  17. }
  18. message.fatal = false
  19. this.messages.push(message)
  20. return message
  21. }
  22. // Fail: creates a vmessage, associates it with the file, and throws it.
  23. function fail() {
  24. var message = this.message.apply(this, arguments)
  25. message.fatal = true
  26. throw message
  27. }
  28. // Info: creates a vmessage, associates it with the file, and marks the fatality
  29. // as null.
  30. function info() {
  31. var message = this.message.apply(this, arguments)
  32. message.fatal = null
  33. return message
  34. }