Skip to content

Conversation

domuk-k
Copy link
Contributor

@domuk-k domuk-k commented Dec 15, 2024

fixes #647

the typeExpression of a JSDocTypeTag is truncated due to comment syntax.

AS-IS TO-BE
image image

This PR addresses an issue where the typeExpression of a JSDocTypeTag was being truncated due to comment syntax (e.g., // ...) when converting JavaScript code with JSDoc to TypeScript.

It appears there is a bug in TypeScript’s parsing of the JSDoc @type tag, where it assigns the typeExpression property incorrectly (parseJSDocTypeExpression, reproduction).

In Svelte documentation, I determined that this issue can be handled without affecting other documents by using an alternative approach.

Changes

In the previous implementation, the typeExpression field in the AST node was used, but it could be incorrect when the JSDoc type tag had multiline types or contained comment expressions.

To resolve this:
• I modified the AST traversal logic to avoid using the typeExpression field directly.
• A helper function was added to correctly handle the type expression and ensure proper type information is generated.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.

- the typeExpression of a JSDocTypeTag is truncated due to comment syntax.
Copy link

vercel bot commented Dec 15, 2024

@domuk-k is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Dec 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
svelte-dev ✅ Ready (Inspect) Visit Preview Dec 16, 2024 10:14pm

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris Rich-Harris merged commit aa7e00e into sveltejs:main Dec 17, 2024
2 of 3 checks passed
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

Successfully merging this pull request may close these issues.

Typescript renders incorrectly in documentation example

2 participants