77 CancellationToken ,
88 canUsePropertyAccess ,
99 CaseBlock ,
10- CaseClause ,
1110 cast ,
1211 CharacterCodes ,
1312 ClassElement ,
@@ -43,13 +42,11 @@ import {
4342 createTextSpanFromRange ,
4443 Debug ,
4544 Declaration ,
46- DefaultClause ,
4745 Diagnostics ,
4846 diagnosticToString ,
4947 displayPart ,
5048 EmitHint ,
5149 EmitTextWriter ,
52- endsWith ,
5350 EntityName ,
5451 EnumMember ,
5552 escapeSnippetText ,
@@ -140,7 +137,6 @@ import {
140137 isConstructorDeclaration ,
141138 isContextualKeyword ,
142139 isDeclarationName ,
143- isDefaultClause ,
144140 isDeprecatedDeclaration ,
145141 isEntityName ,
146142 isEnumMember ,
@@ -185,7 +181,6 @@ import {
185181 isKeyword ,
186182 isKnownSymbol ,
187183 isLabeledStatement ,
188- isLiteralExpression ,
189184 isLiteralImportTypeNode ,
190185 isMemberName ,
191186 isMethodDeclaration ,
@@ -276,6 +271,7 @@ import {
276271 ModuleReference ,
277272 moduleResolutionSupportsPackageJsonExportsAndImports ,
278273 NamedImportBindings ,
274+ newCaseClauseTracker ,
279275 Node ,
280276 NodeArray ,
281277 NodeBuilderFlags ,
@@ -288,7 +284,6 @@ import {
288284 ObjectTypeDeclaration ,
289285 or ,
290286 ParenthesizedTypeNode ,
291- parseBigInt ,
292287 positionBelongsToNode ,
293288 positionIsASICandidate ,
294289 positionsAreOnSameLine ,
@@ -1105,75 +1100,6 @@ function getExhaustiveCaseSnippets(
11051100 return undefined ;
11061101}
11071102
1108- interface CaseClauseTracker {
1109- addValue ( value : string | number ) : void ;
1110- hasValue ( value : string | number | PseudoBigInt ) : boolean ;
1111- }
1112-
1113- function newCaseClauseTracker ( checker : TypeChecker , clauses : readonly ( CaseClause | DefaultClause ) [ ] ) : CaseClauseTracker {
1114- const existingStrings = new Set < string > ( ) ;
1115- const existingNumbers = new Set < number > ( ) ;
1116- const existingBigInts = new Set < string > ( ) ;
1117-
1118- for ( const clause of clauses ) {
1119- if ( ! isDefaultClause ( clause ) ) {
1120- if ( isLiteralExpression ( clause . expression ) ) {
1121- const expression = clause . expression ;
1122- switch ( expression . kind ) {
1123- case SyntaxKind . NoSubstitutionTemplateLiteral :
1124- case SyntaxKind . StringLiteral :
1125- existingStrings . add ( expression . text ) ;
1126- break ;
1127- case SyntaxKind . NumericLiteral :
1128- existingNumbers . add ( parseInt ( expression . text ) ) ;
1129- break ;
1130- case SyntaxKind . BigIntLiteral :
1131- const parsedBigInt = parseBigInt ( endsWith ( expression . text , "n" ) ? expression . text . slice ( 0 , - 1 ) : expression . text ) ;
1132- if ( parsedBigInt ) {
1133- existingBigInts . add ( pseudoBigIntToString ( parsedBigInt ) ) ;
1134- }
1135- break ;
1136- }
1137- }
1138- else {
1139- const symbol = checker . getSymbolAtLocation ( clause . expression ) ;
1140- if ( symbol && symbol . valueDeclaration && isEnumMember ( symbol . valueDeclaration ) ) {
1141- const enumValue = checker . getConstantValue ( symbol . valueDeclaration ) ;
1142- if ( enumValue !== undefined ) {
1143- addValue ( enumValue ) ;
1144- }
1145- }
1146- }
1147- }
1148- }
1149-
1150- return {
1151- addValue,
1152- hasValue,
1153- } ;
1154-
1155- function addValue ( value : string | number ) {
1156- switch ( typeof value ) {
1157- case "string" :
1158- existingStrings . add ( value ) ;
1159- break ;
1160- case "number" :
1161- existingNumbers . add ( value ) ;
1162- }
1163- }
1164-
1165- function hasValue ( value : string | number | PseudoBigInt ) : boolean {
1166- switch ( typeof value ) {
1167- case "string" :
1168- return existingStrings . has ( value ) ;
1169- case "number" :
1170- return existingNumbers . has ( value ) ;
1171- case "object" :
1172- return existingBigInts . has ( pseudoBigIntToString ( value ) ) ;
1173- }
1174- }
1175- }
1176-
11771103function typeNodeToExpression ( typeNode : TypeNode , languageVersion : ScriptTarget , quotePreference : QuotePreference ) : Expression | undefined {
11781104 switch ( typeNode . kind ) {
11791105 case SyntaxKind . TypeReference :
0 commit comments