@@ -7,19 +7,23 @@ function endsWith(s: string, suffix: string) {
7
7
return s . lastIndexOf ( suffix , s . length - suffix . length ) !== - 1 ;
8
8
}
9
9
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
+
10
14
class DeclarationsWalker {
11
15
private visitedTypes : ts . Type [ ] = [ ] ;
12
16
private text = "" ;
13
17
private removedTypes : ts . Type [ ] = [ ] ;
14
-
18
+
15
19
private constructor ( private typeChecker : ts . TypeChecker , private protocolFile : ts . SourceFile ) {
16
20
}
17
21
18
22
static getExtraDeclarations ( typeChecker : ts . TypeChecker , protocolFile : ts . SourceFile ) : string {
19
23
let text = "declare namespace ts.server.protocol {\n" ;
20
24
var walker = new DeclarationsWalker ( typeChecker , protocolFile ) ;
21
25
walker . visitTypeNodes ( protocolFile ) ;
22
- text = walker . text
26
+ text = walker . text
23
27
? `declare namespace ts.server.protocol {\n${ walker . text } }`
24
28
: "" ;
25
29
if ( walker . removedTypes ) {
@@ -52,7 +56,7 @@ class DeclarationsWalker {
52
56
if ( sourceFile === this . protocolFile || path . basename ( sourceFile . fileName ) === "lib.d.ts" ) {
53
57
return ;
54
58
}
55
- if ( decl . kind === ts . SyntaxKind . EnumDeclaration ) {
59
+ if ( decl . kind === ts . SyntaxKind . EnumDeclaration && ! isStringEnum ( decl as ts . EnumDeclaration ) ) {
56
60
this . removedTypes . push ( type ) ;
57
61
return ;
58
62
}
@@ -91,7 +95,7 @@ class DeclarationsWalker {
91
95
for ( const type of heritageClauses [ 0 ] . types ) {
92
96
this . processTypeOfNode ( type ) ;
93
97
}
94
- }
98
+ }
95
99
break ;
96
100
}
97
101
}
@@ -110,7 +114,7 @@ class DeclarationsWalker {
110
114
this . processType ( type ) ;
111
115
}
112
116
}
113
- }
117
+ }
114
118
}
115
119
116
120
function writeProtocolFile ( outputFile : string , protocolTs : string , typeScriptServicesDts : string ) {
0 commit comments