warning.js 648 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. class Warning {
  3. constructor(text, opts = {}) {
  4. this.type = 'warning'
  5. this.text = text
  6. if (opts.node && opts.node.source) {
  7. let pos = opts.node.positionBy(opts)
  8. this.line = pos.line
  9. this.column = pos.column
  10. }
  11. for (let opt in opts) this[opt] = opts[opt]
  12. }
  13. toString() {
  14. if (this.node) {
  15. return this.node.error(this.text, {
  16. plugin: this.plugin,
  17. index: this.index,
  18. word: this.word
  19. }).message
  20. }
  21. if (this.plugin) {
  22. return this.plugin + ': ' + this.text
  23. }
  24. return this.text
  25. }
  26. }
  27. module.exports = Warning
  28. Warning.default = Warning