b9b97de665ba72e2b80e9e35b1e3f22136afcbf8811d8711150555f84a58c5e281f76d1967293d7b72cbc0afecd43bb93a2f98193df960ab7f350ee48ac26c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {Deprecation} from '../deprecations';
  2. import {SourceSpan} from './source_span';
  3. export {SourceLocation} from './source_location';
  4. export {SourceSpan} from './source_span';
  5. /**
  6. * The options passed to {@link Logger.warn}.
  7. *
  8. * * `deprecation`: Whether this is a deprecation warning.
  9. *
  10. * * `deprecationType`: The type of deprecation. Only set if `deprecation` is
  11. * true.
  12. *
  13. * * `span`: The location in the Sass source code that generated this warning.
  14. * This may be unset if the warning didn't come from Sass source, for
  15. * example if it's from a deprecated JavaScript option.
  16. *
  17. * * `stack`: The Sass stack trace at the point the warning was issued. This may
  18. * be unset if the warning didn't come from Sass source, for example if it's
  19. * from a deprecated JavaScript option.
  20. *
  21. * @category Logger
  22. */
  23. export type LoggerWarnOptions = (
  24. | {
  25. deprecation: true;
  26. deprecationType: Deprecation;
  27. }
  28. | {deprecation: false}
  29. ) & {
  30. span?: SourceSpan;
  31. stack?: string;
  32. };
  33. /**
  34. * An object that can be passed to {@link LegacySharedOptions.logger} to control
  35. * how Sass emits warnings and debug messages.
  36. *
  37. * @example
  38. *
  39. * ```js
  40. * const fs = require('fs');
  41. * const sass = require('sass');
  42. *
  43. * let log = "";
  44. * sass.renderSync({
  45. * file: 'input.scss',
  46. * logger: {
  47. * warn(message, options) {
  48. * if (options.span) {
  49. * log += `${span.url}:${span.start.line}:${span.start.column}: ` +
  50. * `${message}\n`;
  51. * } else {
  52. * log += `::: ${message}\n`;
  53. * }
  54. * }
  55. * }
  56. * });
  57. *
  58. * fs.writeFileSync('log.txt', log);
  59. * ```
  60. *
  61. * @category Logger
  62. */
  63. export interface Logger {
  64. /**
  65. * This method is called when Sass emits a warning, whether due to a [`@warn`
  66. * rule](https://sass-lang.com/documentation/at-rules/warn) or a warning
  67. * generated by the Sass compiler.
  68. *
  69. * If this is `undefined`, Sass will print warnings to standard error.
  70. *
  71. * `options` may contain the following fields:
  72. *
  73. * @param message - The warning message.
  74. */
  75. warn?(message: string, options: LoggerWarnOptions): void;
  76. /**
  77. * This method is called when Sass emits a debug message due to a [`@debug`
  78. * rule](https://sass-lang.com/documentation/at-rules/debug).
  79. *
  80. * If this is `undefined`, Sass will print debug messages to standard error.
  81. *
  82. * @param message - The debug message.
  83. * @param options.span - The location in the Sass source code that generated this
  84. * debug message.
  85. */
  86. debug?(message: string, options: {span: SourceSpan}): void;
  87. }
  88. /**
  89. * A namespace for built-in {@link Logger}s.
  90. *
  91. * @category Logger
  92. * @compatibility dart: "1.43.0", node: false
  93. */
  94. export namespace Logger {
  95. /**
  96. * A {@link Logger} that silently ignores all warnings and debug messages.
  97. *
  98. * @example
  99. *
  100. * ```js
  101. * const sass = require('sass');
  102. *
  103. * const result = sass.renderSync({
  104. * file: 'input.scss',
  105. * logger: sass.Logger.silent,
  106. * });
  107. * ```
  108. */
  109. export const silent: Logger;
  110. }