Skip to content

Commit a8e5aad

Browse files
committed
use const enums in compiler
1 parent 72402f9 commit a8e5aad

13 files changed

Lines changed: 40 additions & 40 deletions

File tree

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module ts {
77

8-
export enum ModuleInstanceState {
8+
export const enum ModuleInstanceState {
99
NonInstantiated = 0,
1010
Instantiated = 1,
1111
ConstEnumOnly = 2

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ module ts {
16061606
return true;
16071607

16081608
default:
1609-
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + SyntaxKind[node.kind]);
1609+
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
16101610
}
16111611
}
16121612

src/compiler/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module ts {
99
// x | y is False if both x and y are False.
1010
// x | y is Maybe if either x or y is Maybe, but neither x or y is True.
1111
// x | y is True if either x or y is True.
12-
export enum Ternary {
12+
export const enum Ternary {
1313
False = 0,
1414
Maybe = 1,
1515
True = -1
@@ -19,7 +19,7 @@ module ts {
1919
[index: string]: T;
2020
}
2121

22-
export enum Comparison {
22+
export const enum Comparison {
2323
LessThan = -1,
2424
EqualTo = 0,
2525
GreaterThan = 1
@@ -637,7 +637,7 @@ module ts {
637637
getSignatureConstructor: () => <any>Signature
638638
}
639639

640-
export enum AssertionLevel {
640+
export const enum AssertionLevel {
641641
None = 0,
642642
Normal = 1,
643643
Aggressive = 2,

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ module ts {
28292829
break;
28302830

28312831
default:
2832-
Debug.fail("This is unknown parent for type parameter: " + SyntaxKind[node.parent.kind]);
2832+
Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
28332833
}
28342834

28352835
return {
@@ -3225,7 +3225,7 @@ module ts {
32253225
break;
32263226

32273227
default:
3228-
Debug.fail("This is unknown kind for signature: " + SyntaxKind[node.kind]);
3228+
Debug.fail("This is unknown kind for signature: " + node.kind);
32293229
}
32303230

32313231
return {
@@ -3310,7 +3310,7 @@ module ts {
33103310
break;
33113311

33123312
default:
3313-
Debug.fail("This is unknown parent for parameter: " + SyntaxKind[node.parent.kind]);
3313+
Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
33143314
}
33153315

33163316
return {

src/compiler/parser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ module ts {
666666
return undefined;
667667
}
668668

669-
enum ParsingContext {
669+
const enum ParsingContext {
670670
SourceElements, // Elements in source file
671671
ModuleElements, // Elements in module declaration
672672
BlockStatements, // Statements in block
@@ -687,7 +687,7 @@ module ts {
687687
Count // Number of parsing contexts
688688
}
689689

690-
enum Tristate {
690+
const enum Tristate {
691691
False,
692692
True,
693693
Unknown
@@ -715,13 +715,13 @@ module ts {
715715
}
716716
};
717717

718-
enum LookAheadMode {
718+
const enum LookAheadMode {
719719
NotLookingAhead,
720720
NoErrorYet,
721721
Error
722722
}
723723

724-
enum ModifierContext {
724+
const enum ModifierContext {
725725
SourceElements, // Top level elements in a source file
726726
ModuleElements, // Elements in module declaration
727727
ClassMembers, // Members in class declaration
@@ -730,7 +730,7 @@ module ts {
730730

731731
// Tracks whether we nested (directly or indirectly) in a certain control block.
732732
// Used for validating break and continue statements.
733-
enum ControlBlockContext {
733+
const enum ControlBlockContext {
734734
NotNested,
735735
Nested,
736736
CrossingFunctionBoundary
@@ -2734,7 +2734,7 @@ module ts {
27342734
currentKind = SetAccesor;
27352735
}
27362736
else {
2737-
Debug.fail("Unexpected syntax kind:" + SyntaxKind[p.kind]);
2737+
Debug.fail("Unexpected syntax kind:" + p.kind);
27382738
}
27392739

27402740
if (!hasProperty(seen, p.name.text)) {

src/compiler/types.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module ts {
99
}
1010

1111
// token > SyntaxKind.Identifer => token is a keyword
12-
export enum SyntaxKind {
12+
export const enum SyntaxKind {
1313
Unknown,
1414
EndOfFileToken,
1515
SingleLineCommentTrivia,
@@ -249,7 +249,7 @@ module ts {
249249
LastTemplateToken = TemplateTail
250250
}
251251

252-
export enum NodeFlags {
252+
export const enum NodeFlags {
253253
Export = 0x00000001, // Declarations
254254
Ambient = 0x00000002, // Declarations
255255
QuestionMark = 0x00000004, // Parameter/Property/Method
@@ -722,7 +722,7 @@ module ts {
722722
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
723723
}
724724

725-
export enum TypeFormatFlags {
725+
export const enum TypeFormatFlags {
726726
None = 0x00000000,
727727
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
728728
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
@@ -733,7 +733,7 @@ module ts {
733733
InElementType = 0x00000040, // Writing an array or union element type
734734
}
735735

736-
export enum SymbolFormatFlags {
736+
export const enum SymbolFormatFlags {
737737
None = 0x00000000,
738738
WriteTypeParametersOrArguments = 0x00000001, // Write symbols's type argument if it is instantiated symbol
739739
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
@@ -744,7 +744,7 @@ module ts {
744744
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
745745
}
746746

747-
export enum SymbolAccessibility {
747+
export const enum SymbolAccessibility {
748748
Accessible,
749749
NotAccessible,
750750
CannotBeNamed
@@ -778,7 +778,7 @@ module ts {
778778
hasEarlyErrors(sourceFile?: SourceFile): boolean;
779779
}
780780

781-
export enum SymbolFlags {
781+
export const enum SymbolFlags {
782782
FunctionScopedVariable = 0x00000001, // Variable (var) or parameter
783783
BlockScopedVariable = 0x00000002, // A block-scoped variable (let or const)
784784
Property = 0x00000004, // Property or enum member
@@ -890,7 +890,7 @@ module ts {
890890
[index: string]: Symbol;
891891
}
892892

893-
export enum NodeCheckFlags {
893+
export const enum NodeCheckFlags {
894894
TypeChecked = 0x00000001, // Node has been type checked
895895
LexicalThis = 0x00000002, // Lexical 'this' reference
896896
CaptureThis = 0x00000004, // Lexical 'this' used in body
@@ -915,7 +915,7 @@ module ts {
915915
assignmentChecks?: Map<boolean>; // Cache of assignment checks
916916
}
917917

918-
export enum TypeFlags {
918+
export const enum TypeFlags {
919919
Any = 0x00000001,
920920
String = 0x00000002,
921921
Number = 0x00000004,
@@ -1012,7 +1012,7 @@ module ts {
10121012
mapper?: TypeMapper; // Instantiation mapper
10131013
}
10141014

1015-
export enum SignatureKind {
1015+
export const enum SignatureKind {
10161016
Call,
10171017
Construct,
10181018
}
@@ -1032,7 +1032,7 @@ module ts {
10321032
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
10331033
}
10341034

1035-
export enum IndexKind {
1035+
export const enum IndexKind {
10361036
String,
10371037
Number,
10381038
}
@@ -1112,7 +1112,7 @@ module ts {
11121112
[option: string]: string | number | boolean;
11131113
}
11141114

1115-
export enum ModuleKind {
1115+
export const enum ModuleKind {
11161116
None,
11171117
CommonJS,
11181118
AMD,
@@ -1127,7 +1127,7 @@ module ts {
11271127
}
11281128

11291129

1130-
export enum ScriptTarget {
1130+
export const enum ScriptTarget {
11311131
ES3,
11321132
ES5,
11331133
ES6,
@@ -1149,7 +1149,7 @@ module ts {
11491149
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'.
11501150
}
11511151

1152-
export enum CharacterCodes {
1152+
export const enum CharacterCodes {
11531153
nullCharacter = 0,
11541154
maxAsciiCharacter = 0x7F,
11551155

src/harness/compilerRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <reference path='typeWriter.ts' />
44
/// <reference path='syntacticCleaner.ts' />
55

6-
enum CompilerTestType {
6+
const enum CompilerTestType {
77
Conformance,
88
Regressions,
99
Test262

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ module FourSlash {
23682368
};
23692369
}
23702370

2371-
enum State {
2371+
const enum State {
23722372
none,
23732373
inSlashStarMarker,
23742374
inObjectMarker

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Utils {
3030
var global = <any>Function("return this").call(null);
3131

3232
// Setup some globals based on the current environment
33-
export enum ExecutionEnvironment {
33+
export const enum ExecutionEnvironment {
3434
Node,
3535
Browser,
3636
CScript

src/harness/typeWriter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface TypeWriterResult {
22
line: number;
33
column: number;
4-
syntaxKind: string;
4+
syntaxKind: number;
55
sourceText: string;
66
type: string;
77
}
@@ -84,7 +84,7 @@ class TypeWriterWalker {
8484
this.results.push({
8585
line: lineAndCharacter.line - 1,
8686
column: lineAndCharacter.character,
87-
syntaxKind: ts.SyntaxKind[node.kind],
87+
syntaxKind: node.kind,
8888
sourceText: sourceText,
8989
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.WriteOwnNameForAnyLike)
9090
});

0 commit comments

Comments
 (0)