From 8c7e495ce256b7d07a36548565a1e2f6edda7c7b Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 4 Feb 2020 15:56:57 +0800 Subject: [PATCH] parser: simplify parsing of null, boolean and enum values --- src/language/parser.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/language/parser.js b/src/language/parser.js index 4ada62dcbd..2fdcdc6ab6 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -554,26 +554,21 @@ class Parser { case TokenKind.BLOCK_STRING: return this.parseStringLiteral(); case TokenKind.NAME: - if (token.value === 'true' || token.value === 'false') { - this._lexer.advance(); - return { - kind: Kind.BOOLEAN, - value: token.value === 'true', - loc: this.loc(token), - }; - } else if (token.value === 'null') { - this._lexer.advance(); - return { - kind: Kind.NULL, - loc: this.loc(token), - }; - } this._lexer.advance(); - return { - kind: Kind.ENUM, - value: ((token.value: any): string), - loc: this.loc(token), - }; + switch (token.value) { + case 'true': + return { kind: Kind.BOOLEAN, value: true, loc: this.loc(token) }; + case 'false': + return { kind: Kind.BOOLEAN, value: false, loc: this.loc(token) }; + case 'null': + return { kind: Kind.NULL, loc: this.loc(token) }; + default: + return { + kind: Kind.ENUM, + value: ((token.value: any): string), + loc: this.loc(token), + }; + } case TokenKind.DOLLAR: if (!isConst) { return this.parseVariable();