Skip to content

Commit 0968ed9

Browse files
authored
Revert string enum changes (#16569)
* Revert "Convert Extension to a string enum (#16425)" This reverts commit 09321b3. * Revert "Also convert ClassificationTypeNames and CommandTypes/CommandNames" This reverts commit f94818d. * Revert "Make ScriptElementKind and HighlightSpanKind string enums" This reverts commit b162097. * Revert "Make ScriptElementKind and HighlightSpanKind string enums" This reverts commit b162097. # Conflicts: # lib/lib.d.ts # lib/lib.es2016.full.d.ts # lib/lib.es2017.full.d.ts # lib/lib.es5.d.ts # lib/lib.es6.d.ts # lib/lib.esnext.full.d.ts # lib/tsc.js # lib/tsserver.js # lib/tsserverlibrary.d.ts # lib/tsserverlibrary.js # lib/typescript.d.ts # lib/typescript.js # lib/typescriptServices.d.ts # lib/typescriptServices.js # lib/typingsInstaller.js * Update LKG * Revert "Make CommandTypes a const enum and use `allCommandTypes` for unit test" This reverts commit f6240cb.
1 parent 096f8cc commit 0968ed9

37 files changed

+2441
-2291
lines changed

lib/protocol.d.ts

Lines changed: 97 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,54 @@
22
* Declaration module describing the TypeScript Server protocol
33
*/
44
declare namespace ts.server.protocol {
5-
const enum CommandTypes {
6-
Brace = "brace",
7-
BraceCompletion = "braceCompletion",
8-
Change = "change",
9-
Close = "close",
10-
Completions = "completions",
11-
CompletionDetails = "completionEntryDetails",
12-
CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList",
13-
CompileOnSaveEmitFile = "compileOnSaveEmitFile",
14-
Configure = "configure",
15-
Definition = "definition",
16-
Implementation = "implementation",
17-
Exit = "exit",
18-
Format = "format",
19-
Formatonkey = "formatonkey",
20-
Geterr = "geterr",
21-
GeterrForProject = "geterrForProject",
22-
SemanticDiagnosticsSync = "semanticDiagnosticsSync",
23-
SyntacticDiagnosticsSync = "syntacticDiagnosticsSync",
24-
NavBar = "navbar",
25-
Navto = "navto",
26-
NavTree = "navtree",
27-
NavTreeFull = "navtree-full",
28-
Occurrences = "occurrences",
29-
DocumentHighlights = "documentHighlights",
30-
Open = "open",
31-
Quickinfo = "quickinfo",
32-
References = "references",
33-
Reload = "reload",
34-
Rename = "rename",
35-
Saveto = "saveto",
36-
SignatureHelp = "signatureHelp",
37-
TypeDefinition = "typeDefinition",
38-
ProjectInfo = "projectInfo",
39-
ReloadProjects = "reloadProjects",
40-
Unknown = "unknown",
41-
OpenExternalProject = "openExternalProject",
42-
OpenExternalProjects = "openExternalProjects",
43-
CloseExternalProject = "closeExternalProject",
44-
TodoComments = "todoComments",
45-
Indentation = "indentation",
46-
DocCommentTemplate = "docCommentTemplate",
47-
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
48-
GetCodeFixes = "getCodeFixes",
49-
GetSupportedCodeFixes = "getSupportedCodeFixes",
50-
GetApplicableRefactors = "getApplicableRefactors",
51-
GetEditsForRefactor = "getEditsForRefactor",
5+
namespace CommandTypes {
6+
type Brace = "brace";
7+
type BraceCompletion = "braceCompletion";
8+
type Change = "change";
9+
type Close = "close";
10+
type Completions = "completions";
11+
type CompletionDetails = "completionEntryDetails";
12+
type CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
13+
type CompileOnSaveEmitFile = "compileOnSaveEmitFile";
14+
type Configure = "configure";
15+
type Definition = "definition";
16+
type Implementation = "implementation";
17+
type Exit = "exit";
18+
type Format = "format";
19+
type Formatonkey = "formatonkey";
20+
type Geterr = "geterr";
21+
type GeterrForProject = "geterrForProject";
22+
type SemanticDiagnosticsSync = "semanticDiagnosticsSync";
23+
type SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
24+
type NavBar = "navbar";
25+
type Navto = "navto";
26+
type NavTree = "navtree";
27+
type NavTreeFull = "navtree-full";
28+
type Occurrences = "occurrences";
29+
type DocumentHighlights = "documentHighlights";
30+
type Open = "open";
31+
type Quickinfo = "quickinfo";
32+
type References = "references";
33+
type Reload = "reload";
34+
type Rename = "rename";
35+
type Saveto = "saveto";
36+
type SignatureHelp = "signatureHelp";
37+
type TypeDefinition = "typeDefinition";
38+
type ProjectInfo = "projectInfo";
39+
type ReloadProjects = "reloadProjects";
40+
type Unknown = "unknown";
41+
type OpenExternalProject = "openExternalProject";
42+
type OpenExternalProjects = "openExternalProjects";
43+
type CloseExternalProject = "closeExternalProject";
44+
type TodoComments = "todoComments";
45+
type Indentation = "indentation";
46+
type DocCommentTemplate = "docCommentTemplate";
47+
type CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects";
48+
type GetCodeFixes = "getCodeFixes";
49+
type GetSupportedCodeFixes = "getSupportedCodeFixes";
50+
type GetApplicableRefactors = "getApplicableRefactors";
51+
type GetRefactorCodeActions = "getRefactorCodeActions";
52+
type GetEditsForRefactor = "getEditsForRefactor";
5253
}
5354
/**
5455
* A TypeScript Server message
@@ -571,9 +572,10 @@ declare namespace ts.server.protocol {
571572
}
572573
/**
573574
* Span augmented with extra information that denotes the kind of the highlighting to be used for span.
575+
* Kind is taken from HighlightSpanKind type.
574576
*/
575577
interface HighlightSpan extends TextSpan {
576-
kind: HighlightSpanKind;
578+
kind: string;
577579
}
578580
/**
579581
* Represents a set of highligh spans for a give name
@@ -691,7 +693,7 @@ declare namespace ts.server.protocol {
691693
/**
692694
* The items's kind (such as 'className' or 'parameterName' or plain 'text').
693695
*/
694-
kind: ScriptElementKind;
696+
kind: string;
695697
/**
696698
* Optional modifiers for the kind (such as 'public').
697699
*/
@@ -1039,7 +1041,7 @@ declare namespace ts.server.protocol {
10391041
/**
10401042
* The symbol's kind (such as 'className' or 'parameterName' or plain 'text').
10411043
*/
1042-
kind: ScriptElementKind;
1044+
kind: string;
10431045
/**
10441046
* Optional modifiers for the kind (such as 'public').
10451047
*/
@@ -1225,7 +1227,7 @@ declare namespace ts.server.protocol {
12251227
/**
12261228
* The symbol's kind (such as 'className' or 'parameterName').
12271229
*/
1228-
kind: ScriptElementKind;
1230+
kind: string;
12291231
/**
12301232
* Optional modifiers for the kind (such as 'public').
12311233
*/
@@ -1252,7 +1254,7 @@ declare namespace ts.server.protocol {
12521254
/**
12531255
* The symbol's kind (such as 'className' or 'parameterName').
12541256
*/
1255-
kind: ScriptElementKind;
1257+
kind: string;
12561258
/**
12571259
* Optional modifiers for the kind (such as 'public').
12581260
*/
@@ -1645,7 +1647,7 @@ declare namespace ts.server.protocol {
16451647
/**
16461648
* The symbol's kind (such as 'className' or 'parameterName').
16471649
*/
1648-
kind: ScriptElementKind;
1650+
kind: string;
16491651
/**
16501652
* exact, substring, or prefix.
16511653
*/
@@ -1678,7 +1680,7 @@ declare namespace ts.server.protocol {
16781680
/**
16791681
* Kind of symbol's container symbol (if any).
16801682
*/
1681-
containerKind?: ScriptElementKind;
1683+
containerKind?: string;
16821684
}
16831685
/**
16841686
* Navto response message. Body is an array of navto items. Each
@@ -1742,7 +1744,7 @@ declare namespace ts.server.protocol {
17421744
/**
17431745
* The symbol's kind (such as 'className' or 'parameterName').
17441746
*/
1745-
kind: ScriptElementKind;
1747+
kind: string;
17461748
/**
17471749
* Optional modifiers for the kind (such as 'public').
17481750
*/
@@ -1763,7 +1765,7 @@ declare namespace ts.server.protocol {
17631765
/** protocol.NavigationTree is identical to ts.NavigationTree, except using protocol.TextSpan instead of ts.TextSpan */
17641766
interface NavigationTree {
17651767
text: string;
1766-
kind: ScriptElementKind;
1768+
kind: string;
17671769
kindModifiers: string;
17681770
spans: TextSpan[];
17691771
childItems?: NavigationTree[];
@@ -1838,11 +1840,12 @@ declare namespace ts.server.protocol {
18381840
interface NavTreeResponse extends Response {
18391841
body?: NavigationTree;
18401842
}
1841-
const enum IndentStyle {
1842-
None = "None",
1843-
Block = "Block",
1844-
Smart = "Smart",
1843+
namespace IndentStyle {
1844+
type None = "None";
1845+
type Block = "Block";
1846+
type Smart = "Smart";
18451847
}
1848+
type IndentStyle = IndentStyle.None | IndentStyle.Block | IndentStyle.Smart;
18461849
interface EditorSettings {
18471850
baseIndentSize?: number;
18481851
indentSize?: number;
@@ -1936,35 +1939,40 @@ declare namespace ts.server.protocol {
19361939
typeRoots?: string[];
19371940
[option: string]: CompilerOptionsValue | undefined;
19381941
}
1939-
const enum JsxEmit {
1940-
None = "None",
1941-
Preserve = "Preserve",
1942-
ReactNative = "ReactNative",
1943-
React = "React",
1944-
}
1945-
const enum ModuleKind {
1946-
None = "None",
1947-
CommonJS = "CommonJS",
1948-
AMD = "AMD",
1949-
UMD = "UMD",
1950-
System = "System",
1951-
ES6 = "ES6",
1952-
ES2015 = "ES2015",
1953-
}
1954-
const enum ModuleResolutionKind {
1955-
Classic = "Classic",
1956-
Node = "Node",
1957-
}
1958-
const enum NewLineKind {
1959-
Crlf = "Crlf",
1960-
Lf = "Lf",
1961-
}
1962-
const enum ScriptTarget {
1963-
ES3 = "ES3",
1964-
ES5 = "ES5",
1965-
ES6 = "ES6",
1966-
ES2015 = "ES2015",
1967-
}
1942+
namespace JsxEmit {
1943+
type None = "None";
1944+
type Preserve = "Preserve";
1945+
type ReactNative = "ReactNative";
1946+
type React = "React";
1947+
}
1948+
type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.ReactNative;
1949+
namespace ModuleKind {
1950+
type None = "None";
1951+
type CommonJS = "CommonJS";
1952+
type AMD = "AMD";
1953+
type UMD = "UMD";
1954+
type System = "System";
1955+
type ES6 = "ES6";
1956+
type ES2015 = "ES2015";
1957+
}
1958+
type ModuleKind = ModuleKind.None | ModuleKind.CommonJS | ModuleKind.AMD | ModuleKind.UMD | ModuleKind.System | ModuleKind.ES6 | ModuleKind.ES2015;
1959+
namespace ModuleResolutionKind {
1960+
type Classic = "Classic";
1961+
type Node = "Node";
1962+
}
1963+
type ModuleResolutionKind = ModuleResolutionKind.Classic | ModuleResolutionKind.Node;
1964+
namespace NewLineKind {
1965+
type Crlf = "Crlf";
1966+
type Lf = "Lf";
1967+
}
1968+
type NewLineKind = NewLineKind.Crlf | NewLineKind.Lf;
1969+
namespace ScriptTarget {
1970+
type ES3 = "ES3";
1971+
type ES5 = "ES5";
1972+
type ES6 = "ES6";
1973+
type ES2015 = "ES2015";
1974+
}
1975+
type ScriptTarget = ScriptTarget.ES3 | ScriptTarget.ES5 | ScriptTarget.ES6 | ScriptTarget.ES2015;
19681976
}
19691977
declare namespace ts.server.protocol {
19701978

@@ -2020,8 +2028,6 @@ declare namespace ts.server.protocol {
20202028
}
20212029
declare namespace ts {
20222030
// these types are empty stubs for types from services and should not be used directly
2023-
export type HighlightSpanKind = never;
2024-
export type ScriptElementKind = never;
20252031
export type ScriptKind = never;
20262032
export type IndentStyle = never;
20272033
export type JsxEmit = never;

lib/tsc.js

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ var ts;
8080
ModuleKind[ModuleKind["ES2015"] = 5] = "ES2015";
8181
ModuleKind[ModuleKind["ESNext"] = 6] = "ESNext";
8282
})(ModuleKind = ts.ModuleKind || (ts.ModuleKind = {}));
83+
var Extension;
84+
(function (Extension) {
85+
Extension[Extension["Ts"] = 0] = "Ts";
86+
Extension[Extension["Tsx"] = 1] = "Tsx";
87+
Extension[Extension["Dts"] = 2] = "Dts";
88+
Extension[Extension["Js"] = 3] = "Js";
89+
Extension[Extension["Jsx"] = 4] = "Jsx";
90+
Extension[Extension["LastTypeScriptExtension"] = 2] = "LastTypeScriptExtension";
91+
})(Extension = ts.Extension || (ts.Extension = {}));
8392
})(ts || (ts = {}));
8493
var ts;
8594
(function (ts) {
@@ -2123,7 +2132,7 @@ var ts;
21232132
}
21242133
ts.positionIsSynthesized = positionIsSynthesized;
21252134
function extensionIsTypeScript(ext) {
2126-
return ext === ".ts" || ext === ".tsx" || ext === ".d.ts";
2135+
return ext <= ts.Extension.LastTypeScriptExtension;
21272136
}
21282137
ts.extensionIsTypeScript = extensionIsTypeScript;
21292138
function extensionFromPath(path) {
@@ -2135,7 +2144,21 @@ var ts;
21352144
}
21362145
ts.extensionFromPath = extensionFromPath;
21372146
function tryGetExtensionFromPath(path) {
2138-
return find(ts.supportedTypescriptExtensionsForExtractExtension, function (e) { return fileExtensionIs(path, e); }) || find(ts.supportedJavascriptExtensions, function (e) { return fileExtensionIs(path, e); });
2147+
if (fileExtensionIs(path, ".d.ts")) {
2148+
return ts.Extension.Dts;
2149+
}
2150+
if (fileExtensionIs(path, ".ts")) {
2151+
return ts.Extension.Ts;
2152+
}
2153+
if (fileExtensionIs(path, ".tsx")) {
2154+
return ts.Extension.Tsx;
2155+
}
2156+
if (fileExtensionIs(path, ".js")) {
2157+
return ts.Extension.Js;
2158+
}
2159+
if (fileExtensionIs(path, ".jsx")) {
2160+
return ts.Extension.Jsx;
2161+
}
21392162
}
21402163
ts.tryGetExtensionFromPath = tryGetExtensionFromPath;
21412164
function isCheckJsEnabledForFile(sourceFile, compilerOptions) {
@@ -21555,14 +21578,14 @@ var ts;
2155521578
}
2155621579
switch (extensions) {
2155721580
case Extensions.DtsOnly:
21558-
return tryExtension(".d.ts");
21581+
return tryExtension(".d.ts", ts.Extension.Dts);
2155921582
case Extensions.TypeScript:
21560-
return tryExtension(".ts") || tryExtension(".tsx") || tryExtension(".d.ts");
21583+
return tryExtension(".ts", ts.Extension.Ts) || tryExtension(".tsx", ts.Extension.Tsx) || tryExtension(".d.ts", ts.Extension.Dts);
2156121584
case Extensions.JavaScript:
21562-
return tryExtension(".js") || tryExtension(".jsx");
21585+
return tryExtension(".js", ts.Extension.Js) || tryExtension(".jsx", ts.Extension.Jsx);
2156321586
}
21564-
function tryExtension(extension) {
21565-
var path = tryFile(candidate + extension, failedLookupLocations, onlyRecordFailures, state);
21587+
function tryExtension(ext, extension) {
21588+
var path = tryFile(candidate + ext, failedLookupLocations, onlyRecordFailures, state);
2156621589
return path && { path: path, extension: extension };
2156721590
}
2156821591
}
@@ -21632,11 +21655,11 @@ var ts;
2163221655
function extensionIsOk(extensions, extension) {
2163321656
switch (extensions) {
2163421657
case Extensions.JavaScript:
21635-
return extension === ".js" || extension === ".jsx";
21658+
return extension === ts.Extension.Js || extension === ts.Extension.Jsx;
2163621659
case Extensions.TypeScript:
21637-
return extension === ".ts" || extension === ".tsx" || extension === ".d.ts";
21660+
return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts;
2163821661
case Extensions.DtsOnly:
21639-
return extension === ".d.ts";
21662+
return extension === ts.Extension.Dts;
2164021663
}
2164121664
}
2164221665
function pathToPackageJson(directory) {
@@ -56483,14 +56506,14 @@ var ts;
5648356506
function getResolutionDiagnostic(options, _a) {
5648456507
var extension = _a.extension;
5648556508
switch (extension) {
56486-
case ".ts":
56487-
case ".d.ts":
56509+
case ts.Extension.Ts:
56510+
case ts.Extension.Dts:
5648856511
return undefined;
56489-
case ".tsx":
56512+
case ts.Extension.Tsx:
5649056513
return needJsx();
56491-
case ".jsx":
56514+
case ts.Extension.Jsx:
5649256515
return needJsx() || needAllowJs();
56493-
case ".js":
56516+
case ts.Extension.Js:
5649456517
return needAllowJs();
5649556518
}
5649656519
function needJsx() {

0 commit comments

Comments
 (0)