-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit deprecation warnings for legacy JS API #331
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our offline conversation, I think the best available solution for value API deprecations is to store a set of all active deprecation options and decide what to do based on those.
lib/src/deprecations.ts
Outdated
/** | ||
* Shorthand for the subset of options related to deprecations. | ||
*/ | ||
export type DeprecationOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using Pick<>
to derive this from the options type.
lib/src/deprecations.ts
Outdated
|
||
/** | ||
* Handles a host-side deprecation warning, either emitting a warning, throwing | ||
* and error, or doing nothing depending on the deprecation options used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* and error, or doing nothing depending on the deprecation options used. | |
* an error, or doing nothing depending on the deprecation options used. |
lib/src/deprecations.ts
Outdated
* This is used to determine which options to use when handling host-side | ||
* deprecation warnings that aren't explicitly tied to a particular compilation. | ||
*/ | ||
export const activeDeprecationOptions: Map<Object, DeprecationOptions> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using Symbol
s as the key here, you could actually just use a Record<Symbol, DeprecationOptions>
. Either way, the key type should be Symbol
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the key type to Symbol, but keeping this as a Map because it's better for adding/removing and checking the size
lib/src/deprecations.ts
Outdated
*/ | ||
export function warnForHostSideDeprecation( | ||
message: string, | ||
deprecation: Deprecation, | ||
options?: DeprecationOptions | ||
): void { | ||
if (options) throw Error(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this line. Is it left over from debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though I'd removed it before requesting review, so I think this was just GitHub's review interface being bad
lib/src/deprecations.ts
Outdated
} | ||
return false; | ||
} | ||
return getDeprecationIds(options?.silenceDeprecations ?? []).includes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return getDeprecationIds(options?.silenceDeprecations ?? []).includes( | |
return getDeprecationIds(options.silenceDeprecations ?? []).includes( |
There's no way for options
to be undefined here. Also below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
See sass/sass#3932
See sass/sass-spec#2016
See sass/dart-sass#2343