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