source: frontend/node_modules/postcss/lib/css-syntax-error.d.ts@ 9af201e

Last change on this file since 9af201e was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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