From d130a6067227f541c4f04e5c9de6282f1a7409ed Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 1 Aug 2019 12:10:47 +0300 Subject: [PATCH] parser: Inline 'parseExecutableDefinition' to simplify code (#2069) --- src/language/parser.js | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/language/parser.js b/src/language/parser.js index cb3ae04446..4ec89102aa 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -19,7 +19,6 @@ import { type VariableNode, type DocumentNode, type DefinitionNode, - type ExecutableDefinitionNode, type OperationDefinitionNode, type OperationTypeNode, type VariableDefinitionNode, @@ -217,6 +216,10 @@ class Parser { * - ExecutableDefinition * - TypeSystemDefinition * - TypeSystemExtension + * + * ExecutableDefinition : + * - OperationDefinition + * - FragmentDefinition */ parseDefinition(): DefinitionNode { if (this.peek(TokenKind.NAME)) { @@ -224,8 +227,9 @@ class Parser { case 'query': case 'mutation': case 'subscription': + return this.parseOperationDefinition(); case 'fragment': - return this.parseExecutableDefinition(); + return this.parseFragmentDefinition(); case 'schema': case 'scalar': case 'type': @@ -239,7 +243,7 @@ class Parser { return this.parseTypeSystemExtension(); } } else if (this.peek(TokenKind.BRACE_L)) { - return this.parseExecutableDefinition(); + return this.parseOperationDefinition(); } else if (this.peekDescription()) { return this.parseTypeSystemDefinition(); } @@ -247,29 +251,6 @@ class Parser { throw this.unexpected(); } - /** - * ExecutableDefinition : - * - OperationDefinition - * - FragmentDefinition - */ - parseExecutableDefinition(): ExecutableDefinitionNode { - if (this.peek(TokenKind.NAME)) { - switch (this._lexer.token.value) { - case 'query': - case 'mutation': - case 'subscription': - return this.parseOperationDefinition(); - - case 'fragment': - return this.parseFragmentDefinition(); - } - } else if (this.peek(TokenKind.BRACE_L)) { - return this.parseOperationDefinition(); - } - - throw this.unexpected(); - } - // Implements the parsing rules in the Operations section. /**