Skip to content

Commit

Permalink
Improve parser location API (#3061)
Browse files Browse the repository at this point in the history
This replaces manual assignment of `loc` on each node in Parser with a `node()` function. This simplifies the parser and also ensures the `loc` field does not appear at all when `noLocation` is provided.
  • Loading branch information
leebyron committed May 6, 2021
1 parent a4e9bc9 commit 002fb91
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 158 deletions.
7 changes: 4 additions & 3 deletions src/language/parser.d.ts
Expand Up @@ -3,7 +3,6 @@ import { GraphQLError } from '../error/GraphQLError';

import {
Token,
Location,
NameNode,
VariableNode,
DocumentNode,
Expand Down Expand Up @@ -501,9 +500,11 @@ export declare class Parser {
parseDirectiveLocation(): NameNode;

/**
* Returns a location object, used to identify the place in the source that created a given parsed object.
* Returns a node that, if configured to do so, sets a "loc" field as a
* location object, used to identify the place in the source that created a
* given parsed object.
*/
loc(startToken: Token): Location | undefined;
node<T>(startToken: Token, node: T): T;

/**
* Determines if the next token is of a given kind
Expand Down

0 comments on commit 002fb91

Please sign in to comment.