From fd3f37c865008d2548c92cfa31f2dee67b050a77 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 3 Feb 2020 12:39:00 +0800 Subject: [PATCH] Use explicit default arguments --- src/language/printer.js | 8 ++++---- src/language/source.js | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/language/printer.js b/src/language/printer.js index 71569529bd..85b45ba053 100644 --- a/src/language/printer.js +++ b/src/language/printer.js @@ -255,8 +255,8 @@ function addDescription(cb) { * Given maybeArray, print an empty string if it is null or empty, otherwise * print all items together separated by separator if provided */ -function join(maybeArray, separator) { - return maybeArray ? maybeArray.filter(x => x).join(separator || '') : ''; +function join(maybeArray: ?Array, separator = '') { + return maybeArray?.filter(x => x).join(separator) || ''; } /** @@ -273,8 +273,8 @@ function block(array) { * If maybeString is not null or empty, then wrap with start and end, otherwise * print an empty string. */ -function wrap(start, maybeString, end) { - return maybeString ? start + maybeString + (end || '') : ''; +function wrap(start, maybeString, end = '') { + return maybeString ? start + maybeString + end : ''; } function indent(maybeString) { diff --git a/src/language/source.js b/src/language/source.js index e9ff700a18..961205a2cf 100644 --- a/src/language/source.js +++ b/src/language/source.js @@ -22,10 +22,14 @@ export class Source { name: string; locationOffset: Location; - constructor(body: string, name?: string, locationOffset?: Location): void { + constructor( + body: string, + name: string = 'GraphQL request', + locationOffset: Location = { line: 1, column: 1 }, + ): void { this.body = body; - this.name = name != null ? name : 'GraphQL request'; - this.locationOffset = locationOffset || { line: 1, column: 1 }; + this.name = name; + this.locationOffset = locationOffset; devAssert( this.locationOffset.line > 0, 'line in locationOffset is 1-indexed and must be positive.',