@@ -36,7 +36,7 @@ Output:
36
36
*/
37
37
38
38
import type * as md from 'mdast'
39
- import type { } from 'mdast-util-mdx' ; // Type-only empty import to register MDX types into mdast
39
+ import type { } from 'mdast-util-mdx' // Type-only empty import to register MDX types into mdast
40
40
import assert from 'node:assert/strict'
41
41
import * as path from 'node:path'
42
42
import * as prettier from 'prettier'
@@ -54,8 +54,13 @@ const autoJSCodePlugin: Plugin<[], md.Root> = () => async (tree, file) => {
54
54
55
55
visitParents ( tree , 'code' , ( node , ancestors ) => {
56
56
if ( node . meta && META_FLAG_REGEX . test ( node . meta ) ) {
57
- if ( ! node . lang || ! SUPPORTED_LANGS . has ( node . lang ) ) {
58
- throw new Error ( `Unsupported language: ${ node . lang } ` )
57
+ if ( ! node . lang ) {
58
+ file . fail ( 'No language specified' , { place : node . position } )
59
+ }
60
+ if ( ! SUPPORTED_LANGS . has ( node . lang ) ) {
61
+ file . fail ( `Unsupported language: ${ node . lang } ` , {
62
+ place : node . position ,
63
+ } )
59
64
}
60
65
61
66
// We put these aside for processing later
@@ -67,7 +72,7 @@ const autoJSCodePlugin: Plugin<[], md.Root> = () => async (tree, file) => {
67
72
68
73
for ( const { node, ancestors } of nodesToProcess ) {
69
74
const parent = ancestors . at ( - 1 )
70
- assert ( parent ) // It must have a parent because the root node is a fully formed tree
75
+ assert ( parent ) // The node is never a `Root` node, so it will always have a parent
71
76
assert ( node . meta && node . lang ) // Already checked in the visitor
72
77
73
78
// Remove our flag from the meta so other plugins don't trip up
0 commit comments