Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: allow 'options' to explicitly accept undefined #3701

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/language/parser.ts
Original file line number Diff line number Diff line change
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