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

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

Open
jrencz opened this issue Dec 28, 2022 · 1 comment

Comments

@jrencz
Copy link

jrencz commented Dec 28, 2022

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:

comment: node.comment?.replace(/^\s*-\s*/, "").trim(),

(1.1.6)

It's improved in master already:

const comment = typeof node.comment === "string" ? node.comment.replace(/^\s*-\s*/, "").trim() : "";

via 7db4cbe#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
Copy link
Author

jrencz commented Dec 28, 2022

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

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