@@ -203,6 +203,327 @@ test('markdown -> mdast', (t) => {
203203 'should support expressions'
204204 )
205205
206+ t . deepEqual (
207+ JSON . parse (
208+ JSON . stringify (
209+ fromMarkdown (
210+ `<Stuff>
211+ {{
212+ template: /* Comment */ '',
213+ }}
214+ </Stuff>` ,
215+ {
216+ extensions : [ mdxjs ( ) ] ,
217+ mdastExtensions : [ mdxFromMarkdown ( ) ]
218+ }
219+ )
220+ )
221+ ) ,
222+ {
223+ type : 'root' ,
224+ children : [
225+ {
226+ type : 'mdxJsxFlowElement' ,
227+ name : 'Stuff' ,
228+ attributes : [ ] ,
229+ children : [
230+ {
231+ type : 'mdxFlowExpression' ,
232+ value : "{\n template: /* Comment */ '',\n}" ,
233+ position : {
234+ start : { line : 2 , column : 3 , offset : 10 } ,
235+ end : { line : 4 , column : 5 , offset : 49 }
236+ } ,
237+ data : {
238+ estree : {
239+ type : 'Program' ,
240+ start : 11 ,
241+ end : 48 ,
242+ body : [
243+ {
244+ type : 'ExpressionStatement' ,
245+ expression : {
246+ type : 'ObjectExpression' ,
247+ start : 11 ,
248+ end : 48 ,
249+ properties : [
250+ {
251+ type : 'Property' ,
252+ start : 17 ,
253+ end : 43 ,
254+ method : false ,
255+ shorthand : false ,
256+ computed : false ,
257+ key : {
258+ type : 'Identifier' ,
259+ start : 17 ,
260+ end : 25 ,
261+ name : 'template' ,
262+ loc : {
263+ start : { line : 3 , column : 4 } ,
264+ end : { line : 3 , column : 12 }
265+ } ,
266+ range : [ 17 , 25 ]
267+ } ,
268+ value : {
269+ type : 'Literal' ,
270+ start : 41 ,
271+ end : 43 ,
272+ value : '' ,
273+ raw : "''" ,
274+ loc : {
275+ start : { line : 3 , column : 28 } ,
276+ end : { line : 3 , column : 30 }
277+ } ,
278+ range : [ 41 , 43 ]
279+ } ,
280+ kind : 'init' ,
281+ loc : {
282+ start : { line : 3 , column : 4 } ,
283+ end : { line : 3 , column : 30 }
284+ } ,
285+ range : [ 17 , 43 ]
286+ }
287+ ] ,
288+ loc : {
289+ start : { line : 2 , column : 3 } ,
290+ end : { line : 4 , column : 3 }
291+ } ,
292+ range : [ 11 , 48 ]
293+ } ,
294+ start : 11 ,
295+ end : 48 ,
296+ loc : {
297+ start : { line : 2 , column : 3 } ,
298+ end : { line : 4 , column : 3 }
299+ } ,
300+ range : [ 11 , 48 ]
301+ }
302+ ] ,
303+ sourceType : 'module' ,
304+ comments : [
305+ {
306+ type : 'Block' ,
307+ value : ' Comment ' ,
308+ start : 27 ,
309+ end : 40 ,
310+ loc : {
311+ start : { line : 3 , column : 14 } ,
312+ end : { line : 3 , column : 27 }
313+ } ,
314+ range : [ 27 , 40 ]
315+ }
316+ ] ,
317+ loc : {
318+ start : { line : 2 , column : 3 } ,
319+ end : { line : 4 , column : 3 }
320+ } ,
321+ range : [ 11 , 48 ]
322+ }
323+ }
324+ }
325+ ] ,
326+ position : {
327+ start : { line : 1 , column : 1 , offset : 0 } ,
328+ end : { line : 5 , column : 9 , offset : 58 }
329+ }
330+ }
331+ ] ,
332+ position : {
333+ start : { line : 1 , column : 1 , offset : 0 } ,
334+ end : { line : 5 , column : 9 , offset : 58 }
335+ }
336+ } ,
337+ 'should add proper positions on estree (1)'
338+ )
339+
340+ t . deepEqual (
341+ JSON . parse (
342+ JSON . stringify (
343+ fromMarkdown (
344+ `export let a = 'a'
345+
346+ export let b = 'b'` ,
347+ { extensions : [ mdxjs ( ) ] , mdastExtensions : [ mdxFromMarkdown ( ) ] }
348+ )
349+ )
350+ ) ,
351+ {
352+ type : 'root' ,
353+ children : [
354+ {
355+ type : 'mdxjsEsm' ,
356+ value : "export let a = 'a'" ,
357+ position : {
358+ start : { line : 1 , column : 1 , offset : 0 } ,
359+ end : { line : 1 , column : 19 , offset : 18 }
360+ } ,
361+ data : {
362+ estree : {
363+ type : 'Program' ,
364+ start : 0 ,
365+ end : 18 ,
366+ body : [
367+ {
368+ type : 'ExportNamedDeclaration' ,
369+ start : 0 ,
370+ end : 18 ,
371+ declaration : {
372+ type : 'VariableDeclaration' ,
373+ start : 7 ,
374+ end : 18 ,
375+ declarations : [
376+ {
377+ type : 'VariableDeclarator' ,
378+ start : 11 ,
379+ end : 18 ,
380+ id : {
381+ type : 'Identifier' ,
382+ start : 11 ,
383+ end : 12 ,
384+ name : 'a' ,
385+ loc : {
386+ start : { line : 1 , column : 11 } ,
387+ end : { line : 1 , column : 12 }
388+ } ,
389+ range : [ 11 , 12 ]
390+ } ,
391+ init : {
392+ type : 'Literal' ,
393+ start : 15 ,
394+ end : 18 ,
395+ value : 'a' ,
396+ raw : "'a'" ,
397+ loc : {
398+ start : { line : 1 , column : 15 } ,
399+ end : { line : 1 , column : 18 }
400+ } ,
401+ range : [ 15 , 18 ]
402+ } ,
403+ loc : {
404+ start : { line : 1 , column : 11 } ,
405+ end : { line : 1 , column : 18 }
406+ } ,
407+ range : [ 11 , 18 ]
408+ }
409+ ] ,
410+ kind : 'let' ,
411+ loc : {
412+ start : { line : 1 , column : 7 } ,
413+ end : { line : 1 , column : 18 }
414+ } ,
415+ range : [ 7 , 18 ]
416+ } ,
417+ specifiers : [ ] ,
418+ source : null ,
419+ loc : {
420+ start : { line : 1 , column : 0 } ,
421+ end : { line : 1 , column : 18 }
422+ } ,
423+ range : [ 0 , 18 ]
424+ }
425+ ] ,
426+ sourceType : 'module' ,
427+ comments : [ ] ,
428+ loc : {
429+ start : { line : 1 , column : 0 } ,
430+ end : { line : 1 , column : 18 }
431+ } ,
432+ range : [ 0 , 18 ]
433+ }
434+ }
435+ } ,
436+ {
437+ type : 'mdxjsEsm' ,
438+ value : "export let b = 'b'" ,
439+ position : {
440+ start : { line : 3 , column : 1 , offset : 20 } ,
441+ end : { line : 3 , column : 19 , offset : 38 }
442+ } ,
443+ data : {
444+ estree : {
445+ type : 'Program' ,
446+ start : 20 ,
447+ end : 38 ,
448+ body : [
449+ {
450+ type : 'ExportNamedDeclaration' ,
451+ start : 20 ,
452+ end : 38 ,
453+ declaration : {
454+ type : 'VariableDeclaration' ,
455+ start : 27 ,
456+ end : 38 ,
457+ declarations : [
458+ {
459+ type : 'VariableDeclarator' ,
460+ start : 31 ,
461+ end : 38 ,
462+ id : {
463+ type : 'Identifier' ,
464+ start : 31 ,
465+ end : 32 ,
466+ name : 'b' ,
467+ loc : {
468+ start : { line : 3 , column : 11 } ,
469+ end : { line : 3 , column : 12 }
470+ } ,
471+ range : [ 31 , 32 ]
472+ } ,
473+ init : {
474+ type : 'Literal' ,
475+ start : 35 ,
476+ end : 38 ,
477+ value : 'b' ,
478+ raw : "'b'" ,
479+ loc : {
480+ start : { line : 3 , column : 15 } ,
481+ end : { line : 3 , column : 18 }
482+ } ,
483+ range : [ 35 , 38 ]
484+ } ,
485+ loc : {
486+ start : { line : 3 , column : 11 } ,
487+ end : { line : 3 , column : 18 }
488+ } ,
489+ range : [ 31 , 38 ]
490+ }
491+ ] ,
492+ kind : 'let' ,
493+ loc : {
494+ start : { line : 3 , column : 7 } ,
495+ end : { line : 3 , column : 18 }
496+ } ,
497+ range : [ 27 , 38 ]
498+ } ,
499+ specifiers : [ ] ,
500+ source : null ,
501+ loc : {
502+ start : { line : 3 , column : 0 } ,
503+ end : { line : 3 , column : 18 }
504+ } ,
505+ range : [ 20 , 38 ]
506+ }
507+ ] ,
508+ sourceType : 'module' ,
509+ comments : [ ] ,
510+ loc : {
511+ start : { line : 3 , column : 0 } ,
512+ end : { line : 3 , column : 18 }
513+ } ,
514+ range : [ 20 , 38 ]
515+ }
516+ }
517+ }
518+ ] ,
519+ position : {
520+ start : { line : 1 , column : 1 , offset : 0 } ,
521+ end : { line : 3 , column : 19 , offset : 38 }
522+ }
523+ } ,
524+ 'should add proper positions on estree (2)'
525+ )
526+
206527 t . end ( )
207528} )
208529
0 commit comments