Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: Inline 'parseExecutableDefinition' to simplify code #2069

Merged
merged 1 commit into from Aug 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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