Repository: mdx-js/mdx-analyzer
Pull request #375 (2023-12-18 14:43:40)

Fix return type of MDXContent in case of syntax error
### Initial checklist

*   [x] I read the support docs <!-- https://github.com/unifiedjs/.github/blob/main/support.md -->
*   [x] I read the contributing guide <!-- https://github.com/unifiedjs/.github/blob/main/contributing.md -->
*   [x] I agree to follow the code of conduct <!-- https://github.com/unifiedjs/.github/blob/main/code-of-conduct.md -->
*   [x] I searched issues and couldn’t find anything (or linked relevant results below) <!-- https://github.com/search?q=user%3Aunifiedjs&type=Issues -->
*   [x] If applicable, I’ve added docs and tests

### Description of changes

This means that if the component is used in another file, the return type of MDXContent is inferred as JSX.Element, not void.

<!--do not edit: pr-->


changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: be72b7cf0a91b7dee53017c4a403eb9eb1a87811

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 2 packages</summary>

  | Name                     | Type  |
| ------------------------ | ----- |
| @mdx-js/language-service | Patch |
| @mdx-js/language-server  | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/mdx-js/mdx-analyzer/new/handle-error-mdx-content-return-type?filename=.changeset/slow-carpets-heal.md&value=---%0A%22%40mdx-js%2Flanguage-service%22%3A%20patch%0A---%0A%0AFix%20return%20type%20of%20MDXContent%20in%20case%20of%20syntax%20error%0A)


github-actions[bot]: Hi! This is accepted and can go somewhere!

Team: please review this PR and use the `area/*` (to describe the scope of the change), `platform/*` (if this is related to a specific one), and `semver/*` and `type/*` labels to annotate this.

<!--xxx:beep-boop:yes-maintainers-->

Patch:
diff --git a/.changeset/pink-beans-move.md b/.changeset/pink-beans-move.md
new file mode 100644
index 0000000..4b1ab3d
--- /dev/null
+++ b/.changeset/pink-beans-move.md
@@ -0,0 +1,5 @@
+---
+"@mdx-js/language-service": patch
+---
+
+Fix the return type of `MDXContent` in case of a syntax error
diff --git a/packages/language-service/lib/virtual-file.js b/packages/language-service/lib/virtual-file.js
index 0c7e671..cebc589 100644
--- a/packages/language-service/lib/virtual-file.js
+++ b/packages/language-service/lib/virtual-file.js
@@ -46,7 +46,7 @@ const componentEnd = `
 /** @typedef {0 extends 1 & Props ? {} : Props} MDXContentProps */
 `
 
-const fallback = componentStart + componentEnd
+const fallback = componentStart + '<></>' + componentEnd
 
 /**
  * Visit an mdast tree with and enter and exit callback.


Test patch:
diff --git a/packages/language-service/test/language-module.js b/packages/language-service/test/language-module.js
index dd0653c..c7731a6 100644
--- a/packages/language-service/test/language-module.js
+++ b/packages/language-service/test/language-module.js
@@ -1713,7 +1713,7 @@ test('create virtual file w/ syntax error', () => {
           ' *   The [props](https://mdxjs.com/docs/using-mdx/#props) that have been passed to the MDX component.',
           ' */',
           'export default function MDXContent(props) {',
-          '  return ',
+          '  return <></>',
           '}',
           '',
           '// @ts-ignore',