1 | import { FilePosition } from './input.js'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export interface RangePosition {
|
7 | |
8 |
|
9 |
|
10 | line: number
|
11 |
|
12 | |
13 |
|
14 |
|
15 | column: number
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export default class CssSyntaxError {
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | constructor(
|
61 | message: string,
|
62 | lineOrStartPos?: number | RangePosition,
|
63 | columnOrEndPos?: number | RangePosition,
|
64 | source?: string,
|
65 | file?: string,
|
66 | plugin?: string
|
67 | )
|
68 |
|
69 | stack: string
|
70 |
|
71 | /**
|
72 | * Always equal to `'CssSyntaxError'`. You should always check error type
|
73 | * by `error.name === 'CssSyntaxError'`
|
74 | * instead of `error instanceof CssSyntaxError`,
|
75 | * because npm could have several PostCSS versions.
|
76 | *
|
77 | * ```js
|
78 | * if (error.name === 'CssSyntaxError') {
|
79 | * error
|
80 | * }
|
81 | * ```
|
82 | */
|
83 | name: 'CssSyntaxError'
|
84 |
|
85 | /**
|
86 | * Error message.
|
87 | *
|
88 | * ```js
|
89 | * error.message
|
90 | * ```
|
91 | */
|
92 | reason: string
|
93 |
|
94 | /**
|
95 | * Full error text in the GNU error format
|
96 | * with plugin, file, line and column.
|
97 | *
|
98 | * ```js
|
99 | * error.message
|
100 | * ```
|
101 | */
|
102 | message: string
|
103 |
|
104 | /**
|
105 | * Absolute path to the broken file.
|
106 | *
|
107 | * ```js
|
108 | * error.file
|
109 | * error.input.file
|
110 | * ```
|
111 | *
|
112 | * PostCSS will use the input source map to detect the original location.
|
113 | * If you need the position in the PostCSS input, use `error.input.file`.
|
114 | */
|
115 | file?: string
|
116 |
|
117 | /**
|
118 | * Source line of the error.
|
119 | *
|
120 | * ```js
|
121 | * error.line
|
122 | * error.input.line
|
123 | * ```
|
124 | *
|
125 | * PostCSS will use the input source map to detect the original location.
|
126 | * If you need the position in the PostCSS input, use `error.input.line`.
|
127 | */
|
128 | line?: number
|
129 |
|
130 | /**
|
131 | * Source column of the error.
|
132 | *
|
133 | * ```js
|
134 | * error.column
|
135 | * error.input.column
|
136 | * ```
|
137 | *
|
138 | * PostCSS will use the input source map to detect the original location.
|
139 | * If you need the position in the PostCSS input, use `error.input.column`.
|
140 | */
|
141 | column?: number
|
142 |
|
143 | /**
|
144 | * Source line of the error's end, exclusive. Provided if the error pertains
|
145 | * to a range.
|
146 | *
|
147 | * ```js
|
148 | * error.endLine
|
149 | * error.input.endLine
|
150 | * ```
|
151 | *
|
152 | * PostCSS will use the input source map to detect the original location.
|
153 | * If you need the position in the PostCSS input, use `error.input.endLine`.
|
154 | */
|
155 | endLine?: number
|
156 |
|
157 | /**
|
158 | * Source column of the error's end, exclusive. Provided if the error pertains
|
159 | * to a range.
|
160 | *
|
161 | * ```js
|
162 | * error.endColumn
|
163 | * error.input.endColumn
|
164 | * ```
|
165 | *
|
166 | * PostCSS will use the input source map to detect the original location.
|
167 | * If you need the position in the PostCSS input, use `error.input.endColumn`.
|
168 | */
|
169 | endColumn?: number
|
170 |
|
171 | /**
|
172 | * Source code of the broken file.
|
173 | *
|
174 | * ```js
|
175 | * error.source
|
176 | * error.input.source
|
177 | * ```
|
178 | */
|
179 | source?: string
|
180 |
|
181 | /**
|
182 | * Plugin name, if error came from plugin.
|
183 | *
|
184 | * ```js
|
185 | * error.plugin
|
186 | * ```
|
187 | */
|
188 | plugin?: string
|
189 |
|
190 | /**
|
191 | * Input object with PostCSS internal information
|
192 | * about input file. If input has source map
|
193 | * from previous tool, PostCSS will use origin
|
194 | * (for example, Sass) source. You can use this
|
195 | * object to get PostCSS input source.
|
196 | *
|
197 | * ```js
|
198 | * error.input.file
|
199 | * error.file
|
200 | * ```
|
201 | */
|
202 | input?: FilePosition
|
203 |
|
204 | /**
|
205 | * Returns error position, message and source code of the broken part.
|
206 | *
|
207 | * ```js
|
208 | * error.toString()
|
209 | *
|
210 | *
|
211 | * ```
|
212 | *
|
213 | * @return Error position, message and source code.
|
214 | */
|
215 | toString(): string
|
216 |
|
217 | /**
|
218 | * Returns a few lines of CSS source that caused the error.
|
219 | *
|
220 | * If the CSS has an input source map without `sourceContent`,
|
221 | * this method will return an empty string.
|
222 | *
|
223 | * ```js
|
224 | * error.showSourceCode()
|
225 | *
|
226 | *
|
227 | *
|
228 | *
|
229 | *
|
230 | * ```
|
231 | *
|
232 | * @param color Whether arrow will be colored red by terminal
|
233 | * color codes. By default, PostCSS will detect
|
234 | * color support by `process.stdout.isTTY`
|
235 | * and `process.env.NODE_DISABLE_COLORS`.
|
236 | * @return Few lines of CSS source that caused the error.
|
237 | */
|
238 | showSourceCode(color?: boolean): string
|
239 | }
|
240 |
|
\ | No newline at end of file |