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