File tree 4 files changed +30
-20
lines changed
4 files changed +30
-20
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,14 @@ export interface MdxjsEsmHast extends HastLiteral {
56
56
57
57
// Add nodes to mdast content.
58
58
declare module 'mdast' {
59
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
60
+ interface RootContentMap {
61
+ /**
62
+ * MDX ESM.
63
+ */
64
+ mdxjsEsm : MdxjsEsm
65
+ }
66
+
59
67
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
60
68
interface FrontmatterContentMap {
61
69
/**
Original file line number Diff line number Diff line change @@ -46,7 +46,10 @@ function enterMdxjsEsm(token) {
46
46
*/
47
47
function exitMdxjsEsm ( token ) {
48
48
const value = this . resume ( )
49
- const node = /** @type {MdxjsEsm } */ ( this . exit ( token ) )
49
+ const node = /** @type {MdxjsEsm } */ ( this . stack [ this . stack . length - 1 ] )
50
+
51
+ this . exit ( token )
52
+
50
53
const estree = token . estree
51
54
52
55
node . value = value
Original file line number Diff line number Diff line change 40
40
],
41
41
"dependencies" : {
42
42
"@types/estree-jsx" : " ^1.0.0" ,
43
- "@types/hast" : " ^2 .0.0" ,
44
- "@types/mdast" : " ^3 .0.0" ,
45
- "mdast-util-from-markdown" : " ^1 .0.0" ,
46
- "mdast-util-to-markdown" : " ^1 .0.0"
43
+ "@types/hast" : " ^3 .0.0" ,
44
+ "@types/mdast" : " ^4 .0.0" ,
45
+ "mdast-util-from-markdown" : " ^2 .0.0" ,
46
+ "mdast-util-to-markdown" : " ^2 .0.0"
47
47
},
48
48
"devDependencies" : {
49
49
"@types/node" : " ^20.0.0" ,
50
50
"acorn" : " ^8.0.0" ,
51
- "c8" : " ^7 .0.0" ,
52
- "micromark-extension-mdxjs-esm" : " ^1 .0.0" ,
51
+ "c8" : " ^8 .0.0" ,
52
+ "micromark-extension-mdxjs-esm" : " ^2 .0.0" ,
53
53
"prettier" : " ^2.0.0" ,
54
54
"remark-cli" : " ^11.0.0" ,
55
55
"remark-preset-wooorm" : " ^9.0.0" ,
56
56
"type-coverage" : " ^2.0.0" ,
57
57
"typescript" : " ^5.0.0" ,
58
- "unist-util-remove-position" : " ^4 .0.0" ,
58
+ "unist-util-remove-position" : " ^5 .0.0" ,
59
59
"xo" : " ^0.54.0"
60
60
},
61
61
"scripts" : {
Original file line number Diff line number Diff line change @@ -59,19 +59,18 @@ test('mdxjsEsmFromMarkdown', () => {
59
59
'should support ESM'
60
60
)
61
61
62
+ let tree = fromMarkdown ( 'import a from "b"\nexport var c = ""\n\nd' , {
63
+ extensions : [ mdxjsEsm ( { acorn, addResult : true } ) ] ,
64
+ mdastExtensions : [ mdxjsEsmFromMarkdown ]
65
+ } )
66
+
67
+ removePosition ( tree , { force : true } )
68
+
69
+ // Cheap clone to remove non-JSON values.
70
+ tree = JSON . parse ( JSON . stringify ( tree ) )
71
+
62
72
assert . deepEqual (
63
- // Cheap clone to remove non-JSON values.
64
- JSON . parse (
65
- JSON . stringify (
66
- removePosition (
67
- fromMarkdown ( 'import a from "b"\nexport var c = ""\n\nd' , {
68
- extensions : [ mdxjsEsm ( { acorn, addResult : true } ) ] ,
69
- mdastExtensions : [ mdxjsEsmFromMarkdown ]
70
- } ) ,
71
- true
72
- )
73
- )
74
- ) ,
73
+ tree ,
75
74
{
76
75
type : 'root' ,
77
76
children : [
You can’t perform that action at this time.
0 commit comments