| [2058e5c] | 1 | import {
|
|---|
| 2 | Document,
|
|---|
| 3 | Node,
|
|---|
| 4 | Plugin,
|
|---|
| 5 | ProcessOptions,
|
|---|
| 6 | Root,
|
|---|
| 7 | SourceMap,
|
|---|
| 8 | TransformCallback,
|
|---|
| 9 | Warning,
|
|---|
| 10 | WarningOptions
|
|---|
| 11 | } from './postcss.js'
|
|---|
| 12 | import Processor from './processor.js'
|
|---|
| 13 |
|
|---|
| 14 | declare namespace Result {
|
|---|
| 15 | export interface Message {
|
|---|
| 16 | [others: string]: any
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Source PostCSS plugin name.
|
|---|
| 20 | */
|
|---|
| 21 | plugin?: string
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Message type.
|
|---|
| 25 | */
|
|---|
| 26 | type: string
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | export interface ResultOptions extends ProcessOptions {
|
|---|
| 30 | /**
|
|---|
| 31 | * The CSS node that was the source of the warning.
|
|---|
| 32 | */
|
|---|
| 33 | node?: Node
|
|---|
| 34 |
|
|---|
| 35 | /**
|
|---|
| 36 | * Name of plugin that created this warning. `Result#warn` will fill it
|
|---|
| 37 | * automatically with `Plugin#postcssPlugin` value.
|
|---|
| 38 | */
|
|---|
| 39 | plugin?: string
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|---|
| 43 | export { Result_ as default }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * Provides the result of the PostCSS transformations.
|
|---|
| 48 | *
|
|---|
| 49 | * A Result instance is returned by `LazyResult#then`
|
|---|
| 50 | * or `Root#toResult` methods.
|
|---|
| 51 | *
|
|---|
| 52 | * ```js
|
|---|
| 53 | * postcss([autoprefixer]).process(css).then(result => {
|
|---|
| 54 | * console.log(result.css)
|
|---|
| 55 | * })
|
|---|
| 56 | * ```
|
|---|
| 57 | *
|
|---|
| 58 | * ```js
|
|---|
| 59 | * const result2 = postcss.parse(css).toResult()
|
|---|
| 60 | * ```
|
|---|
| 61 | */
|
|---|
| 62 | declare class Result_<RootNode = Document | Root> {
|
|---|
| 63 | /**
|
|---|
| 64 | * A CSS string representing of `Result#root`.
|
|---|
| 65 | *
|
|---|
| 66 | * ```js
|
|---|
| 67 | * postcss.parse('a{}').toResult().css //=> "a{}"
|
|---|
| 68 | * ```
|
|---|
| 69 | */
|
|---|
| 70 | css: string
|
|---|
| 71 |
|
|---|
| 72 | /**
|
|---|
| 73 | * Last runned PostCSS plugin.
|
|---|
| 74 | */
|
|---|
| 75 | lastPlugin: Plugin | TransformCallback
|
|---|
| 76 |
|
|---|
| 77 | /**
|
|---|
| 78 | * An instance of `SourceMapGenerator` class from the `source-map` library,
|
|---|
| 79 | * representing changes to the `Result#root` instance.
|
|---|
| 80 | *
|
|---|
| 81 | * ```js
|
|---|
| 82 | * result.map.toJSON() //=> { version: 3, file: 'a.css', … }
|
|---|
| 83 | * ```
|
|---|
| 84 | *
|
|---|
| 85 | * ```js
|
|---|
| 86 | * if (result.map) {
|
|---|
| 87 | * fs.writeFileSync(result.opts.to + '.map', result.map.toString())
|
|---|
| 88 | * }
|
|---|
| 89 | * ```
|
|---|
| 90 | */
|
|---|
| 91 | map: SourceMap
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | * Contains messages from plugins (e.g., warnings or custom messages).
|
|---|
| 95 | * Each message should have type and plugin properties.
|
|---|
| 96 | *
|
|---|
| 97 | * ```js
|
|---|
| 98 | * AtRule: {
|
|---|
| 99 | * import: (atRule, { result }) {
|
|---|
| 100 | * const importedFile = parseImport(atRule)
|
|---|
| 101 | * result.messages.push({
|
|---|
| 102 | * type: 'dependency',
|
|---|
| 103 | * plugin: 'postcss-import',
|
|---|
| 104 | * file: importedFile,
|
|---|
| 105 | * parent: result.opts.from
|
|---|
| 106 | * })
|
|---|
| 107 | * }
|
|---|
| 108 | * }
|
|---|
| 109 | * ```
|
|---|
| 110 | */
|
|---|
| 111 | messages: Result.Message[]
|
|---|
| 112 |
|
|---|
| 113 | /**
|
|---|
| 114 | * Options from the `Processor#process` or `Root#toResult` call
|
|---|
| 115 | * that produced this Result instance.]
|
|---|
| 116 | *
|
|---|
| 117 | * ```js
|
|---|
| 118 | * root.toResult(opts).opts === opts
|
|---|
| 119 | * ```
|
|---|
| 120 | */
|
|---|
| 121 | opts: Result.ResultOptions
|
|---|
| 122 |
|
|---|
| 123 | /**
|
|---|
| 124 | * The Processor instance used for this transformation.
|
|---|
| 125 | *
|
|---|
| 126 | * ```js
|
|---|
| 127 | * for (const plugin of result.processor.plugins) {
|
|---|
| 128 | * if (plugin.postcssPlugin === 'postcss-bad') {
|
|---|
| 129 | * throw 'postcss-good is incompatible with postcss-bad'
|
|---|
| 130 | * }
|
|---|
| 131 | * })
|
|---|
| 132 | * ```
|
|---|
| 133 | */
|
|---|
| 134 | processor: Processor
|
|---|
| 135 |
|
|---|
| 136 | /**
|
|---|
| 137 | * Root node after all transformations.
|
|---|
| 138 | *
|
|---|
| 139 | * ```js
|
|---|
| 140 | * root.toResult().root === root
|
|---|
| 141 | * ```
|
|---|
| 142 | */
|
|---|
| 143 | root: RootNode
|
|---|
| 144 |
|
|---|
| 145 | /**
|
|---|
| 146 | * An alias for the `Result#css` property.
|
|---|
| 147 | * Use it with syntaxes that generate non-CSS output.
|
|---|
| 148 | *
|
|---|
| 149 | * ```js
|
|---|
| 150 | * result.css === result.content
|
|---|
| 151 | * ```
|
|---|
| 152 | */
|
|---|
| 153 | get content(): string
|
|---|
| 154 |
|
|---|
| 155 | /**
|
|---|
| 156 | * @param processor Processor used for this transformation.
|
|---|
| 157 | * @param root Root node after all transformations.
|
|---|
| 158 | * @param opts Options from the `Processor#process` or `Root#toResult`.
|
|---|
| 159 | */
|
|---|
| 160 | constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions)
|
|---|
| 161 |
|
|---|
| 162 | /**
|
|---|
| 163 | * Returns for `Result#css` content.
|
|---|
| 164 | *
|
|---|
| 165 | * ```js
|
|---|
| 166 | * result + '' === result.css
|
|---|
| 167 | * ```
|
|---|
| 168 | *
|
|---|
| 169 | * @return String representing of `Result#root`.
|
|---|
| 170 | */
|
|---|
| 171 | toString(): string
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | * Creates an instance of `Warning` and adds it to `Result#messages`.
|
|---|
| 175 | *
|
|---|
| 176 | * ```js
|
|---|
| 177 | * if (decl.important) {
|
|---|
| 178 | * result.warn('Avoid !important', { node: decl, word: '!important' })
|
|---|
| 179 | * }
|
|---|
| 180 | * ```
|
|---|
| 181 | *
|
|---|
| 182 | * @param text Warning message.
|
|---|
| 183 | * @param opts Warning options.
|
|---|
| 184 | * @return Created warning.
|
|---|
| 185 | */
|
|---|
| 186 | warn(message: string, options?: WarningOptions): Warning
|
|---|
| 187 |
|
|---|
| 188 | /**
|
|---|
| 189 | * Returns warnings from plugins. Filters `Warning` instances
|
|---|
| 190 | * from `Result#messages`.
|
|---|
| 191 | *
|
|---|
| 192 | * ```js
|
|---|
| 193 | * result.warnings().forEach(warn => {
|
|---|
| 194 | * console.warn(warn.toString())
|
|---|
| 195 | * })
|
|---|
| 196 | * ```
|
|---|
| 197 | *
|
|---|
| 198 | * @return Warnings from plugins.
|
|---|
| 199 | */
|
|---|
| 200 | warnings(): Warning[]
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}
|
|---|
| 204 |
|
|---|
| 205 | export = Result
|
|---|