lazy-result.d.ts 4.7 KB

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