Skip to content

Inline "our own" regular enums #48161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const buildServices = (() => {
const createTypescriptServicesDts = () => src("built/local/typescriptServices.out.d.ts")
.pipe(newer("built/local/typescriptServices.d.ts"))
.pipe(prependFile(copyright))
.pipe(transform(content => content.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4")))
.pipe(rename("typescriptServices.d.ts"))
.pipe(dest("built/local"));

Expand Down Expand Up @@ -265,7 +264,6 @@ const buildLssl = (() => {
const createServerLibraryDts = () => src("built/local/tsserverlibrary.out.d.ts")
.pipe(newer("built/local/tsserverlibrary.d.ts"))
.pipe(prependFile(copyright))
.pipe(transform(content => content.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4")))
.pipe(append("\nexport = ts;\nexport as namespace ts;"))
.pipe(rename("tsserverlibrary.d.ts"))
.pipe(dest("built/local"));
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* @internal */
namespace ts {
export const enum ModuleInstanceState {
export enum ModuleInstanceState {
NonInstantiated = 0,
Instantiated = 1,
ConstEnumOnly = 2
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace ts {
return ModuleInstanceState.Instantiated; // Couldn't locate, assume could refer to a value
}

const enum ContainerFlags {
enum ContainerFlags {
// The current node is not a container, and no container manipulation should happen before
// recursing into it.
None = 0,
Expand Down Expand Up @@ -2039,7 +2039,7 @@ namespace ts {
}

function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
const enum ElementKind {
enum ElementKind {
Property = 1,
Accessor = 2
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace ts {
hasReusableDiagnostic?: true;
}

export const enum BuilderFileEmit {
export enum BuilderFileEmit {
DtsOnly,
Full
}
Expand Down
36 changes: 18 additions & 18 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ts {
let nextMergeId = 1;
let nextFlowId = 1;

const enum IterationUse {
enum IterationUse {
AllowsSyncIterablesFlag = 1 << 0,
AllowsAsyncIterablesFlag = 1 << 1,
AllowsStringInputFlag = 1 << 2,
Expand All @@ -34,7 +34,7 @@ namespace ts {

}

const enum IterationTypeKind {
enum IterationTypeKind {
Yield,
Return,
Next,
Expand All @@ -54,14 +54,14 @@ namespace ts {
mustHaveAValueDiagnostic: DiagnosticMessage;
}

const enum WideningKind {
enum WideningKind {
Normal,
FunctionReturn,
GeneratorNext,
GeneratorYield,
}

const enum TypeFacts {
enum TypeFacts {
None = 0,
TypeofEQString = 1 << 0, // typeof x === "string"
TypeofEQNumber = 1 << 1, // typeof x === "number"
Expand Down Expand Up @@ -163,7 +163,7 @@ namespace ts {

type TypeSystemEntity = Node | Symbol | Type | Signature;

const enum TypeSystemPropertyName {
enum TypeSystemPropertyName {
Type,
ResolvedBaseConstructorType,
DeclaredType,
Expand All @@ -174,7 +174,7 @@ namespace ts {
ResolvedBaseTypes,
}

const enum CheckMode {
enum CheckMode {
Normal = 0, // Normal type checking
Contextual = 1 << 0, // Explicitly assigned contextual type, therefore not cacheable
Inferential = 1 << 1, // Inferential typing
Expand All @@ -186,49 +186,49 @@ namespace ts {
// we need to preserve generic types instead of substituting them for constraints
}

const enum SignatureCheckMode {
enum SignatureCheckMode {
BivariantCallback = 1 << 0,
StrictCallback = 1 << 1,
IgnoreReturnTypes = 1 << 2,
StrictArity = 1 << 3,
Callback = BivariantCallback | StrictCallback,
}

const enum IntersectionState {
enum IntersectionState {
None = 0,
Source = 1 << 0,
Target = 1 << 1,
PropertyCheck = 1 << 2,
InPropertyCheck = 1 << 3,
}

const enum RecursionFlags {
enum RecursionFlags {
None = 0,
Source = 1 << 0,
Target = 1 << 1,
Both = Source | Target,
}

const enum MappedTypeModifiers {
enum MappedTypeModifiers {
IncludeReadonly = 1 << 0,
ExcludeReadonly = 1 << 1,
IncludeOptional = 1 << 2,
ExcludeOptional = 1 << 3,
}

const enum ExpandingFlags {
enum ExpandingFlags {
None = 0,
Source = 1,
Target = 1 << 1,
Both = Source | Target,
}

const enum MembersOrExportsResolutionKind {
enum MembersOrExportsResolutionKind {
resolvedExports = "resolvedExports",
resolvedMembers = "resolvedMembers"
}

const enum UnusedKind {
enum UnusedKind {
Local,
Parameter,
}
Expand All @@ -238,7 +238,7 @@ namespace ts {

const isNotOverloadAndNotAccessor = and(isNotOverload, isNotAccessor);

const enum DeclarationMeaning {
enum DeclarationMeaning {
GetAccessor = 1,
SetAccessor = 2,
PropertyAssignment = 4,
Expand All @@ -248,20 +248,20 @@ namespace ts {
PropertyAssignmentOrMethod = PropertyAssignment | Method,
}

const enum DeclarationSpaces {
enum DeclarationSpaces {
None = 0,
ExportValue = 1 << 0,
ExportType = 1 << 1,
ExportNamespace = 1 << 2,
}

const enum MinArgumentCountFlags {
enum MinArgumentCountFlags {
None = 0,
StrongArityForUntypedJS = 1 << 0,
VoidIsNonOptional = 1 << 1,
}

const enum IntrinsicTypeKind {
enum IntrinsicTypeKind {
Uppercase,
Lowercase,
Capitalize,
Expand Down Expand Up @@ -42277,7 +42277,7 @@ namespace ts {
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
// inline property\index accesses only for const enums
const member = symbol.valueDeclaration as EnumMember;
if (isEnumConst(member.parent)) {
if (!(member.flags & NodeFlags.Ambient) || isEnumConst(member.parent) || host.getFileIncludeReasons().get(getSourceFileOfNode(member).fileName as never)?.some(reason => reason.kind === FileIncludeKind.OutputFromProjectReference)) {
return getEnumMemberValue(member);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ namespace ts {
}
}

export const enum AssertionLevel {
export enum AssertionLevel {
None = 0,
Normal = 1,
Aggressive = 2,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/corePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace ts {
export type Comparer<T> = (a: T, b: T) => Comparison;

/* @internal */
export const enum Comparison {
export enum Comparison {
LessThan = -1,
EqualTo = 0,
GreaterThan = 1
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ namespace ts {
return outputFiles;
}

const enum PipelinePhase {
enum PipelinePhase {
Notification,
Substitution,
Comments,
Expand Down Expand Up @@ -5883,7 +5883,7 @@ namespace ts {
}

// Flags enum to track count of temp variables and a few dedicated names
const enum TempFlags {
enum TempFlags {
Auto = 0x00000000, // No preferred name
CountMask = 0x0FFFFFFF, // Temp variable counter
_i = 0x10000000, // Use/preference flag for '_i'
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace ts {
let nextAutoGenerateId = 0;

/* @internal */
export const enum NodeFactoryFlags {
export enum NodeFactoryFlags {
None = 0,
// Disables the parenthesizer rules for the factory.
NoParenthesizerRules = 1 << 0,
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Used by importFixes, getEditsForFileRename, and declaration emit to synthesize import module specifiers.
/* @internal */
namespace ts.moduleSpecifiers {
const enum RelativePreference { Relative, NonRelative, Shortest, ExternalNonRelative }
enum RelativePreference { Relative, NonRelative, Shortest, ExternalNonRelative }
// See UserPreferences#importPathEnding
const enum Ending { Minimal, Index, JsExtension }
enum Ending { Minimal, Index, JsExtension }

// Processed preferences
interface Preferences {
Expand Down Expand Up @@ -582,7 +582,7 @@ namespace ts.moduleSpecifiers {
}
}

const enum MatchingMode {
enum MatchingMode {
Exact,
Directory,
Pattern
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace ts {
const enum SignatureFlags {
enum SignatureFlags {
None = 0,
Yield = 1 << 0,
Await = 1 << 1,
Expand All @@ -8,7 +8,7 @@ namespace ts {
JSDoc = 1 << 5,
}

const enum SpeculationKind {
enum SpeculationKind {
TryParse,
Lookahead,
Reparse
Expand Down Expand Up @@ -7610,7 +7610,7 @@ namespace ts {
return isMetaProperty(node) && node.keywordToken === SyntaxKind.ImportKeyword && node.name.escapedText === "meta";
}

const enum ParsingContext {
enum ParsingContext {
SourceElements, // Elements in source file
BlockStatements, // Statements in block
SwitchClauses, // Clauses in switch statement
Expand Down Expand Up @@ -7639,7 +7639,7 @@ namespace ts {
Count // Number of parsing contexts
}

const enum Tristate {
enum Tristate {
False,
True,
Unknown
Expand Down Expand Up @@ -7727,14 +7727,14 @@ namespace ts {
return comment;
}

const enum JSDocState {
enum JSDocState {
BeginningOfLine,
SawAsterisk,
SavingComments,
SavingBackticks, // NOTE: Only used when parsing tag comments
}

const enum PropertyLikeParse {
enum PropertyLikeParse {
Property = 1 << 0,
Parameter = 1 << 1,
CallbackParameter = 1 << 2,
Expand Down Expand Up @@ -9307,7 +9307,7 @@ namespace ts {
}
}

const enum InvalidPosition {
enum InvalidPosition {
Value = -1
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ namespace ts {
}

const oldSourceFiles = oldProgram.getSourceFiles();
const enum SeenPackageName { Exists, Modified }
enum SeenPackageName { Exists, Modified }
const seenPackageNames = new Map<string, SeenPackageName>();

for (const oldSourceFile of oldSourceFiles) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ namespace ts {
export type FsWatch = (fileOrDirectory: string, entryKind: FileSystemEntryKind, callback: FsWatchCallback, recursive: boolean, fallbackPollingInterval: PollingInterval, fallbackOptions: WatchOptions | undefined) => FileWatcher;

/*@internal*/
export const enum FileSystemEntryKind {
export enum FileSystemEntryKind {
File,
Directory,
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
}
}

export const enum Phase {
export enum Phase {
Parse = "parse",
Program = "program",
Bind = "bind",
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace ts {
}
}

const enum TransformationState {
enum TransformationState {
Uninitialized,
Initialized,
Completed,
Disposed
}

const enum SyntaxKindFeatureFlags {
enum SyntaxKindFeatureFlags {
Substitution = 1 << 0,
EmitNotifications = 1 << 1,
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*@internal*/
namespace ts {
const enum ClassPropertySubstitutionFlags {
enum ClassPropertySubstitutionFlags {
/**
* Enables substitutions for class expressions with static fields
* which have initializers that reference the class name.
Expand All @@ -12,7 +12,7 @@ namespace ts {
*/
ClassStaticThisOrSuperReference = 1 << 1,
}
export const enum PrivateIdentifierKind {
export enum PrivateIdentifierKind {
Field = "f",
Method = "m",
Accessor = "a"
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace ts {
privateIdentifierEnvironment: PrivateIdentifierEnvironment | undefined;
}

const enum ClassFacts {
enum ClassFacts {
None = 0,
ClassWasDecorated = 1 << 0,
NeedsClassConstructorReference = 1 << 1,
Expand Down
Loading