CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
css-syntax-error.d.ts248 linesDownload Raw Back to lib
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: number12 13    /**14     * The line number in the input.15     */16    line: number17  }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 using26 * 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 input33 * (e.g., to debug the previous compiler), use `error.input.file`.34 *35 * ```js36 * // Raising error from plugin37 * throw node.error('Unknown variable', { plugin: 'postcss-vars' })38 * ```39 *40 * ```js41 * // Catching and checking syntax error42 * try {43 *   postcss.parse('a{')44 * } catch (error) {45 *   if (error.name === 'CssSyntaxError') {46 *     error //=> CssSyntaxError47 *   }48 * }49 * ```50 */51declare class CssSyntaxError_ extends Error {52  /**53   * Source column of the error.54   *55   * ```js56   * error.column       //=> 157   * error.input.column //=> 458   * ```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?: number64 65  /**66   * Source column of the error's end, exclusive. Provided if the error pertains67   * to a range.68   *69   * ```js70   * error.endColumn       //=> 171   * error.input.endColumn //=> 472   * ```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?: number78 79  /**80   * Source line of the error's end, exclusive. Provided if the error pertains81   * to a range.82   *83   * ```js84   * error.endLine       //=> 385   * error.input.endLine //=> 486   * ```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?: number92 93  /**94   * Absolute path to the broken file.95   *96   * ```js97   * 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?: string105 106  /**107   * Input object with PostCSS internal information108   * about input file. If input has source map109   * from previous tool, PostCSS will use origin110   * (for example, Sass) source. You can use this111   * object to get PostCSS input source.112   *113   * ```js114   * error.input.file //=> 'a.css'115   * error.file       //=> 'a.sass'116   * ```117   */118  input?: FilePosition119 120  /**121   * Source line of the error.122   *123   * ```js124   * error.line       //=> 2125   * error.input.line //=> 4126   * ```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?: number132 133  /**134   * Full error text in the GNU error format135   * with plugin, file, line and column.136   *137   * ```js138   * error.message //=> 'a.css:1:1: Unclosed block'139   * ```140   */141  message: string142 143  /**144   * Always equal to `'CssSyntaxError'`. You should always check error type145   * by `error.name === 'CssSyntaxError'`146   * instead of `error instanceof CssSyntaxError`,147   * because npm could have several PostCSS versions.148   *149   * ```js150   * if (error.name === 'CssSyntaxError') {151   *   error //=> CssSyntaxError152   * }153   * ```154   */155  name: 'CssSyntaxError'156 157  /**158   * Plugin name, if error came from plugin.159   *160   * ```js161   * error.plugin //=> 'postcss-vars'162   * ```163   */164  plugin?: string165 166  /**167   * Error message.168   *169   * ```js170   * error.message //=> 'Unclosed block'171   * ```172   */173  reason: string174 175  /**176   * Source code of the broken file.177   *178   * ```js179   * error.source       //=> 'a { b {} }'180   * error.input.source //=> 'a b { }'181   * ```182   */183  source?: string184 185  stack: string186 187  /**188   * Instantiates a CSS syntax error. Can be instantiated for a single position189   * or for a range.190   * @param message        Error message.191   * @param lineOrStartPos If for a single position, the line number, or if for192   *                       a range, the inclusive start position of the error.193   * @param columnOrEndPos If for a single position, the column number, or if for194   *                       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?: string206  )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   * ```js215   * error.showSourceCode() //=> "  4 | }216   *                        //      5 | a {217   *                        //    > 6 |   bad218   *                        //        |   ^219   *                        //      7 | }220   *                        //      8 | b {"221   * ```222   *223   * @param color Whether arrow will be colored red by terminal224   *              color codes. By default, PostCSS will detect225   *              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): string230 231  /**232   * Returns error position, message and source code of the broken part.233   *234   * ```js235   * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block236   *                  //    > 1 | a {237   *                  //        | ^"238   * ```239   *240   * @return Error position, message and source code.241   */242  toString(): string243}244 245declare class CssSyntaxError extends CssSyntaxError_ {}246 247export = CssSyntaxError248