Skip to content

Commit d130a60

Browse files
parser: Inline 'parseExecutableDefinition' to simplify code (#2069)
1 parent b13f283 commit d130a60

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

src/language/parser.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
type VariableNode,
2020
type DocumentNode,
2121
type DefinitionNode,
22-
type ExecutableDefinitionNode,
2322
type OperationDefinitionNode,
2423
type OperationTypeNode,
2524
type VariableDefinitionNode,
@@ -217,15 +216,20 @@ class Parser {
217216
* - ExecutableDefinition
218217
* - TypeSystemDefinition
219218
* - TypeSystemExtension
219+
*
220+
* ExecutableDefinition :
221+
* - OperationDefinition
222+
* - FragmentDefinition
220223
*/
221224
parseDefinition(): DefinitionNode {
222225
if (this.peek(TokenKind.NAME)) {
223226
switch (this._lexer.token.value) {
224227
case 'query':
225228
case 'mutation':
226229
case 'subscription':
230+
return this.parseOperationDefinition();
227231
case 'fragment':
228-
return this.parseExecutableDefinition();
232+
return this.parseFragmentDefinition();
229233
case 'schema':
230234
case 'scalar':
231235
case 'type':
@@ -239,37 +243,14 @@ class Parser {
239243
return this.parseTypeSystemExtension();
240244
}
241245
} else if (this.peek(TokenKind.BRACE_L)) {
242-
return this.parseExecutableDefinition();
246+
return this.parseOperationDefinition();
243247
} else if (this.peekDescription()) {
244248
return this.parseTypeSystemDefinition();
245249
}
246250

247251
throw this.unexpected();
248252
}
249253

250-
/**
251-
* ExecutableDefinition :
252-
* - OperationDefinition
253-
* - FragmentDefinition
254-
*/
255-
parseExecutableDefinition(): ExecutableDefinitionNode {
256-
if (this.peek(TokenKind.NAME)) {
257-
switch (this._lexer.token.value) {
258-
case 'query':
259-
case 'mutation':
260-
case 'subscription':
261-
return this.parseOperationDefinition();
262-
263-
case 'fragment':
264-
return this.parseFragmentDefinition();
265-
}
266-
} else if (this.peek(TokenKind.BRACE_L)) {
267-
return this.parseOperationDefinition();
268-
}
269-
270-
throw this.unexpected();
271-
}
272-
273254
// Implements the parsing rules in the Operations section.
274255

275256
/**

0 commit comments

Comments
 (0)