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 | * @param processor Processor used for this transformation.
|
147 | * @param root Root node after all transformations.
|
148 | * @param opts Options from the `Processor#process` or `Root#toResult`.
|
149 | */
|
150 | constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions)
|
151 |
|
152 | /**
|
153 | * Returns for `Result#css` content.
|
154 | *
|
155 | * ```js
|
156 | * result + '' === result.css
|
157 | * ```
|
158 | *
|
159 | * @return String representing of `Result#root`.
|
160 | */
|
161 | toString(): string
|
162 |
|
163 | /**
|
164 | * Creates an instance of `Warning` and adds it to `Result#messages`.
|
165 | *
|
166 | * ```js
|
167 | * if (decl.important) {
|
168 | * result.warn('Avoid !important', { node: decl, word: '!important' })
|
169 | * }
|
170 | * ```
|
171 | *
|
172 | * @param text Warning message.
|
173 | * @param opts Warning options.
|
174 | * @return Created warning.
|
175 | */
|
176 | warn(message: string, options?: WarningOptions): Warning
|
177 |
|
178 | /**
|
179 | * Returns warnings from plugins. Filters `Warning` instances
|
180 | * from `Result#messages`.
|
181 | *
|
182 | * ```js
|
183 | * result.warnings().forEach(warn => {
|
184 | * console.warn(warn.toString())
|
185 | * })
|
186 | * ```
|
187 | *
|
188 | * @return Warnings from plugins.
|
189 | */
|
190 | warnings(): Warning[]
|
191 |
|
192 | /**
|
193 | * An alias for the `Result#css` property.
|
194 | * Use it with syntaxes that generate non-CSS output.
|
195 | *
|
196 | * ```js
|
197 | * result.css === result.content
|
198 | * ```
|
199 | */
|
200 | get content(): string
|
201 | }
|
202 |
|
203 | declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}
|
204 |
|
205 | export = Result
|
206 |
|
\ | No newline at end of file |