Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 1 | 'use strict' |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 2 | |
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 3 | class Warning { |
4 | constructor(text, opts = {}) { | ||||
5 | this.type = 'warning' | ||||
6 | this.text = text | ||||
Alex Rudenko | 6c0f161 | 2021-11-05 06:28:44 +0000 | [diff] [blame] | 7 | |
8 | if (opts.node && opts.node.source) { | ||||
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 9 | let pos = opts.node.positionBy(opts) |
10 | this.line = pos.line | ||||
11 | this.column = pos.column | ||||
Alex Rudenko | 6c0f161 | 2021-11-05 06:28:44 +0000 | [diff] [blame] | 12 | } |
13 | |||||
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 14 | for (let opt in opts) this[opt] = opts[opt] |
Alex Rudenko | 6c0f161 | 2021-11-05 06:28:44 +0000 | [diff] [blame] | 15 | } |
Alex Rudenko | 6c0f161 | 2021-11-05 06:28:44 +0000 | [diff] [blame] | 16 | |
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 17 | toString() { |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 18 | if (this.node) { |
19 | return this.node.error(this.text, { | ||||
20 | plugin: this.plugin, | ||||
21 | index: this.index, | ||||
22 | word: this.word | ||||
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 23 | }).message |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 24 | } |
25 | |||||
26 | if (this.plugin) { | ||||
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 27 | return this.plugin + ': ' + this.text |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 28 | } |
29 | |||||
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 30 | return this.text |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 31 | } |
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 32 | } |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 33 | |
Tim van der Lippe | f2ea2c9 | 2021-11-08 10:55:56 +0000 | [diff] [blame] | 34 | module.exports = Warning |
35 | Warning.default = Warning |