1 | module.exports = { remapMessages }
|
2 |
|
3 | function remapMessages(messages, hasBOM, codePart) {
|
4 | const newMessages = []
|
5 |
|
6 | for (const message of messages) {
|
7 | if (remapMessage(message, hasBOM, codePart)) {
|
8 | newMessages.push(message)
|
9 | }
|
10 | }
|
11 |
|
12 | return newMessages
|
13 | }
|
14 |
|
15 | function remapMessage(message, hasBOM, codePart) {
|
16 | if (!message.line || !message.column) {
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | return true
|
24 | }
|
25 |
|
26 | const location = codePart.originalLocation({
|
27 | line: message.line,
|
28 | column: message.column,
|
29 | })
|
30 |
|
31 |
|
32 | if (!location) {
|
33 | return false
|
34 | }
|
35 |
|
36 | Object.assign(message, location)
|
37 | message.source = codePart.getOriginalLine(location.line)
|
38 |
|
39 |
|
40 | if (message.fix && message.fix.range) {
|
41 | const bomOffset = hasBOM ? -1 : 0
|
42 | message.fix.range = [
|
43 | codePart.originalIndex(message.fix.range[0]) + bomOffset,
|
44 |
|
45 |
|
46 | codePart.originalIndex(message.fix.range[1] - 1) + 1 + bomOffset,
|
47 | ]
|
48 | }
|
49 |
|
50 |
|
51 | if (message.endLine && message.endColumn) {
|
52 | const endLocation = codePart.originalLocation({
|
53 | line: message.endLine,
|
54 | column: message.endColumn,
|
55 | })
|
56 | if (endLocation) {
|
57 | message.endLine = endLocation.line
|
58 | message.endColumn = endLocation.column
|
59 | }
|
60 | }
|
61 |
|
62 | return true
|
63 | }
|