Skip to content

Commit

Permalink
Parser: allow 'options' to explicitly accept undefined (#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 16, 2022
1 parent af8221a commit 6c6508b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/language/parser.ts
Expand Up @@ -102,7 +102,7 @@ export interface ParseOptions {
*/
export function parse(
source: string | Source,
options?: ParseOptions,
options?: ParseOptions | undefined,
): DocumentNode {
const parser = new Parser(source, options);
return parser.parseDocument();
Expand All @@ -120,7 +120,7 @@ export function parse(
*/
export function parseValue(
source: string | Source,
options?: ParseOptions,
options?: ParseOptions | undefined,
): ValueNode {
const parser = new Parser(source, options);
parser.expectToken(TokenKind.SOF);
Expand All @@ -135,7 +135,7 @@ export function parseValue(
*/
export function parseConstValue(
source: string | Source,
options?: ParseOptions,
options?: ParseOptions | undefined,
): ConstValueNode {
const parser = new Parser(source, options);
parser.expectToken(TokenKind.SOF);
Expand All @@ -156,7 +156,7 @@ export function parseConstValue(
*/
export function parseType(
source: string | Source,
options?: ParseOptions,
options?: ParseOptions | undefined,
): TypeNode {
const parser = new Parser(source, options);
parser.expectToken(TokenKind.SOF);
Expand All @@ -177,10 +177,10 @@ export function parseType(
* @internal
*/
export class Parser {
protected _options: Maybe<ParseOptions>;
protected _options: ParseOptions;
protected _lexer: Lexer;

constructor(source: string | Source, options?: ParseOptions) {
constructor(source: string | Source, options: ParseOptions = {}) {
const sourceObj = isSource(source) ? source : new Source(source);

this._lexer = new Lexer(sourceObj);
Expand Down Expand Up @@ -510,7 +510,7 @@ export class Parser {
// Legacy support for defining variables within fragments changes
// the grammar of FragmentDefinition:
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
if (this._options?.allowLegacyFragmentVariables === true) {
if (this._options.allowLegacyFragmentVariables === true) {
return this.node<FragmentDefinitionNode>(start, {
kind: Kind.FRAGMENT_DEFINITION,
name: this.parseFragmentName(),
Expand Down Expand Up @@ -1387,7 +1387,7 @@ export class Parser {
* given parsed object.
*/
node<T extends { loc?: Location }>(startToken: Token, node: T): T {
if (this._options?.noLocation !== true) {
if (this._options.noLocation !== true) {
node.loc = new Location(
startToken,
this._lexer.lastToken,
Expand Down

0 comments on commit 6c6508b

Please sign in to comment.