lazy-result.d.ts 4.7 KB

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