lazy-result.d.ts 4.9 KB

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