Improve the JS API documentation for Logger.warn() (#3894)

This is not a functional change. The old type for this was too
complicated for TypeDoc to parse, so the documentation was being
hidden.
This commit is contained in:
Natalie Weizenbaum 2024-07-11 16:12:18 -07:00 committed by GitHub
parent a39dbad4ff
commit 21ae10af23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 28 deletions

View File

@ -29,7 +29,7 @@ export {
ImporterResult, ImporterResult,
NodePackageImporter, NodePackageImporter,
} from './importer'; } from './importer';
export {Logger, SourceSpan, SourceLocation} from './logger'; export {Logger, LoggerWarnOptions, SourceSpan, SourceLocation} from './logger';
export { export {
CustomFunction, CustomFunction,
Options, Options,

View File

@ -4,6 +4,33 @@ import {SourceSpan} from './source_span';
export {SourceLocation} from './source_location'; export {SourceLocation} from './source_location';
export {SourceSpan} from './source_span'; export {SourceSpan} from './source_span';
/**
* The options passed to {@link Logger.warn}.
*
* * `deprecation`: Whether this is a deprecation warning.
*
* * `deprecationType`: The type of deprecation. Only set if `deprecation` is
* true.
*
* * `span`: The location in the Sass source code that generated this warning.
* This may be unset if the warning didn't come from Sass source, for
* example if it's from a deprecated JavaScript option.
*
* * `stack`: The Sass stack trace at the point the warning was issued. This may
* be unset if the warning didn't come from Sass source, for example if it's
* from a deprecated JavaScript option.
*/
export type LoggerWarnOptions = (
| {
deprecation: true;
deprecationType: Deprecation;
}
| {deprecation: false}
) & {
span?: SourceSpan;
stack?: string;
};
/** /**
* An object that can be passed to {@link LegacySharedOptions.logger} to control * An object that can be passed to {@link LegacySharedOptions.logger} to control
* how Sass emits warnings and debug messages. * how Sass emits warnings and debug messages.
@ -42,24 +69,11 @@ export interface Logger {
* *
* If this is `undefined`, Sass will print warnings to standard error. * If this is `undefined`, Sass will print warnings to standard error.
* *
* `options` may contain the following fields:
*
* @param message - The warning message. * @param message - The warning message.
* @param options.deprecation - Whether this is a deprecation warning.
* @param options.deprecationType - The type of deprecation this warning is
* for, if any.
* @param options.span - The location in the Sass source code that generated this
* warning.
* @param options.stack - The Sass stack trace at the point the warning was issued.
*/ */
warn?( warn?(message: string, options: LoggerWarnOptions): void;
message: string,
options: (
| {
deprecation: true;
deprecationType: Deprecation;
}
| {deprecation: false}
) & {span?: SourceSpan; stack?: string}
): void;
/** /**
* This method is called when Sass emits a debug message due to a [`@debug` * This method is called when Sass emits a debug message due to a [`@debug`

View File

@ -66,7 +66,7 @@ export {
ImporterResult, ImporterResult,
NodePackageImporter, NodePackageImporter,
} from './importer'; } from './importer';
export {Logger, SourceSpan, SourceLocation} from './logger'; export {Logger, LoggerWarnOptions, SourceSpan, SourceLocation} from './logger';
export { export {
CustomFunction, CustomFunction,
Options, Options,

View File

@ -11,6 +11,7 @@ export {SourceSpan} from './source_span';
## Table of Contents ## Table of Contents
* [Types](#types) * [Types](#types)
* [`LoggerWarnOptions`](#loggerwarnoptions)
* [`Logger`](#logger) * [`Logger`](#logger)
* [`warn`](#warn) * [`warn`](#warn)
* [`debug`](#debug) * [`debug`](#debug)
@ -20,6 +21,24 @@ export {SourceSpan} from './source_span';
## Types ## Types
### `LoggerWarnOptions`
The options passed to `Logger.warn`. These are split out for documentation
purposes.
```ts
export type LoggerWarnOptions = (
| {
deprecation: true;
deprecationType: Deprecation;
}
| {deprecation: false}
) & {
span?: SourceSpan;
stack?: string;
};
```
### `Logger` ### `Logger`
An object that provides callbacks for handling messages from the compiler. An object that provides callbacks for handling messages from the compiler.
@ -67,16 +86,7 @@ If this field is defined, the compiler must not surface warnings in any way
other than inkoving `warn`. other than inkoving `warn`.
```ts ```ts
warn?( warn?(message: string, options: LoggerWarnOptions): void;
message: string,
options: (
| {
deprecation: true;
deprecationType: Deprecation;
}
| {deprecation: false}
) & {span?: SourceSpan; stack?: string}
): void;
``` ```
#### `debug` #### `debug`