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