Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 30, 2021
1 parent 12b541b commit 0ecd247
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 46 deletions.
7 changes: 3 additions & 4 deletions .eslintrc.yml
Expand Up @@ -454,12 +454,11 @@ overrides:
- plugin:import/typescript
rules:
##########################################################################
# Validating TS Doc comments
# `eslint-plugin-tsdoc` rule list based on `v0.2.x`
# https://github.com/microsoft/tsdoc/tree/master/eslint-plugin
##########################################################################

# Supported Rules
# https://tsdoc.org/pages/packages/eslint-plugin-tsdoc/
'tsdoc/syntax': error
tsdoc/syntax: error

##########################################################################
# `@typescript-eslint/eslint-plugin` rule list based on `v4.25.x`
Expand Down
2 changes: 1 addition & 1 deletion src/__testUtils__/dedent.ts
Expand Up @@ -18,7 +18,7 @@ export function dedentString(string: string): string {
/**
* An ES6 string tag that fixes indentation and also trims string.
*
* Example Usage:
* Example usage:
* ```ts
* const str = dedent`
* {
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/starWarsSchema.ts
Expand Up @@ -59,6 +59,7 @@ import { getFriends, getHero, getHuman, getDroid } from './starWarsData';
* droid(id: String!): Droid
* }
* ```
*
* We begin by setting up our schema.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/error/formatError.ts
Expand Up @@ -21,7 +21,7 @@ export function formatError(error: GraphQLError): GraphQLFormattedError {
}

/**
* @see {@link https://github.com/graphql/graphql-spec/blob/main/spec/Section%207%20--%20Response.md#errors | Errors}
* See: https://spec.graphql.org/draft/#sec-Errors
*/
export interface GraphQLFormattedError {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.ts
Expand Up @@ -82,9 +82,9 @@ import {
*
* "Selections" are the definitions that can appear legally and at
* single level of the query. These include:
* 1) field references e.g `"a"`
* 2) fragment "spreads" e.g. `"...c"`
* 3) inline fragment "spreads" e.g. `"...on Type { a }"`
* 1) field references e.g `a`
* 2) fragment "spreads" e.g. `...c`
* 3) inline fragment "spreads" e.g. `...on Type { a }`
*/

/**
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -15,8 +15,9 @@
* This also includes utility functions for operating on GraphQL types and
* GraphQL documents to facilitate building tools.
*
* You may also import from each sub-directory directly.
* the following two import statements are equivalent:
* You may also import from each sub-directory directly. For example, the
* following two import statements are equivalent:
*
* ```ts
* import { parse } from 'graphql';
* import { parse } from 'graphql/language';
Expand Down
10 changes: 7 additions & 3 deletions src/jsutils/keyMap.ts
Expand Up @@ -12,15 +12,19 @@ import type { ObjMap } from './ObjMap';
* { name: 'Jenny', num: '867-5309' }
* ]
*
* // { Jon: { name: 'Jon', num: '555-1234' },
* // Jenny: { name: 'Jenny', num: '867-5309' } }
* const entriesByName = keyMap(
* phoneBook,
* entry => entry.name
* )
*
* // { name: 'Jenny', num: '857-6309' }
* // {
* // Jon: { name: 'Jon', num: '555-1234' },
* // Jenny: { name: 'Jenny', num: '867-5309' }
* // }
*
* const jennyEntry = entriesByName['Jenny']
*
* // { name: 'Jenny', num: '857-6309' }
* ```
*/
export function keyMap<T>(
Expand Down
62 changes: 39 additions & 23 deletions src/language/lexer.ts
Expand Up @@ -107,20 +107,22 @@ export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean {
);
}

/*
/**
* ```
* SourceCharacter ::
* - U+0009 (Horizontal Tab)
* - U+000A (New Line)
* - U+000D (Carriage Return)
* - U+0020-U+FFFF
* ```
*/
function isSourceCharacter(code: number): boolean {
return (
code >= 0x0020 || code === 0x0009 || code === 0x000a || code === 0x000d
);
}

/*
/**
* Prints the code point (or end of file reference) at a given location in a
* source for use in error messages.
*
Expand All @@ -143,7 +145,7 @@ function printCodePointAt(lexer: Lexer, location: number): string {
return `U+${zeroPad}${code.toString(16).toUpperCase()}`;
}

/*
/**
* Create a token with line and column location information.
*/
function createToken(
Expand All @@ -158,7 +160,7 @@ function createToken(
return new Token(kind, start, end, line, col, value);
}

/*
/**
* Gets the next token from the source starting at the given position.
*
* This skips over whitespace until it finds the next lexable token, then lexes
Expand Down Expand Up @@ -293,12 +295,14 @@ function readNextToken(lexer: Lexer, start: number): Token {
return createToken(lexer, TokenKind.EOF, bodyLength, bodyLength);
}

/*
/**
* Reads a comment token from the source file.
*
* ```
* Comment :: # CommentChar* [lookahead != CommentChar]
*
* CommentChar :: SourceCharacter but not LineTerminator
* ```
*/
function readComment(lexer: Lexer, start: number): Token {
const body = lexer.source.body;
Expand Down Expand Up @@ -330,10 +334,11 @@ function readComment(lexer: Lexer, start: number): Token {
);
}

/*
/**
* Reads a number token from the source file, either a FloatValue or an IntValue
* depending on whether a FractionalPart or ExponentPart is encountered.
*
* ```
* IntValue :: IntegerPart [lookahead != {Digit, `.`, NameStart}]
*
* IntegerPart ::
Expand All @@ -356,6 +361,7 @@ function readComment(lexer: Lexer, start: number): Token {
* ExponentIndicator :: one of `e` `E`
*
* Sign :: one of + -
* ```
*/
function readNumber(lexer: Lexer, start: number, firstCode: number): Token {
const body = lexer.source.body;
Expand Down Expand Up @@ -429,7 +435,7 @@ function readNumber(lexer: Lexer, start: number, firstCode: number): Token {
);
}

/*
/**
* Returns the new position in the source after reading one or more digits.
*/
function readDigits(lexer: Lexer, start: number, firstCode: number): number {
Expand All @@ -455,9 +461,10 @@ function readDigits(lexer: Lexer, start: number, firstCode: number): number {
return position;
}

/*
/**
* Reads a single-quote string token from the source file.
*
* ```
* StringValue ::
* - `""` [lookahead != `"`]
* - `"` StringCharacter+ `"`
Expand All @@ -470,6 +477,7 @@ function readDigits(lexer: Lexer, start: number, firstCode: number): number {
* EscapedUnicode :: /[0-9A-Fa-f]{4}/
*
* EscapedCharacter :: one of `"` `\` `/` `b` `f` `n` `r` `t`
* ```
*/
function readString(lexer: Lexer, start: number): Token {
const body = lexer.source.body;
Expand Down Expand Up @@ -544,7 +552,7 @@ function readEscapedUnicode(lexer: Lexer, position: number): EscapeSequence {
);
}

/*
/**
* Reads four hexadecimal characters and returns the positive integer that 16bit
* hexadecimal string represents. For example, "000f" will return 15, and "dead"
* will return 57005.
Expand All @@ -562,7 +570,7 @@ function read16BitHexCode(body: string, position: number): number {
);
}

/*
/**
* Reads a hexadecimal character and returns its positive integer value (0-15).
*
* '0' becomes 0, '9' becomes 9
Expand All @@ -581,17 +589,17 @@ function readHexDigit(code: number): number {
: -1;
}

/*
/**
* | Escaped Character | Code Point | Character Name |
* | ----------------- | ---------- | ---------------------------- |
* | {`"`} | U+0022 | double quote |
* | {`\`} | U+005C | reverse solidus (back slash) |
* | {`/`} | U+002F | solidus (forward slash) |
* | {`b`} | U+0008 | backspace |
* | {`f`} | U+000C | form feed |
* | {`n`} | U+000A | line feed (new line) |
* | {`r`} | U+000D | carriage return |
* | {`t`} | U+0009 | horizontal tab |
* | `"` | U+0022 | double quote |
* | `\` | U+005C | reverse solidus (back slash) |
* | `/` | U+002F | solidus (forward slash) |
* | `b` | U+0008 | backspace |
* | `f` | U+000C | form feed |
* | `n` | U+000A | line feed (new line) |
* | `r` | U+000D | carriage return |
* | `t` | U+0009 | horizontal tab |
*/
function readEscapedCharacter(lexer: Lexer, position: number): EscapeSequence {
const body = lexer.source.body;
Expand Down Expand Up @@ -624,15 +632,17 @@ function readEscapedCharacter(lexer: Lexer, position: number): EscapeSequence {
);
}

/*
/**
* Reads a block string token from the source file.
*
* ```
* StringValue ::
* - `"""` BlockStringCharacter* `"""`
*
* BlockStringCharacter ::
* - SourceCharacter but not `"""` or `\"""`
* - `\"""`
* ```
*/
function readBlockString(lexer: Lexer, start: number): Token {
const body = lexer.source.body;
Expand Down Expand Up @@ -703,9 +713,10 @@ function readBlockString(lexer: Lexer, start: number): Token {
throw syntaxError(lexer.source, position, 'Unterminated string.');
}

/*
/**
* Reads an alphanumeric + underscore name from the source.
*
* ```
* Name ::
* - NameStart NameContinue* [lookahead != NameContinue]
*
Expand All @@ -717,6 +728,7 @@ function readBlockString(lexer: Lexer, start: number): Token {
* - Letter
* - Digit
* - `_`
* ```
*/
function readName(lexer: Lexer, start: number): Token {
const body = lexer.source.body;
Expand Down Expand Up @@ -746,20 +758,24 @@ function isNameStart(code: number): boolean {
return isLetter(code) || code === 0x005f;
}

/*
/**
* ```
* Digit :: one of
* - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
* ```
*/
function isDigit(code: number): boolean {
return code >= 0x0030 && code <= 0x0039;
}

/*
/**
* ```
* Letter :: one of
* - `A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M`
* - `N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
* - `a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
* - `n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
* ```
*/
function isLetter(code: number): boolean {
return (
Expand Down
3 changes: 1 addition & 2 deletions src/language/printer.ts
Expand Up @@ -316,8 +316,7 @@ function join(
}

/**
* Given array, print each item on its own line, wrapped in an
* indented `"{ }"` block.
* Given array, print each item on its own line, wrapped in an indented `{ }` block.
*/
function block(array: Maybe<ReadonlyArray<string | undefined>>): string {
return wrap('{\n', indent(join(array, '\n')), '\n}');
Expand Down
17 changes: 11 additions & 6 deletions src/language/visitor.ts
Expand Up @@ -178,7 +178,7 @@ export const BREAK: unknown = Object.freeze({});
* a new version of the AST with the changes applied will be returned from the
* visit function.
*
* ```
* ```ts
* const editedAST = visit(ast, {
* enter(node, key, parent, path, ancestors) {
* // @return
Expand All @@ -198,22 +198,25 @@ export const BREAK: unknown = Object.freeze({});
* }
* });
* ```
*
* Alternatively to providing enter() and leave() functions, a visitor can
* instead provide functions named the same as the kinds of AST nodes, or
* enter/leave visitors at a named key, leading to three permutations of the
* visitor API:
*
* 1) Named visitors triggered when entering a node of a specific kind.
* ```
*
* ```ts
* visit(ast, {
* Kind(node) {
* // enter the "Kind" node
* }
* })
* ```
* 2) Named visitors that trigger upon entering and leaving a node of
* a specific kind.
* ```
*
* 2) Named visitors that trigger upon entering and leaving a node of a specific kind.
*
* ```ts
* visit(ast, {
* Kind: {
* enter(node) {
Expand All @@ -225,8 +228,10 @@ export const BREAK: unknown = Object.freeze({});
* }
* })
* ```
*
* 3) Generic visitors that trigger upon entering and leaving any node.
* ```
*
* ```ts
* visit(ast, {
* enter(node) {
* // enter any node
Expand Down

0 comments on commit 0ecd247

Please sign in to comment.