18e387982c970bafeedf13299cc4d0bc7c85fa8e5dd046666cfa91760b60f39bd58762f7f457c3bbd1c051beafd948ef64f1b4626eaa4ceff884c2cb9448bc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import {LegacyPluginThis} from './plugin_this';
  2. /**
  3. * The value of `this` in the context of a {@link LegacyImporter} function.
  4. *
  5. * @category Legacy
  6. * @deprecated This is only used by the legacy {@link render} and {@link
  7. * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
  8. * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
  9. */
  10. interface LegacyImporterThis extends LegacyPluginThis {
  11. /**
  12. * Whether the importer is being invoked because of a Sass `@import` rule, as
  13. * opposed to a `@use` or `@forward` rule.
  14. *
  15. * This should *only* be used for determining whether or not to load
  16. * [import-only files](https://sass-lang.com/documentation/at-rules/import#import-only-files).
  17. *
  18. * @compatibility dart: "1.33.0", node: false
  19. */
  20. fromImport: boolean;
  21. }
  22. /**
  23. * The result of running a {@link LegacyImporter}. It must be one of the
  24. * following types:
  25. *
  26. * * An object with the key `contents` whose value is the contents of a stylesheet
  27. * (in SCSS syntax). This causes Sass to load that stylesheet’s contents.
  28. *
  29. * * An object with the key `file` whose value is a path on disk. This causes Sass
  30. * to load that file as though it had been imported directly.
  31. *
  32. * * `null`, which indicates that it doesn’t recognize the URL and another
  33. * importer should be tried instead.
  34. *
  35. * * An [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
  36. * object, indicating that importing failed.
  37. *
  38. * @category Legacy
  39. * @deprecated This only works with the legacy {@link render} and {@link
  40. * renderSync} APIs. Use {@link ImporterResult} with {@link compile}, {@link
  41. * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
  42. */
  43. export type LegacyImporterResult =
  44. | {file: string}
  45. | {contents: string}
  46. | Error
  47. | null;
  48. /**
  49. * A synchronous callback that implements custom Sass loading logic for
  50. * [`@import` rules](https://sass-lang.com/documentation/at-rules/import) and
  51. * [`@use` rules](https://sass-lang.com/documentation/at-rules/use). This can be
  52. * passed to {@link LegacySharedOptions.importer} for either {@link render} or
  53. * {@link renderSync}.
  54. *
  55. * See {@link LegacySharedOptions.importer} for more detailed documentation.
  56. *
  57. * ```js
  58. * sass.renderSync({
  59. * file: "style.scss",
  60. * importer: [
  61. * function(url, prev) {
  62. * if (url != "big-headers") return null;
  63. *
  64. * return {
  65. * contents: 'h1 { font-size: 40px; }'
  66. * };
  67. * }
  68. * ]
  69. * });
  70. * ```
  71. *
  72. * @param url - The `@use` or `@import` rule’s URL as a string, exactly as it
  73. * appears in the stylesheet.
  74. *
  75. * @param prev - A string identifying the stylesheet that contained the `@use`
  76. * or `@import`. This string’s format depends on how that stylesheet was loaded:
  77. *
  78. * * If the stylesheet was loaded from the filesystem, it’s the absolute path of
  79. * its file.
  80. * * If the stylesheet was loaded from an importer that returned its contents,
  81. * it’s the URL of the `@use` or `@import` rule that loaded it.
  82. * * If the stylesheet came from the data option, it’s the string "stdin".
  83. *
  84. * @category Legacy
  85. * @deprecated This only works with the legacy {@link render} and {@link
  86. * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
  87. * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
  88. */
  89. type LegacySyncImporter = (
  90. this: LegacyImporterThis,
  91. url: string,
  92. prev: string
  93. ) => LegacyImporterResult;
  94. /**
  95. * An asynchronous callback that implements custom Sass loading logic for
  96. * [`@import` rules](https://sass-lang.com/documentation/at-rules/import) and
  97. * [`@use` rules](https://sass-lang.com/documentation/at-rules/use). This can be
  98. * passed to {@link LegacySharedOptions.importer} for either {@link render} or
  99. * {@link renderSync}.
  100. *
  101. * An asynchronous importer must return `undefined`, and then call `done` with
  102. * the result of its {@link LegacyImporterResult} once it's done running.
  103. *
  104. * See {@link LegacySharedOptions.importer} for more detailed documentation.
  105. *
  106. * ```js
  107. * sass.render({
  108. * file: "style.scss",
  109. * importer: [
  110. * function(url, prev, done) {
  111. * if (url != "big-headers") done(null);
  112. *
  113. * done({
  114. * contents: 'h1 { font-size: 40px; }'
  115. * });
  116. * }
  117. * ]
  118. * });
  119. * ```
  120. *
  121. * @param url - The `@use` or `@import` rule’s URL as a string, exactly as it
  122. * appears in the stylesheet.
  123. *
  124. * @param prev - A string identifying the stylesheet that contained the `@use`
  125. * or `@import`. This string’s format depends on how that stylesheet was loaded:
  126. *
  127. * * If the stylesheet was loaded from the filesystem, it’s the absolute path of
  128. * its file.
  129. * * If the stylesheet was loaded from an importer that returned its contents,
  130. * it’s the URL of the `@use` or `@import` rule that loaded it.
  131. * * If the stylesheet came from the data option, it’s the string "stdin".
  132. *
  133. * @param done - The callback to call once the importer has finished running.
  134. *
  135. * @category Legacy
  136. * @deprecated This only works with the legacy {@link render} and {@link
  137. * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
  138. * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
  139. */
  140. type LegacyAsyncImporter = (
  141. this: LegacyImporterThis,
  142. url: string,
  143. prev: string,
  144. done: (result: LegacyImporterResult) => void
  145. ) => void;
  146. /**
  147. * A callback that implements custom Sass loading logic for [`@import`
  148. * rules](https://sass-lang.com/documentation/at-rules/import) and [`@use`
  149. * rules](https://sass-lang.com/documentation/at-rules/use). For {@link
  150. * renderSync}, this must be a {@link LegacySyncImporter} which returns its
  151. * result directly; for {@link render}, it may be either a {@link
  152. * LegacySyncImporter} or a {@link LegacyAsyncImporter} which calls a callback
  153. * with its result.
  154. *
  155. * See {@link LegacySharedOptions.importer} for more details.
  156. *
  157. * @category Legacy
  158. * @deprecated This only works with the legacy {@link render} and {@link
  159. * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
  160. * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
  161. */
  162. export type LegacyImporter<sync = 'sync' | 'async'> = sync extends 'async'
  163. ? LegacySyncImporter | LegacyAsyncImporter
  164. : LegacySyncImporter;