Skip to content

Commit 791be1a

Browse files
parser: simplify parsing of null, boolean and enum values (#2432)
1 parent 04470e0 commit 791be1a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/language/parser.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -554,26 +554,21 @@ class Parser {
554554
case TokenKind.BLOCK_STRING:
555555
return this.parseStringLiteral();
556556
case TokenKind.NAME:
557-
if (token.value === 'true' || token.value === 'false') {
558-
this._lexer.advance();
559-
return {
560-
kind: Kind.BOOLEAN,
561-
value: token.value === 'true',
562-
loc: this.loc(token),
563-
};
564-
} else if (token.value === 'null') {
565-
this._lexer.advance();
566-
return {
567-
kind: Kind.NULL,
568-
loc: this.loc(token),
569-
};
570-
}
571557
this._lexer.advance();
572-
return {
573-
kind: Kind.ENUM,
574-
value: ((token.value: any): string),
575-
loc: this.loc(token),
576-
};
558+
switch (token.value) {
559+
case 'true':
560+
return { kind: Kind.BOOLEAN, value: true, loc: this.loc(token) };
561+
case 'false':
562+
return { kind: Kind.BOOLEAN, value: false, loc: this.loc(token) };
563+
case 'null':
564+
return { kind: Kind.NULL, loc: this.loc(token) };
565+
default:
566+
return {
567+
kind: Kind.ENUM,
568+
value: ((token.value: any): string),
569+
loc: this.loc(token),
570+
};
571+
}
577572
case TokenKind.DOLLAR:
578573
if (!isConst) {
579574
return this.parseVariable();

0 commit comments

Comments
 (0)