Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07e1d3b

Browse filesBrowse files
authored
Ensure string enums are generated in protocol.d.ts (microsoft#17914)
1 parent 5e8e735 commit 07e1d3b
Copy full SHA for 07e1d3b

2 files changed

+13-5Lines changed: 13 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/buildProtocol.ts‎

Copy file name to clipboardExpand all lines: scripts/buildProtocol.ts
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1014
class 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

116120
function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {
Collapse file

‎src/server/protocol.ts‎

Copy file name to clipboardExpand all lines: src/server/protocol.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,7 @@ namespace ts.server.protocol {
24892489
System = "System",
24902490
ES6 = "ES6",
24912491
ES2015 = "ES2015",
2492+
ESNext = "ESNext"
24922493
}
24932494

24942495
export const enum ModuleResolutionKind {
@@ -2506,5 +2507,8 @@ namespace ts.server.protocol {
25062507
ES5 = "ES5",
25072508
ES6 = "ES6",
25082509
ES2015 = "ES2015",
2510+
ES2016 = "ES2016",
2511+
ES2017 = "ES2017",
2512+
ESNext = "ESNext"
25092513
}
25102514
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.