runem / web-component-analyzer

CLI that analyzes web components and emits documentation
https://runem.github.io/web-component-analyzer
MIT License
507 stars 65 forks source link

`TypeError: replace is not a function` if `{@link something}` is used in any jsDoc tag #254

Open jrencz opened 1 year ago

jrencz commented 1 year ago

I experienced a TypeError once I put {@link} in either doclet, e.g.

/**
 * Some text
 *
 * @slot foo - does something {@link http://example.com}
 */

Error originates in this line:

https://github.com/runem/web-component-analyzer/blob/bf76b43221ff494f553cc46ed604bc5582e01356/src/analyze/util/js-doc-util.ts#L90 (1.1.6)

It's improved in master already: https://github.com/runem/web-component-analyzer/blob/88100440c904a543a57866dd8022f4525fecba22/src/analyze/util/js-doc-util.ts#L87

via https://github.com/runem/web-component-analyzer/commit/7db4cbec43445a19e67b65deae6e392f92b1477e#diff-ef413a90c49b28e770d0d5a76db8389b3e974f2c765ca8507dc8fe3466a65edbR87-R92 but it's not released as stable

In case of given example node.comment is not a string, it's: (positions may be misleading - the example is greatly simplified comparing to the code where I replaced single line):

<ref *1> [
  NodeObject {
    pos: 1233,
    end: 1254,
    flags: 8388608,
    modifierFlagsCache: 0,
    transformFlags: 0,
    parent: NodeObject {
      pos: 1227,
      end: 1284,
      flags: 8388608,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: [NodeObject],
      kind: 327,
      tagName: [IdentifierObject],
      comment: [Circular *1]
    },
    kind: 321,
    text: 'foo - does something '
  },
  <ref *2> NodeObject {
    pos: 1254,
    end: 1280,
    flags: 8388608,
    modifierFlagsCache: 0,
    transformFlags: 0,
    parent: NodeObject {
      pos: 1227,
      end: 1284,
      flags: 8388608,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: [NodeObject],
      kind: 327,
      tagName: [IdentifierObject],
      comment: [Circular *1]
    },
    kind: 324,
    name: IdentifierObject {
      pos: 1261,
      end: 1265,
      flags: 8388608,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: [Circular *2],
      kind: 79,
      originalKeywordKind: undefined,
      escapedText: 'http'
    },
    text: '://example.com'
  },
  pos: 1233,
  end: 1284,
  hasTrailingComma: false,
  transformFlags: 0
]

It seems to me like the comment is valid. What's more, IDE (WebStorm in my case) allows me to click the http://example.com

jrencz commented 1 year ago

Additionally: if error occurs then it still exits with code 0 (doesn't fail a build) so it took me a while to figure out there's a problem