@@ -205,8 +205,8 @@ test('markdown -> mdast', function (t) {
205205 )
206206
207207 t . deepEqual (
208+ // Cheap clone to remove non-JSON values.
208209 JSON . parse (
209- // Cheap clone to remove non-JSON values.
210210 JSON . stringify (
211211 removePosition (
212212 fromMarkdown ( '{a}.' , {
@@ -255,6 +255,7 @@ test('markdown -> mdast', function (t) {
255255 }
256256 ] ,
257257 sourceType : 'module' ,
258+ comments : [ ] ,
258259 loc : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 2 } } ,
259260 range : [ 1 , 2 ]
260261 }
@@ -268,6 +269,130 @@ test('markdown -> mdast', function (t) {
268269 'should add a `data.estree` if `addResult` was used in the syntax plugin'
269270 )
270271
272+ t . deepEqual (
273+ // Cheap clone to remove non-JSON values.
274+ JSON . parse (
275+ JSON . stringify (
276+ removePosition (
277+ fromMarkdown ( 'A {/*b*/ c // d\n} e {/* f */}.' , {
278+ extensions : [ syntax ( { acorn : acorn , addResult : true } ) ] ,
279+ mdastExtensions : [ mdxExpression . fromMarkdown ]
280+ } ) ,
281+ true
282+ )
283+ )
284+ ) ,
285+ {
286+ type : 'root' ,
287+ children : [
288+ {
289+ type : 'paragraph' ,
290+ children : [
291+ { type : 'text' , value : 'A ' } ,
292+ {
293+ type : 'mdxTextExpression' ,
294+ value : '/*b*/ c // d\n' ,
295+ data : {
296+ estree : {
297+ type : 'Program' ,
298+ start : 3 ,
299+ end : 16 ,
300+ body : [
301+ {
302+ type : 'ExpressionStatement' ,
303+ expression : {
304+ type : 'Identifier' ,
305+ start : 9 ,
306+ end : 10 ,
307+ name : 'c' ,
308+ loc : {
309+ start : { line : 1 , column : 9 } ,
310+ end : { line : 1 , column : 10 }
311+ } ,
312+ range : [ 9 , 10 ]
313+ } ,
314+ start : 3 ,
315+ end : 16 ,
316+ loc : {
317+ start : { line : 1 , column : 3 } ,
318+ end : { line : 1 , column : 16 }
319+ } ,
320+ range : [ 3 , 16 ]
321+ }
322+ ] ,
323+ sourceType : 'module' ,
324+ comments : [
325+ {
326+ type : 'Block' ,
327+ value : 'b' ,
328+ start : 3 ,
329+ end : 8 ,
330+ loc : {
331+ start : { line : 1 , column : 3 } ,
332+ end : { line : 1 , column : 8 }
333+ } ,
334+ range : [ 3 , 8 ]
335+ } ,
336+ {
337+ type : 'Line' ,
338+ value : ' d' ,
339+ start : 11 ,
340+ end : 15 ,
341+ loc : {
342+ start : { line : 1 , column : 11 } ,
343+ end : { line : 1 , column : 15 }
344+ } ,
345+ range : [ 11 , 15 ]
346+ }
347+ ] ,
348+ loc : {
349+ start : { line : 1 , column : 3 } ,
350+ end : { line : 1 , column : 16 }
351+ } ,
352+ range : [ 3 , 16 ]
353+ }
354+ }
355+ } ,
356+ { type : 'text' , value : ' e ' } ,
357+ {
358+ type : 'mdxTextExpression' ,
359+ value : '/* f */' ,
360+ data : {
361+ estree : {
362+ type : 'Program' ,
363+ start : 21 ,
364+ end : 28 ,
365+ body : [ ] ,
366+ sourceType : 'module' ,
367+ comments : [
368+ {
369+ type : 'Block' ,
370+ value : ' f ' ,
371+ start : 21 ,
372+ end : 28 ,
373+ loc : {
374+ start : { line : 2 , column : 5 } ,
375+ end : { line : 2 , column : 12 }
376+ } ,
377+ range : [ 21 , 28 ]
378+ }
379+ ] ,
380+ loc : {
381+ start : { line : 2 , column : 5 } ,
382+ end : { line : 2 , column : 12 }
383+ } ,
384+ range : [ 21 , 28 ]
385+ }
386+ }
387+ } ,
388+ { type : 'text' , value : '.' }
389+ ]
390+ }
391+ ]
392+ } ,
393+ 'should support comments in expressions'
394+ )
395+
271396 t . end ( )
272397} )
273398
0 commit comments