Skip to content

Commit 1e57b94

Browse files
committed
Patch @mdx-js/mdx to stop generating invalid JSX when
used with remark-shiki-twoslash. @calebeby, who provided the workaround, is the king. - mdx-js/mdx#2123 - mdx-js/mdx#2112
1 parent 791b08a commit 1e57b94

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@astrojs/tailwind": "^2.0.2",
1818
"@fontsource/brygada-1918": "^4.5.11",
1919
"@fontsource/inter": "^4.5.13",
20+
"@mdx-js/mdx": "^2.1.3",
2021
"astro": "^1.4.2",
2122
"astro-eslint-parser": "^0.6.2",
2223
"remark-shiki-twoslash": "^3.1.0",
@@ -43,6 +44,12 @@
4344
"rollup",
4445
"postcss"
4546
]
47+
},
48+
"overrides": {
49+
"@mdx-js/mdx": "2.1.3"
50+
},
51+
"patchedDependencies": {
52+
"@mdx-js/[email protected]": "patches/@[email protected]"
4653
}
4754
}
4855
}

patches/@[email protected]

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/lib/plugin/recma-jsx-rewrite.js b/lib/plugin/recma-jsx-rewrite.js
2+
index 1e82a1e41b18b16cb5d2f2a66b07e2d9544c55db..eb5286a273f095bedb693ec587917d6162164108 100644
3+
--- a/lib/plugin/recma-jsx-rewrite.js
4+
+++ b/lib/plugin/recma-jsx-rewrite.js
5+
@@ -387,11 +387,13 @@ export function recmaJsxRewrite(options = {}) {
6+
})
7+
}
8+
9+
- statements.push({
10+
- type: 'VariableDeclaration',
11+
- kind: 'const',
12+
- declarations
13+
- })
14+
+ if (declarations.length > 0) {
15+
+ statements.push({
16+
+ type: 'VariableDeclaration',
17+
+ kind: 'const',
18+
+ declarations
19+
+ })
20+
+ }
21+
}
22+
23+
/** @type {string} */

pnpm-lock.yaml

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

posts/features/shiki-twoslash.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
We're using [Shiki Twoslash](https://shikijs.github.io/twoslash/) to highlight
22
TypeScript and JavaScript code.
3-
`
3+
4+
```ts twoslash
5+
// @module: esnext
6+
// @filename: maths.ts
7+
export function absolute(num: number) {
8+
if (num < 0) return num * -1;
9+
return num;
10+
}
11+
// @filename: index.ts
12+
import { absolute } from "./maths";
13+
const value = absolute(-1);
14+
```

0 commit comments

Comments
 (0)