Skip to content

Commit 6c6508b

Browse files
Parser: allow 'options' to explicitly accept undefined (#3701)
1 parent af8221a commit 6c6508b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/language/parser.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface ParseOptions {
102102
*/
103103
export function parse(
104104
source: string | Source,
105-
options?: ParseOptions,
105+
options?: ParseOptions | undefined,
106106
): DocumentNode {
107107
const parser = new Parser(source, options);
108108
return parser.parseDocument();
@@ -120,7 +120,7 @@ export function parse(
120120
*/
121121
export function parseValue(
122122
source: string | Source,
123-
options?: ParseOptions,
123+
options?: ParseOptions | undefined,
124124
): ValueNode {
125125
const parser = new Parser(source, options);
126126
parser.expectToken(TokenKind.SOF);
@@ -135,7 +135,7 @@ export function parseValue(
135135
*/
136136
export function parseConstValue(
137137
source: string | Source,
138-
options?: ParseOptions,
138+
options?: ParseOptions | undefined,
139139
): ConstValueNode {
140140
const parser = new Parser(source, options);
141141
parser.expectToken(TokenKind.SOF);
@@ -156,7 +156,7 @@ export function parseConstValue(
156156
*/
157157
export function parseType(
158158
source: string | Source,
159-
options?: ParseOptions,
159+
options?: ParseOptions | undefined,
160160
): TypeNode {
161161
const parser = new Parser(source, options);
162162
parser.expectToken(TokenKind.SOF);
@@ -177,10 +177,10 @@ export function parseType(
177177
* @internal
178178
*/
179179
export class Parser {
180-
protected _options: Maybe<ParseOptions>;
180+
protected _options: ParseOptions;
181181
protected _lexer: Lexer;
182182

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

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

0 commit comments

Comments
 (0)