@@ -7,19 +7,23 @@ function endsWith(s: string, suffix: string) {
77 return s . lastIndexOf ( suffix , s . length - suffix . length ) !== - 1 ;
88}
99
10+ function isStringEnum ( declaration : ts . EnumDeclaration ) {
11+ return declaration . members . length && declaration . members . every ( m => m . initializer && m . initializer . kind === ts . SyntaxKind . StringLiteral ) ;
12+ }
13+
1014class DeclarationsWalker {
1115 private visitedTypes : ts . Type [ ] = [ ] ;
1216 private text = "" ;
1317 private removedTypes : ts . Type [ ] = [ ] ;
14-
18+
1519 private constructor ( private typeChecker : ts . TypeChecker , private protocolFile : ts . SourceFile ) {
1620 }
1721
1822 static getExtraDeclarations ( typeChecker : ts . TypeChecker , protocolFile : ts . SourceFile ) : string {
1923 let text = "declare namespace ts.server.protocol {\n" ;
2024 var walker = new DeclarationsWalker ( typeChecker , protocolFile ) ;
2125 walker . visitTypeNodes ( protocolFile ) ;
22- text = walker . text
26+ text = walker . text
2327 ? `declare namespace ts.server.protocol {\n${ walker . text } }`
2428 : "" ;
2529 if ( walker . removedTypes ) {
@@ -52,7 +56,7 @@ class DeclarationsWalker {
5256 if ( sourceFile === this . protocolFile || path . basename ( sourceFile . fileName ) === "lib.d.ts" ) {
5357 return ;
5458 }
55- if ( decl . kind === ts . SyntaxKind . EnumDeclaration ) {
59+ if ( decl . kind === ts . SyntaxKind . EnumDeclaration && ! isStringEnum ( decl as ts . EnumDeclaration ) ) {
5660 this . removedTypes . push ( type ) ;
5761 return ;
5862 }
@@ -91,7 +95,7 @@ class DeclarationsWalker {
9195 for ( const type of heritageClauses [ 0 ] . types ) {
9296 this . processTypeOfNode ( type ) ;
9397 }
94- }
98+ }
9599 break ;
96100 }
97101 }
@@ -110,7 +114,7 @@ class DeclarationsWalker {
110114 this . processType ( type ) ;
111115 }
112116 }
113- }
117+ }
114118}
115119
116120function writeProtocolFile ( outputFile : string , protocolTs : string , typeScriptServicesDts : string ) {
0 commit comments