Skip to content

Conversation

guyutongxue
Copy link

@guyutongxue guyutongxue commented Aug 31, 2025

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

This PR tries to map MDX Markdown node to correct JSX node. The feature request is at https://github.com/orgs/mdx-js/discussions/2639 . Before, the MDX node are translated to <></> fragment in language service, which is not typed well (see microsoft/TypeScript#62358) and this PR changes them to a slightly corrected translation, such as <p></p>.

Benefit on this, we can do type-checking on JSX expression 'hole' inside Markdown contents, such as (e.g. translate to React JSX):

image

Important This PR is not be able to merged now, since I cannot make tests pass -- it changes too many to the code generation and those asserts will failed quickly.

Also some open questions:

  • The parser returns something like listItem { paragraph { innerContent } } for a compact list item, which is not the correct behavior according to CommonMark spec (says no <p> inside a
  • if compact), so the original idea of typing <li> may not work;
  • There are no source mappings of plain texts and tag names, so errors from those content's typing will be silenced;
  • Documentation updates.

Copy link

changeset-bot bot commented Aug 31, 2025

⚠️ No Changeset found

Latest commit: f0dc9b8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Aug 31, 2025
Copy link
Contributor

github-actions bot commented Aug 31, 2025

Hi! It seems some of the things asked in the template are missing? Please edit your post to fill out everything.

  • Initial checklist (todo)
  • Description of changes

You won’t get any more notifications from me, but I’ll keep on updating this comment, and remove it when done!

If you need it, here’s the original template
<!--
  Please check the needed checkboxes ([ ] -> [x]).
  Leave the comments as they are: they do not show on GitHub.

  Please try to limit the scope,
  provide a general description of the changes,
  and remember it’s up to you to convince us to land it.

  We are excited about pull requests.
  Thank you!
-->

### Initial checklist

* [ ] I read the support docs <!-- https://mdxjs.com/community/support/ -->
* [ ] I read the contributing guide <!-- https://mdxjs.com/community/contribute/ -->
* [ ] I agree to follow the code of conduct <!-- https://github.com/mdx-js/.github/blob/main/code-of-conduct.md -->
* [ ] I searched issues and discussions and couldn’t find anything or linked relevant results below <!-- https://github.com/search?q=user%3Amdx-js&type=issues and https://github.com/orgs/mdx-js/discussions -->
* [ ] I made sure the docs are up to date
* [ ] I included tests (or that’s not needed)

### Description of changes

TODO

<!--do not edit: pr-->

Thanks,
— bb

@guyutongxue guyutongxue changed the title feat(language-service): Make MDX nodes typed with MDX.IntrinsicElements feat(language-service): Make MDX nodes typed with JSX.IntrinsicElements Sep 7, 2025
Copy link
Member

@remcohaszing remcohaszing left a comment

Choose a reason for hiding this comment

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

The code looks great, but the tests need to be adjusted, notably the tests in https://github.com/mdx-js/mdx-analyzer/blob/main/packages/language-service/test/language-plugin.js.

@@ -789,7 +831,7 @@ function getEmbeddedCodes(
}

default: {
jsx += jsxIndent + '</>'
jsx += jsxIndent + getJsxNodeNameForMdast(node).map((name) => `</${name}>`).join('')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
jsx += jsxIndent + getJsxNodeNameForMdast(node).map((name) => `</${name}>`).join('')
jsx += jsxIndent + getJsxNodeNameForMdast(node).toReversed().map((name) => `</${name}>`).join('')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👋 phase/new Post is being triaged automatically
Development

Successfully merging this pull request may close these issues.

2 participants