Skip to content

Typescript parsing issue with @ symbol in docstring #147

@johncsnyder

Description

@johncsnyder

With this example.d.ts:

/**
 * Some documentation
 *
 * @see https://example.org
 */
type Foo = string;

Running flowgen ./example.d.ts I get the following

(node:16376) ExperimentalWarning: The fs.promises API is experimental

    ts.SyntaxKind[type.kind]: JSDocNameReference
    name:
    kind: 303
    type: JSDocNameReference { pos: 38,
  end: 38,
  flags: 12582912,
  modifierFlagsCache: 0,
  transformFlags: 0,
  kind: 303,
  name:
   Identifier { pos: 38,
     end: 38,
     flags: 12648448,
     modifierFlagsCache: 0,
     transformFlags: 0,
     kind: 78,
     originalKeywordKind: undefined,
     escapedText: '' } }

: /* NO PRINT IMPLEMENTED: JSDocNameReference */ any
Parsing example
{ SyntaxError: Unterminated regular expression. (11:4)
   9 |  * Some documentation
  10 |  * @see : /* NO PRINT IMPLEMENTED: JSDocNameReference */ any
> 11 |  */
     |    ^
  12 | declare type Foo = string;
    at ir ([...]/node_modules/prettier/parser-babel.js:22:7277)
    at En ([...]/node_modules/prettier/parser-babel.js:22:66392)
    at Object.parse ([...]/node_modules/prettier/parser-babel.js:22:332006)
    at Object.parse$a [as parse] ([...]/node_modules/prettier/index.js:13684:19)
    at coreFormat ([...]/node_modules/prettier/index.js:15215:16)
    at formatWithCursor$1 ([...]/node_modules/prettier/index.js:15455:14)
    at args ([...]/node_modules/prettier/index.js:60228:12)
    at Object.format ([...]/node_modules/prettier/index.js:60248:12)
    at beautify ([...]/node_modules/flowgen/lib/cli/beautifier.js:11:28)
    at outputFile ([...]/node_modules/flowgen/lib/cli/runner.js:40:38)
  loc: { start: { line: 11, column: 4 } },
  codeFrame:
   '\u001b[0m \u001b[90m  9 |\u001b[39m \u001b[90m * Some documentations\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 10 |\u001b[39m \u001b[90m * @see : /* NO PRINT IMPLEMENTED: JSDocNameReference */\u001b[39m any\u001b[0m\n\u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 11 |\u001b[39m  \u001b[33m*\u001b[39m\u001b[33m/\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m    |\u001b[39m    \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 12 |\u001b[39m declare type \u001b[33mFoo\u001b[39m \u001b[33m=\u001b[39m string\u001b[33m;\u001b[39m\u001b[0m' }

Removing the @see from the docstring fixes the issue.

flowgen --version
1.14.1

node --version
v10.16.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions