From 91640f9ca5f307a59337a73475ad4603e4e201ad Mon Sep 17 00:00:00 2001 From: jxom Date: Thu, 26 Sep 2024 15:02:01 +1000 Subject: [PATCH] feat: default twoslash to throw on errors --- .changeset/rich-eggs-look.md | 5 +++++ site/pages/docs/guides/twoslash.mdx | 1 + src/vite/plugins/mdx.ts | 1 + src/vite/plugins/shiki/twoslasher.ts | 1 + 4 files changed, 8 insertions(+) create mode 100644 .changeset/rich-eggs-look.md diff --git a/.changeset/rich-eggs-look.md b/.changeset/rich-eggs-look.md new file mode 100644 index 00000000..e27eac00 --- /dev/null +++ b/.changeset/rich-eggs-look.md @@ -0,0 +1,5 @@ +--- +"vocs": patch +--- + +Defauled Twoslash to throw on syntax errors, and added a `// @noErrors` tag to disable this behavior. diff --git a/site/pages/docs/guides/twoslash.mdx b/site/pages/docs/guides/twoslash.mdx index ceab5931..8eebc917 100644 --- a/site/pages/docs/guides/twoslash.mdx +++ b/site/pages/docs/guides/twoslash.mdx @@ -206,6 +206,7 @@ Taking this example: :::code-group ```ts [Output] twoslash +// @allowErrors const a = "123" a = 132 ``` diff --git a/src/vite/plugins/mdx.ts b/src/vite/plugins/mdx.ts index 6e11f4cd..ef36d66c 100644 --- a/src/vite/plugins/mdx.ts +++ b/src/vite/plugins/mdx.ts @@ -110,6 +110,7 @@ export const getRehypePlugins = ({ twoslashOptions: { ...twoslash, customTags: [ + 'allowErrors', ...(defaultTwoslashOptions.customTags ?? []), ...(twoslash.customTags ?? []), ], diff --git a/src/vite/plugins/shiki/twoslasher.ts b/src/vite/plugins/shiki/twoslasher.ts index 7f29181d..d17b0d0d 100644 --- a/src/vite/plugins/shiki/twoslasher.ts +++ b/src/vite/plugins/shiki/twoslasher.ts @@ -14,6 +14,7 @@ export function twoslasher( cache.twoslash.set(codeHash, twoslash) return twoslash } catch (e) { + if (!parameters[0].includes('@allowErrors')) throw e const error = e as Error const lines = parameters[0].split('\n') const line = lines.length - 1