Skip to content

Commit 002fb91

Browse files
authored
Improve parser location API (#3061)
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.
1 parent a4e9bc9 commit 002fb91

File tree

3 files changed

+104
-158
lines changed

3 files changed

+104
-158
lines changed

src/language/parser.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { GraphQLError } from '../error/GraphQLError';
33

44
import {
55
Token,
6-
Location,
76
NameNode,
87
VariableNode,
98
DocumentNode,
@@ -501,9 +500,11 @@ export declare class Parser {
501500
parseDirectiveLocation(): NameNode;
502501

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

508509
/**
509510
* Determines if the next token is of a given kind

0 commit comments

Comments
 (0)