1 | import Result, { Message, ResultOptions } from './result.js'
|
---|
2 | import { SourceMap } from './postcss.js'
|
---|
3 | import Processor from './processor.js'
|
---|
4 | import Warning from './warning.js'
|
---|
5 | import Root from './root.js'
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * A Promise proxy for the result of PostCSS transformations.
|
---|
9 | *
|
---|
10 | * A `LazyResult` instance is returned by `Processor#process`.
|
---|
11 | *
|
---|
12 | * ```js
|
---|
13 | * const lazy = postcss([autoprefixer]).process(css)
|
---|
14 | * ```
|
---|
15 | */
|
---|
16 | export default class LazyResult implements PromiseLike<Result> {
|
---|
17 | /**
|
---|
18 | * Processes input CSS through synchronous and asynchronous plugins
|
---|
19 | * and calls `onFulfilled` with a Result instance. If a plugin throws
|
---|
20 | * an error, the `onRejected` callback will be executed.
|
---|
21 | *
|
---|
22 | * It implements standard Promise API.
|
---|
23 | *
|
---|
24 | * ```js
|
---|
25 | * postcss([autoprefixer]).process(css, { from: cssPath }).then(result => {
|
---|
26 | * console.log(result.css)
|
---|
27 | * })
|
---|
28 | * ```
|
---|
29 | */
|
---|
30 | then: Promise<Result>['then']
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Processes input CSS through synchronous and asynchronous plugins
|
---|
34 | * and calls onRejected for each error thrown in any plugin.
|
---|
35 | *
|
---|
36 | * It implements standard Promise API.
|
---|
37 | *
|
---|
38 | * ```js
|
---|
39 | * postcss([autoprefixer]).process(css).then(result => {
|
---|
40 | * console.log(result.css)
|
---|
41 | * }).catch(error => {
|
---|
42 | * console.error(error)
|
---|
43 | * })
|
---|
44 | * ```
|
---|
45 | */
|
---|
46 | catch: Promise<Result>['catch']
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Processes input CSS through synchronous and asynchronous plugins
|
---|
50 | * and calls onFinally on any error or when all plugins will finish work.
|
---|
51 | *
|
---|
52 | * It implements standard Promise API.
|
---|
53 | *
|
---|
54 | * ```js
|
---|
55 | * postcss([autoprefixer]).process(css).finally(() => {
|
---|
56 | * console.log('processing ended')
|
---|
57 | * })
|
---|
58 | * ```
|
---|
59 | */
|
---|
60 | finally: Promise<Result>['finally']
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * @param processor Processor used for this transformation.
|
---|
64 | * @param css CSS to parse and transform.
|
---|
65 | * @param opts Options from the `Processor#process` or `Root#toResult`.
|
---|
66 | */
|
---|
67 | constructor(processor: Processor, css: string, opts: ResultOptions)
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Returns the default string description of an object.
|
---|
71 | * Required to implement the Promise interface.
|
---|
72 | */
|
---|
73 | get [Symbol.toStringTag](): string
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Returns a `Processor` instance, which will be used
|
---|
77 | * for CSS transformations.
|
---|
78 | */
|
---|
79 | get processor(): Processor
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Options from the `Processor#process` call.
|
---|
83 | */
|
---|
84 | get opts(): ResultOptions
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Processes input CSS through synchronous plugins, converts `Root`
|
---|
88 | * to a CSS string and returns `Result#css`.
|
---|
89 | *
|
---|
90 | * This property will only work with synchronous plugins.
|
---|
91 | * If the processor contains any asynchronous plugins
|
---|
92 | * it will throw an error. This is why this method is only
|
---|
93 | * for debug purpose, you should always use `LazyResult#then`.
|
---|
94 | */
|
---|
95 | get css(): string
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * An alias for the `css` property. Use it with syntaxes
|
---|
99 | * that generate non-CSS output.
|
---|
100 | *
|
---|
101 | * This property will only work with synchronous plugins.
|
---|
102 | * If the processor contains any asynchronous plugins
|
---|
103 | * it will throw an error. This is why this method is only
|
---|
104 | * for debug purpose, you should always use `LazyResult#then`.
|
---|
105 | */
|
---|
106 | get content(): string
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Processes input CSS through synchronous plugins
|
---|
110 | * and returns `Result#map`.
|
---|
111 | *
|
---|
112 | * This property will only work with synchronous plugins.
|
---|
113 | * If the processor contains any asynchronous plugins
|
---|
114 | * it will throw an error. This is why this method is only
|
---|
115 | * for debug purpose, you should always use `LazyResult#then`.
|
---|
116 | */
|
---|
117 | get map(): SourceMap
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Processes input CSS through synchronous plugins
|
---|
121 | * and returns `Result#root`.
|
---|
122 | *
|
---|
123 | * This property will only work with synchronous plugins. If the processor
|
---|
124 | * contains any asynchronous plugins it will throw an error.
|
---|
125 | *
|
---|
126 | * This is why this method is only for debug purpose,
|
---|
127 | * you should always use `LazyResult#then`.
|
---|
128 | */
|
---|
129 | get root(): Root
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Processes input CSS through synchronous plugins
|
---|
133 | * and returns `Result#messages`.
|
---|
134 | *
|
---|
135 | * This property will only work with synchronous plugins. If the processor
|
---|
136 | * contains any asynchronous plugins it will throw an error.
|
---|
137 | *
|
---|
138 | * This is why this method is only for debug purpose,
|
---|
139 | * you should always use `LazyResult#then`.
|
---|
140 | */
|
---|
141 | get messages(): Message[]
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Processes input CSS through synchronous plugins
|
---|
145 | * and calls `Result#warnings`.
|
---|
146 | *
|
---|
147 | * @return Warnings from plugins.
|
---|
148 | */
|
---|
149 | warnings(): Warning[]
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Alias for the `LazyResult#css` property.
|
---|
153 | *
|
---|
154 | * ```js
|
---|
155 | * lazy + '' === lazy.css
|
---|
156 | * ```
|
---|
157 | *
|
---|
158 | * @return Output CSS.
|
---|
159 | */
|
---|
160 | toString(): string
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Run plugin in sync way and return `Result`.
|
---|
164 | *
|
---|
165 | * @return Result with output content.
|
---|
166 | */
|
---|
167 | sync(): Result
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Run plugin in async way and return `Result`.
|
---|
171 | *
|
---|
172 | * @return Result with output content.
|
---|
173 | */
|
---|
174 | async(): Promise<Result>
|
---|
175 | }
|
---|