1
1
import * as ts from "./_namespaces/ts" ;
2
2
import {
3
3
AnyFunction , AssertionLevel , BigIntLiteralType , CheckMode , compareValues , EmitFlags , every , FlowFlags , FlowLabel , FlowNode ,
4
- FlowNodeBase , FlowSwitchClause , formatStringFromArgs , getEffectiveModifierFlagsNoCache , getEmitFlags , getOwnKeys ,
4
+ FlowNodeBase , FlowSwitchClause , getEffectiveModifierFlagsNoCache , getEmitFlags , getOwnKeys ,
5
5
getParseTreeNode , getSourceFileOfNode , getSourceTextOfNodeFromSourceFile , hasProperty , idText , IntrinsicType ,
6
6
isArrayTypeNode , isBigIntLiteral , isCallSignatureDeclaration , isConditionalTypeNode , isConstructorDeclaration ,
7
7
isConstructorTypeNode , isConstructSignatureDeclaration , isDefaultClause , isFunctionTypeNode , isGeneratedIdentifier ,
@@ -14,7 +14,7 @@ import {
14
14
ObjectFlags , ObjectType , RelationComparisonResult , Signature , SignatureCheckMode ,
15
15
SignatureFlags , SnippetKind , SortedReadonlyArray , stableSort , Symbol , SymbolFlags , symbolName , SyntaxKind ,
16
16
TransformFlags , Type , TypeFacts , TypeFlags , TypeMapKind , TypeMapper , unescapeLeadingUnderscores , VarianceFlags ,
17
- version , Version , zipWith ,
17
+ zipWith ,
18
18
} from "./_namespaces/ts" ;
19
19
20
20
/** @internal */
@@ -31,33 +31,16 @@ export interface LoggingHost {
31
31
log ( level : LogLevel , s : string ) : void ;
32
32
}
33
33
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
-
45
34
/** @internal */
46
35
export namespace Debug {
47
- let typeScriptVersion : Version | undefined ;
48
-
49
36
/* eslint-disable prefer-const */
50
37
let currentAssertionLevel = AssertionLevel . None ;
51
38
export let currentLogLevel = LogLevel . Warning ;
52
39
export let isDebugging = false ;
53
40
export let loggingHost : LoggingHost | undefined ;
54
- export let enableDeprecationWarnings = true ;
55
41
/* eslint-enable prefer-const */
56
42
57
43
type AssertionKeys = MatchingKeys < typeof Debug , AnyFunction > ;
58
- export function getTypeScriptVersion ( ) {
59
- return typeScriptVersion ?? ( typeScriptVersion = new Version ( version ) ) ;
60
- }
61
44
62
45
export function shouldLog ( level : LogLevel ) : boolean {
63
46
return currentLogLevel <= level ;
@@ -697,58 +680,6 @@ export namespace Debug {
697
680
isDebugInfoEnabled = true ;
698
681
}
699
682
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
-
752
683
export function formatVariance ( varianceFlags : VarianceFlags ) {
753
684
const variance = varianceFlags & VarianceFlags . VarianceMask ;
754
685
let result =
0 commit comments