Skip to content

Commit e71b7ce

Browse files
committed
Move deprecate to deprecatedCompat
1 parent b553aff commit e71b7ce

File tree

7 files changed

+443
-424
lines changed

7 files changed

+443
-424
lines changed

src/compiler/debug.ts

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ts from "./_namespaces/ts";
22
import {
33
AnyFunction, AssertionLevel, BigIntLiteralType, CheckMode, compareValues, EmitFlags, every, FlowFlags, FlowLabel, FlowNode,
4-
FlowNodeBase, FlowSwitchClause, formatStringFromArgs, getEffectiveModifierFlagsNoCache, getEmitFlags, getOwnKeys,
4+
FlowNodeBase, FlowSwitchClause, getEffectiveModifierFlagsNoCache, getEmitFlags, getOwnKeys,
55
getParseTreeNode, getSourceFileOfNode, getSourceTextOfNodeFromSourceFile, hasProperty, idText, IntrinsicType,
66
isArrayTypeNode, isBigIntLiteral, isCallSignatureDeclaration, isConditionalTypeNode, isConstructorDeclaration,
77
isConstructorTypeNode, isConstructSignatureDeclaration, isDefaultClause, isFunctionTypeNode, isGeneratedIdentifier,
@@ -31,17 +31,6 @@ export interface LoggingHost {
3131
log(level: LogLevel, s: string): void;
3232
}
3333

34-
/** @internal */
35-
export interface DeprecationOptions {
36-
message?: string;
37-
error?: boolean;
38-
since?: Version | string;
39-
warnAfter?: Version | string;
40-
errorAfter?: Version | string;
41-
typeScriptVersion?: Version | string;
42-
name?: string;
43-
}
44-
4534
/** @internal */
4635
export namespace Debug {
4736
let typeScriptVersion: Version | undefined;
@@ -697,58 +686,6 @@ export namespace Debug {
697686
isDebugInfoEnabled = true;
698687
}
699688

700-
function formatDeprecationMessage(name: string, error: boolean | undefined, errorAfter: Version | undefined, since: Version | undefined, message: string | undefined) {
701-
let deprecationMessage = error ? "DeprecationError: " : "DeprecationWarning: ";
702-
deprecationMessage += `'${name}' `;
703-
deprecationMessage += since ? `has been deprecated since v${since}` : "is deprecated";
704-
deprecationMessage += error ? " and can no longer be used." : errorAfter ? ` and will no longer be usable after v${errorAfter}.` : ".";
705-
deprecationMessage += message ? ` ${formatStringFromArgs(message, [name], 0)}` : "";
706-
return deprecationMessage;
707-
}
708-
709-
function createErrorDeprecation(name: string, errorAfter: Version | undefined, since: Version | undefined, message: string | undefined) {
710-
const deprecationMessage = formatDeprecationMessage(name, /*error*/ true, errorAfter, since, message);
711-
return () => {
712-
throw new TypeError(deprecationMessage);
713-
};
714-
}
715-
716-
function createWarningDeprecation(name: string, errorAfter: Version | undefined, since: Version | undefined, message: string | undefined) {
717-
let hasWrittenDeprecation = false;
718-
return () => {
719-
if (enableDeprecationWarnings && !hasWrittenDeprecation) {
720-
log.warn(formatDeprecationMessage(name, /*error*/ false, errorAfter, since, message));
721-
hasWrittenDeprecation = true;
722-
}
723-
};
724-
}
725-
726-
export function createDeprecation(name: string, options: DeprecationOptions & { error: true }): () => never;
727-
export function createDeprecation(name: string, options?: DeprecationOptions): () => void;
728-
export function createDeprecation(name: string, options: DeprecationOptions = {}) {
729-
const version = typeof options.typeScriptVersion === "string" ? new Version(options.typeScriptVersion) : options.typeScriptVersion ?? getTypeScriptVersion();
730-
const errorAfter = typeof options.errorAfter === "string" ? new Version(options.errorAfter) : options.errorAfter;
731-
const warnAfter = typeof options.warnAfter === "string" ? new Version(options.warnAfter) : options.warnAfter;
732-
const since = typeof options.since === "string" ? new Version(options.since) : options.since ?? warnAfter;
733-
const error = options.error || errorAfter && version.compareTo(errorAfter) <= 0;
734-
const warn = !warnAfter || version.compareTo(warnAfter) >= 0;
735-
return error ? createErrorDeprecation(name, errorAfter, since, options.message) :
736-
warn ? createWarningDeprecation(name, errorAfter, since, options.message) :
737-
noop;
738-
}
739-
740-
function wrapFunction<F extends (...args: any[]) => any>(deprecation: () => void, func: F): F {
741-
return function (this: unknown) {
742-
deprecation();
743-
return func.apply(this, arguments);
744-
} as F;
745-
}
746-
747-
export function deprecate<F extends (...args: any[]) => any>(func: F, options?: DeprecationOptions): F {
748-
const deprecation = createDeprecation(options?.name ?? getFunctionName(func), options);
749-
return wrapFunction(deprecation, func);
750-
}
751-
752689
export function formatVariance(varianceFlags: VarianceFlags) {
753690
const variance = varianceFlags & VarianceFlags.VarianceMask;
754691
let result =

0 commit comments

Comments
 (0)