Skip to content

Commit

Permalink
feat: default twoslash to throw on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Sep 26, 2024
1 parent 6924717 commit 91640f9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-eggs-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vocs": patch
---

Defauled Twoslash to throw on syntax errors, and added a `// @noErrors` tag to disable this behavior.
1 change: 1 addition & 0 deletions site/pages/docs/guides/twoslash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Taking this example:
:::code-group

```ts [Output] twoslash
// @allowErrors
const a = "123"
a = 132
```
Expand Down
1 change: 1 addition & 0 deletions src/vite/plugins/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const getRehypePlugins = ({
twoslashOptions: {
...twoslash,
customTags: [
'allowErrors',
...(defaultTwoslashOptions.customTags ?? []),
...(twoslash.customTags ?? []),
],
Expand Down
1 change: 1 addition & 0 deletions src/vite/plugins/shiki/twoslasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91640f9

Please sign in to comment.