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

Erroneous parsing of decorators in JSDoc code blocks #626

Open
nberlette opened this issue Sep 10, 2024 · 1 comment
Open

Erroneous parsing of decorators in JSDoc code blocks #626

nberlette opened this issue Sep 10, 2024 · 1 comment

Comments

@nberlette
Copy link

When using deno doc --json, example code blocks that contain decorators prove to be problematic for the parser. I'm not sure if this problem persists in --html or in the pretty-printed format in the CLI, but I would assume so since they all use the same parser under the hood AFAIK.

It stems from the @ prefix, which has also been a long running problem with the built-in JSDoc parser used by VSCode's intellisense, and a lot of other projects that incorporate JSDoc comment parsing in their logic. The parser gets confused and thinks the decorator is actually a malformed JSDoc tag, leading to unexpected (and usually terribly formatted) results.

Here's an example from the module doc comment in a JSR package of mine. Note the "unsupported" tags, particularly the last one. You can see it's parsing tags from inside an example code block.

{
  "version": 1,
  "nodes": [
    // ...
    {
      "name": "",
      "location": {
        "filename": "file:///workspaces/decorators/packages/types/mod.ts",
        "line": 1,
        "col": 0,
        "byteIndex": 0
      },
      "declarationKind": "export",
      "jsDoc": {
        "tags": [
          {
            "kind": "module"
          },
          {
            "kind": "unsupported",
            "value": "@log(\"class\") class Example {\n// ...\n"
          },
          {
            "kind": "unsupported",
            "value": "@log(\"method\") method() { return \"foo\" }\n"
          },
          {
            "kind": "unsupported",
            "value": "@log(\"getter\") get field() { return 42 }\n}\n```"
            // ---- the tell-tale sign its in an example code block  ^^^
          }
        ]
      },
      "kind": "moduleDoc"
    }
  ]
}
@nberlette nberlette changed the title [json] erroneous parsing of decorators in JSDoc code blocks Erroneous parsing of decorators in JSDoc code blocks Sep 10, 2024
@nberlette
Copy link
Author

Just checked the output of deno doc --html and it is indeed affected by this issue. However, since the HTML doesn't render unsupported tags, the problem manifests itself as broken example code blocks. Notice in the screenshot below that the example cuts off before the class body for Config - that's because the very first line in the example class has a decorator on it.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant