1
1
/**
2
2
* @typedef {import('mdast').Literal } Literal
3
3
* @typedef {import('mdast').Parent } Parent
4
+ * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
4
5
* @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
5
6
* @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
6
7
* @typedef {import('mdast-util-from-markdown').Token } Token
8
+ * @typedef {import('mdast-util-from-markdown').OnEnterError } OnEnterError
9
+ * @typedef {import('mdast-util-from-markdown').OnExitError } OnExitError
7
10
* @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
8
11
* @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
9
12
* @typedef {import('mdast-util-to-markdown').Map } ToMarkdownMap
10
- * @typedef {import('mdast-util-from-markdown').OnEnterError } OnEnterError
11
- * @typedef {import('mdast-util-from-markdown').OnExitError } OnExitError
12
13
* @typedef {import('estree-jsx').Program } Program
13
14
* @typedef {import('./complex-types.js').MdxJsxAttributeValueExpression } MdxJsxAttributeValueExpression
14
15
* @typedef {import('./complex-types.js').MdxJsxAttribute } MdxJsxAttribute
@@ -100,28 +101,43 @@ export function mdxJsxFromMarkdown() {
100
101
}
101
102
}
102
103
103
- /** @type {FromMarkdownHandle } */
104
+ /**
105
+ * @this {CompileContext}
106
+ * @type {FromMarkdownHandle }
107
+ */
104
108
function buffer ( ) {
105
109
this . buffer ( )
106
110
}
107
111
108
- /** @type {FromMarkdownHandle } */
112
+ /**
113
+ * @this {CompileContext}
114
+ * @type {FromMarkdownHandle }
115
+ */
109
116
function data ( token ) {
110
117
this . config . enter . data . call ( this , token )
111
118
this . config . exit . data . call ( this , token )
112
119
}
113
120
114
- /** @type {FromMarkdownHandle } */
121
+ /**
122
+ * @this {CompileContext}
123
+ * @type {FromMarkdownHandle }
124
+ */
115
125
function enterMdxJsxTag ( token ) {
116
126
/** @type {Tag } */
117
127
const tag = { name : null , attributes : [ ] , start : token . start , end : token . end }
128
+ // @ts -expect-error: to do: register.
118
129
if ( ! this . getData ( 'mdxJsxTagStack' ) ) this . setData ( 'mdxJsxTagStack' , [ ] )
130
+ // @ts -expect-error: to do: register.
119
131
this . setData ( 'mdxJsxTag' , tag )
120
132
this . buffer ( )
121
133
}
122
134
123
- /** @type {FromMarkdownHandle } */
135
+ /**
136
+ * @this {CompileContext}
137
+ * @type {FromMarkdownHandle }
138
+ */
124
139
function enterMdxJsxTagClosingMarker ( token ) {
140
+ // @ts -expect-error: to do: register.
125
141
const stack = /** @type {Tag[] } */ ( this . getData ( 'mdxJsxTagStack' ) )
126
142
127
143
if ( stack . length === 0 ) {
@@ -133,8 +149,12 @@ export function mdxJsxFromMarkdown() {
133
149
}
134
150
}
135
151
136
- /** @type {FromMarkdownHandle } */
152
+ /**
153
+ * @this {CompileContext}
154
+ * @type {FromMarkdownHandle }
155
+ */
137
156
function enterMdxJsxTagAnyAttribute ( token ) {
157
+ // @ts -expect-error: to do: register.
138
158
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
139
159
140
160
if ( tag . close ) {
@@ -146,8 +166,12 @@ export function mdxJsxFromMarkdown() {
146
166
}
147
167
}
148
168
149
- /** @type {FromMarkdownHandle } */
169
+ /**
170
+ * @this {CompileContext}
171
+ * @type {FromMarkdownHandle }
172
+ */
150
173
function enterMdxJsxTagSelfClosingMarker ( token ) {
174
+ // @ts -expect-error: to do: register.
151
175
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
152
176
153
177
if ( tag . close ) {
@@ -159,47 +183,75 @@ export function mdxJsxFromMarkdown() {
159
183
}
160
184
}
161
185
162
- /** @type {FromMarkdownHandle } */
186
+ /**
187
+ * @this {CompileContext}
188
+ * @type {FromMarkdownHandle }
189
+ */
163
190
function exitMdxJsxTagClosingMarker ( ) {
191
+ // @ts -expect-error: to do: register.
164
192
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
165
193
tag . close = true
166
194
}
167
195
168
- /** @type {FromMarkdownHandle } */
196
+ /**
197
+ * @this {CompileContext}
198
+ * @type {FromMarkdownHandle }
199
+ */
169
200
function exitMdxJsxTagNamePrimary ( token ) {
201
+ // @ts -expect-error: to do: register.
170
202
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
171
203
tag . name = this . sliceSerialize ( token )
172
204
}
173
205
174
- /** @type {FromMarkdownHandle } */
206
+ /**
207
+ * @this {CompileContext}
208
+ * @type {FromMarkdownHandle }
209
+ */
175
210
function exitMdxJsxTagNameMember ( token ) {
211
+ // @ts -expect-error: to do: register.
176
212
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
177
213
tag . name += '.' + this . sliceSerialize ( token )
178
214
}
179
215
180
- /** @type {FromMarkdownHandle } */
216
+ /**
217
+ * @this {CompileContext}
218
+ * @type {FromMarkdownHandle }
219
+ */
181
220
function exitMdxJsxTagNameLocal ( token ) {
221
+ // @ts -expect-error: to do: register.
182
222
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
183
223
tag . name += ':' + this . sliceSerialize ( token )
184
224
}
185
225
186
- /** @type {FromMarkdownHandle } */
226
+ /**
227
+ * @this {CompileContext}
228
+ * @type {FromMarkdownHandle }
229
+ */
187
230
function enterMdxJsxTagAttribute ( token ) {
231
+ // @ts -expect-error: to do: register.
188
232
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
189
233
enterMdxJsxTagAnyAttribute . call ( this , token )
190
234
tag . attributes . push ( { type : 'mdxJsxAttribute' , name : '' , value : null } )
191
235
}
192
236
193
- /** @type {FromMarkdownHandle } */
237
+ /**
238
+ * @this {CompileContext}
239
+ * @type {FromMarkdownHandle }
240
+ */
194
241
function enterMdxJsxTagExpressionAttribute ( token ) {
242
+ // @ts -expect-error: to do: register.
195
243
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
196
244
enterMdxJsxTagAnyAttribute . call ( this , token )
197
245
tag . attributes . push ( { type : 'mdxJsxExpressionAttribute' , value : '' } )
198
246
this . buffer ( )
199
247
}
200
248
201
- /** @type {FromMarkdownHandle } */
249
+ /**
250
+ * @this {CompileContext}
251
+ * @type {FromMarkdownHandle }
252
+ */
202
253
function exitMdxJsxTagExpressionAttribute ( token ) {
254
+ // @ts -expect-error: to do: register.
203
255
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
204
256
const tail = /** @type {MdxJsxExpressionAttribute } */ (
205
257
tag . attributes [ tag . attributes . length - 1 ]
@@ -215,35 +267,51 @@ export function mdxJsxFromMarkdown() {
215
267
}
216
268
}
217
269
218
- /** @type {FromMarkdownHandle } */
270
+ /**
271
+ * @this {CompileContext}
272
+ * @type {FromMarkdownHandle }
273
+ */
219
274
function exitMdxJsxTagAttributeNamePrimary ( token ) {
275
+ // @ts -expect-error: to do: register.
220
276
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
221
277
const node = /** @type {MdxJsxAttribute } */ (
222
278
tag . attributes [ tag . attributes . length - 1 ]
223
279
)
224
280
node . name = this . sliceSerialize ( token )
225
281
}
226
282
227
- /** @type {FromMarkdownHandle } */
283
+ /**
284
+ * @this {CompileContext}
285
+ * @type {FromMarkdownHandle }
286
+ */
228
287
function exitMdxJsxTagAttributeNameLocal ( token ) {
288
+ // @ts -expect-error: to do: register.
229
289
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
230
290
const node = /** @type {MdxJsxAttribute } */ (
231
291
tag . attributes [ tag . attributes . length - 1 ]
232
292
)
233
293
node . name += ':' + this . sliceSerialize ( token )
234
294
}
235
295
236
- /** @type {FromMarkdownHandle } */
296
+ /**
297
+ * @this {CompileContext}
298
+ * @type {FromMarkdownHandle }
299
+ */
237
300
function exitMdxJsxTagAttributeValueLiteral ( ) {
301
+ // @ts -expect-error: to do: register.
238
302
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
239
303
tag . attributes [ tag . attributes . length - 1 ] . value = parseEntities (
240
304
this . resume ( ) ,
241
305
{ nonTerminated : false }
242
306
)
243
307
}
244
308
245
- /** @type {FromMarkdownHandle } */
309
+ /**
310
+ * @this {CompileContext}
311
+ * @type {FromMarkdownHandle }
312
+ */
246
313
function exitMdxJsxTagAttributeValueExpression ( token ) {
314
+ // @ts -expect-error: to do: register.
247
315
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
248
316
const tail = /** @type {MdxJsxAttribute } */ (
249
317
tag . attributes [ tag . attributes . length - 1 ]
@@ -261,16 +329,25 @@ export function mdxJsxFromMarkdown() {
261
329
tail . value = node
262
330
}
263
331
264
- /** @type {FromMarkdownHandle } */
332
+ /**
333
+ * @this {CompileContext}
334
+ * @type {FromMarkdownHandle }
335
+ */
265
336
function exitMdxJsxTagSelfClosingMarker ( ) {
337
+ // @ts -expect-error: to do: register.
266
338
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
267
339
268
340
tag . selfClosing = true
269
341
}
270
342
271
- /** @type {FromMarkdownHandle } */
343
+ /**
344
+ * @this {CompileContext}
345
+ * @type {FromMarkdownHandle }
346
+ */
272
347
function exitMdxJsxTag ( token ) {
348
+ // @ts -expect-error: to do: register.
273
349
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
350
+ // @ts -expect-error: to do: register.
274
351
const stack = /** @type {Tag[] } */ ( this . getData ( 'mdxJsxTagStack' ) )
275
352
const tail = stack [ stack . length - 1 ]
276
353
@@ -316,8 +393,12 @@ export function mdxJsxFromMarkdown() {
316
393
}
317
394
}
318
395
319
- /** @type {OnEnterError } */
396
+ /**
397
+ * @this {CompileContext}
398
+ * @type {OnEnterError }
399
+ */
320
400
function onErrorRightIsTag ( closing , open ) {
401
+ // @ts -expect-error: to do: register.
321
402
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
322
403
const place = closing ? ' before the end of `' + closing . type + '`' : ''
323
404
const position = closing
@@ -336,8 +417,12 @@ export function mdxJsxFromMarkdown() {
336
417
)
337
418
}
338
419
339
- /** @type {OnExitError } */
420
+ /**
421
+ * @this {CompileContext}
422
+ * @type {OnExitError }
423
+ */
340
424
function onErrorLeftIsTag ( a , b ) {
425
+ // @ts -expect-error: to do: register.
341
426
const tag = /** @type {Tag } */ ( this . getData ( 'mdxJsxTag' ) )
342
427
throw new VFileMessage (
343
428
'Expected the closing tag `' +
@@ -414,6 +499,7 @@ export function mdxJsxToMarkdown(options = {}) {
414
499
const tracker = track ( safeOptions )
415
500
const selfClosing =
416
501
node . name && ( ! node . children || node . children . length === 0 )
502
+ // @ts -expect-error: to do: register.
417
503
const exit = context . enter ( node . type )
418
504
let index = - 1
419
505
/** @type {Array<string> } */
0 commit comments