Skip to content

Commit

Permalink
Replace const enum with enum (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanBoltonMN authored Mar 28, 2024
1 parent d8d9d54 commit a92d1f0
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/powerquery-parser",
"version": "0.15.8",
"version": "0.15.9",
"description": "A parser for the Power Query/M formula language.",
"author": "Microsoft",
"license": "MIT",
Expand Down Expand Up @@ -57,4 +57,4 @@
"files": [
"lib/powerquery-parser/**/*"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type PartialResult<Ok, Partial, Error> =
| PartialResultIncomplete<Partial>
| PartialResultError<Error>;

export const enum PartialResultKind {
export enum PartialResultKind {
Ok = "Ok",
Incomplete = "Incomplete",
Error = "Error",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/result/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export type Result<T, E> = OkResult<T> | ErrorResult<E>;

export const enum ResultKind {
export enum ResultKind {
Ok = "Ok",
Error = "Error",
}
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface FoundQuotes {
readonly quoteLength: number;
}

export const enum NewlineKind {
export enum NewlineKind {
SingleCharacter = "SingleCharacter",
DoubleCharacter = "DoubleCharacter", // CARRIAGE RETURN + LINE FEED
}
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import performanceNow = require("performance-now");
// foobar(10);

// Constants used in multiple files as part of a trace's phase/task/message/details.
export const enum TraceConstant {
export enum TraceConstant {
CorrelationId = "CorrelationId",
Empty = "[Empty]",
Entry = "Entry",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type TExpandNodesFn<State extends ITraversalState<ResultType>, ResultType
collection: NodesById,
) => Promise<ReadonlyArray<Node>>;

export const enum VisitNodeStrategy {
export enum VisitNodeStrategy {
BreadthFirst = "BreadthFirst",
DepthFirst = "DepthFirst",
}
Expand Down
8 changes: 4 additions & 4 deletions src/powerquery-parser/language/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Constant } from "..";
import { TokenRange } from "../token";

export const enum NodeKind {
export enum NodeKind {
ArithmeticExpression = "ArithmeticExpression",
ArrayWrapper = "ArrayWrapper",
AsExpression = "AsExpression",
Expand Down Expand Up @@ -355,7 +355,7 @@ export type TPrimaryExpression =
// ---------- 12.2.3.11 Literal expression ----------
// --------------------------------------------------

export const enum LiteralKind {
export enum LiteralKind {
List = "List",
Logical = "Logical",
Null = "Null",
Expand Down Expand Up @@ -557,7 +557,7 @@ export type ErrorRaisingExpression = IPairedConstant<
// ---------- 12.2.3.27 Error handling expression ----------
// ---------------------------------------------------------

export const enum ErrorHandlerKind {
export enum ErrorHandlerKind {
Catch = "Catch",
Otherwise = "Otherwise",
}
Expand Down Expand Up @@ -883,7 +883,7 @@ export interface Identifier extends INode {
readonly identifierContextKind: IdentifierContextKind;
}

export const enum IdentifierContextKind {
export enum IdentifierContextKind {
Key = "Key",
Keyword = "Keyword",
Parameter = "Parameter",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TokenPosition } from "./token";

export type TComment = LineComment | MultilineComment;

export const enum CommentKind {
export enum CommentKind {
Line = "Line",
Multiline = "Multiline",
}
Expand Down
20 changes: 10 additions & 10 deletions src/powerquery-parser/language/constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export type TBinOpExpressionOperator =
// ---------- const enums ----------
// ---------------------------------

export const enum LanguageConstant {
export enum LanguageConstant {
Catch = "catch",
Nullable = "nullable",
Optional = "optional",
}

export const enum KeywordConstant {
export enum KeywordConstant {
As = "as",
Each = "each",
Else = "else",
Expand All @@ -54,7 +54,7 @@ export const enum KeywordConstant {
}

// Mostly direct mappings from their respective TokenKind
export const enum MiscConstant {
export enum MiscConstant {
Ampersand = "&",
AtSign = "@",
Comma = ",",
Expand All @@ -67,7 +67,7 @@ export const enum MiscConstant {
QuestionMark = "?",
}

export const enum PrimitiveTypeConstant {
export enum PrimitiveTypeConstant {
Action = "action",
Any = "any",
AnyNonNull = "anynonnull",
Expand All @@ -89,7 +89,7 @@ export const enum PrimitiveTypeConstant {
Type = "type",
}

export const enum WrapperConstant {
export enum WrapperConstant {
LeftBrace = "{",
LeftBracket = "[",
LeftParenthesis = "(",
Expand All @@ -102,32 +102,32 @@ export const enum WrapperConstant {
// ---------- operator const enums ----------
// ------------------------------------------

export const enum ArithmeticOperator {
export enum ArithmeticOperator {
Multiplication = "*",
Division = "/",
Addition = "+",
Subtraction = "-",
And = "&",
}

export const enum EqualityOperator {
export enum EqualityOperator {
EqualTo = "=",
NotEqualTo = "<>",
}

export const enum LogicalOperator {
export enum LogicalOperator {
And = "and",
Or = "or",
}

export const enum RelationalOperator {
export enum RelationalOperator {
LessThan = "<",
LessThanEqualTo = "<=",
GreaterThan = ">",
GreaterThanEqualTo = ">=",
}

export const enum UnaryOperator {
export enum UnaryOperator {
Positive = "+",
Negative = "-",
Not = "not",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/keyword/keyword.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const enum KeywordKind {
export enum KeywordKind {
And = "and",
As = "as",
Each = "each",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/textUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { Assert, Pattern, StringUtils } from "../common";

export const enum IdentifierKind {
export enum IdentifierKind {
Generalized = "Generalized",
Invalid = "Invalid",
Quote = "Quote",
Expand Down
6 changes: 3 additions & 3 deletions src/powerquery-parser/language/token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const enum LineTokenKindAdditions {
export enum LineTokenKindAdditions {
LineComment = "LineComment",
MultilineComment = "MultilineComment",
MultilineCommentContent = "MultilineCommentContent",
Expand All @@ -15,7 +15,7 @@ export const enum LineTokenKindAdditions {
QuotedIdentifierStart = "QuotedIdentifierStart",
}

export const enum TokenKind {
export enum TokenKind {
Ampersand = "Ampersand",
Asterisk = "Asterisk",
AtSign = "AtSign",
Expand Down Expand Up @@ -80,7 +80,7 @@ export const enum TokenKind {
TextLiteral = "TextLiteral",
}

export const enum LineTokenKind {
export enum LineTokenKind {
Ampersand = TokenKind.Ampersand,
Asterisk = TokenKind.Asterisk,
AtSign = TokenKind.AtSign,
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/language/type/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export type TFields = OrderedFields | UnorderedFields;
export type OrderedFields = OrderedMap<string, TPowerQueryType>;
export type UnorderedFields = Map<string, TPowerQueryType>;

export const enum TypeKind {
export enum TypeKind {
Any = "Any",
AnyNonNull = "AnyNonNull",
Binary = "Binary",
Expand Down Expand Up @@ -168,7 +168,7 @@ export const TypeKinds: ReadonlyArray<TypeKind> = [
TypeKind.Type,
];

export const enum ExtendedTypeKind {
export enum ExtendedTypeKind {
// In Power Query if you want a union type, such as when a function returns either a `text` OR a `number`,
// then you're only option is to give it the 'any' type.
// This is a narrower definition which restricts that typing to the union `text | number`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const enum TypeUtilsTraceConstant {
export enum TypeUtilsTraceConstant {
AnyUnion = "CreateAnyUnion",
Categorize = "Categorize",
IsCompatible = "IsCompatible",
Expand Down
8 changes: 4 additions & 4 deletions src/powerquery-parser/lexer/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export type TInnerLexError =
| UnexpectedReadError
| UnterminatedMultilineTokenError;

export const enum BadLineNumberKind {
export enum BadLineNumberKind {
LessThanZero = "LessThanZero",
GreaterThanNumLines = "GreaterThanNumLines",
}

// do not these sort variants,
// they are in order that logical checks are made, which in turn help create logical variants
export const enum BadRangeKind {
export enum BadRangeKind {
SameLine_LineCodeUnitStart_Higher = "SameLine_LineCodeUnitStart_Higher",
LineNumberStart_GreaterThan_LineNumberEnd = "LineNumberStart_GreaterThan_LineNumberEnd",
LineNumberStart_LessThan_Zero = "LineNumberStart_LessThan_Zero",
Expand All @@ -35,13 +35,13 @@ export const enum BadRangeKind {
LineCodeUnitEnd_GreaterThan_LineLength = "LineCodeUnitEnd_GreaterThan_LineLength",
}

export const enum ExpectedKind {
export enum ExpectedKind {
HexLiteral = "HexLiteral",
KeywordOrIdentifier = "KeywordOrIdentifier",
Numeric = "Numeric",
}

export const enum UnterminatedMultilineTokenKind {
export enum UnterminatedMultilineTokenKind {
MultilineComment = "MultilineComment",
QuotedIdentifier = "QuotedIdentifier",
Text = "Text",
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/lexer/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type TLine = TouchedLine | UntouchedLine | TouchedWithErrorLine | ErrorLi

export type TErrorLine = ErrorLine | TouchedWithErrorLine;

export const enum LineKind {
export enum LineKind {
Error = "Error",
Touched = "Touched",
TouchedWithError = "TouchedWithError",
Expand All @@ -53,7 +53,7 @@ export const enum LineKind {
// * Continuation of a multiline token (eg. multiline comment)
//
// All LineModes other than Default are a type of multiline tokenization.
export const enum LineMode {
export enum LineMode {
Comment = "Comment",
Default = "Default",
QuotedIdentifier = "QuotedIdentifier",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/localization/locale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const enum Locale {
export enum Locale {
bg_BG = "bg-BG",
ca_EZ = "ca-EZ",
cs_CZ = "cs-CZ",
Expand Down
6 changes: 3 additions & 3 deletions src/powerquery-parser/parser/disambiguation/disambiguation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ export type TAmbiguousBracketNode = Ast.FieldProjection | Ast.FieldSelector | As

export type TAmbiguousParenthesisNode = Ast.FunctionExpression | Ast.ParenthesizedExpression | Ast.TLogicalExpression;

export const enum DismabiguationBehavior {
export enum DismabiguationBehavior {
Strict = "Strict",
Thorough = "Thorough",
}

export const enum BracketDisambiguation {
export enum BracketDisambiguation {
FieldProjection = "FieldProjection",
FieldSelection = "FieldSelection",
RecordExpression = "RecordExpression",
}

export const enum ParenthesisDisambiguation {
export enum ParenthesisDisambiguation {
FunctionExpression = "FunctionExpression",
ParenthesizedExpression = "ParenthesizedExpression",
}
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/parser/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export type TInnerParseError =
| UnterminatedSequence
| UnusedTokensRemainError;

export const enum CsvContinuationKind {
export enum CsvContinuationKind {
DanglingComma = "DanglingComma",
LetExpression = "LetExpression",
}

export const enum SequenceKind {
export enum SequenceKind {
Bracket = "Bracket",
Parenthesis = "Parenthesis",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface SectionKeyValuePair extends IKeyValuePair<Ast.Identifier> {
readonly pairKind: PairKind.SectionMember;
}

export const enum PairKind {
export enum PairKind {
FieldSpecification = "RecordType",
LetExpression = "LetExpression",
Record = "Record",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/nodeIdMap/xorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Ast } from "../../language";
import { ParseContext } from "..";

export const enum XorNodeKind {
export enum XorNodeKind {
Ast = "Ast",
Context = "Context",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ast } from "../../../language";

export type TOperand = Ast.TBinOpExpression | Ast.TUnaryExpression | Ast.TNullablePrimitiveType;

export const enum CombinatorialParserV2TraceConstant {
export enum CombinatorialParserV2TraceConstant {
CombinatorialParseV2 = "CombinatorialParseV2",
}

Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/task/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type TriedParseTask = ParseTaskOk | ParseTaskCommonError | ParseTaskParse

export type TriedLexParseTask = LexTaskError | TriedParseTask;

export const enum TaskStage {
export enum TaskStage {
Lex = "Lex",
Parse = "Parse",
}
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "lib",
"preserveConstEnums": true,
"resolveJsonModule": true,
"rootDir": "src",
"sourceMap": true,
Expand Down

0 comments on commit a92d1f0

Please sign in to comment.