Skip to content

Commit

Permalink
parser: Inline 'parseExecutableDefinition' to simplify code (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 1, 2019
1 parent b13f283 commit d130a60
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions src/language/parser.js
Expand Up @@ -19,7 +19,6 @@ import {
type VariableNode,
type DocumentNode,
type DefinitionNode,
type ExecutableDefinitionNode,
type OperationDefinitionNode,
type OperationTypeNode,
type VariableDefinitionNode,
Expand Down Expand Up @@ -217,15 +216,20 @@ class Parser {
* - ExecutableDefinition
* - TypeSystemDefinition
* - TypeSystemExtension
*
* ExecutableDefinition :
* - OperationDefinition
* - FragmentDefinition
*/
parseDefinition(): DefinitionNode {
if (this.peek(TokenKind.NAME)) {
switch (this._lexer.token.value) {
case 'query':
case 'mutation':
case 'subscription':
return this.parseOperationDefinition();
case 'fragment':
return this.parseExecutableDefinition();
return this.parseFragmentDefinition();
case 'schema':
case 'scalar':
case 'type':
Expand All @@ -239,37 +243,14 @@ 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();
}

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.

/**
Expand Down

0 comments on commit d130a60

Please sign in to comment.