16
16
* @typedef {import('../index.js').MdxJsxExpressionAttribute } MdxJsxExpressionAttribute
17
17
* @typedef {import('../index.js').MdxJsxFlowElement } MdxJsxFlowElement
18
18
* @typedef {import('../index.js').MdxJsxTextElement } MdxJsxTextElement
19
+ *
20
+ * @typedef {import('unist').Point } Point
19
21
*/
20
22
21
23
/**
@@ -136,6 +138,18 @@ export function mdxJsxFromMarkdown() {
136
138
this . buffer ( )
137
139
}
138
140
141
+ /**
142
+ * Copy a point-like value.
143
+ *
144
+ * @param {Point } d
145
+ * Point-like value.
146
+ * @returns {Point }
147
+ * unist point.
148
+ */
149
+ function point ( d ) {
150
+ return { line : d . line , column : d . column , offset : d . offset }
151
+ }
152
+
139
153
/**
140
154
* @this {CompileContext}
141
155
* @type {FromMarkdownHandle }
@@ -263,7 +277,16 @@ export function mdxJsxFromMarkdown() {
263
277
const tag = this . data . mdxJsxTag
264
278
assert ( tag , 'expected `mdxJsxTag`' )
265
279
enterMdxJsxTagAnyAttribute . call ( this , token )
266
- tag . attributes . push ( { type : 'mdxJsxAttribute' , name : '' , value : null } )
280
+ tag . attributes . push ( {
281
+ type : 'mdxJsxAttribute' ,
282
+ name : '' ,
283
+ value : null ,
284
+ position : {
285
+ start : point ( token . start ) ,
286
+ // @ts -expect-error: `end` will be patched later.
287
+ end : undefined
288
+ }
289
+ } )
267
290
}
268
291
269
292
/**
@@ -306,6 +329,8 @@ export function mdxJsxFromMarkdown() {
306
329
const node = tag . attributes [ tag . attributes . length - 1 ]
307
330
assert ( node . type === 'mdxJsxAttribute' )
308
331
node . name = this . sliceSerialize ( token )
332
+ assert ( node . position !== undefined )
333
+ node . position . end = point ( token . end )
309
334
}
310
335
311
336
/**
@@ -318,19 +343,21 @@ export function mdxJsxFromMarkdown() {
318
343
const node = tag . attributes [ tag . attributes . length - 1 ]
319
344
assert ( node . type === 'mdxJsxAttribute' )
320
345
node . name += ':' + this . sliceSerialize ( token )
346
+ assert ( node . position !== undefined )
347
+ node . position . end = point ( token . end )
321
348
}
322
349
323
350
/**
324
351
* @this {CompileContext}
325
352
* @type {FromMarkdownHandle }
326
353
*/
327
- function exitMdxJsxTagAttributeValueLiteral ( ) {
354
+ function exitMdxJsxTagAttributeValueLiteral ( token ) {
328
355
const tag = this . data . mdxJsxTag
329
356
assert ( tag , 'expected `mdxJsxTag`' )
330
- tag . attributes [ tag . attributes . length - 1 ] . value = parseEntities (
331
- this . resume ( ) ,
332
- { nonTerminated : false }
333
- )
357
+ const node = tag . attributes [ tag . attributes . length - 1 ]
358
+ node . value = parseEntities ( this . resume ( ) , { nonTerminated : false } )
359
+ assert ( node . position !== undefined )
360
+ node . position . end = point ( token . end )
334
361
}
335
362
336
363
/**
@@ -351,6 +378,8 @@ export function mdxJsxFromMarkdown() {
351
378
}
352
379
353
380
tail . value = node
381
+ assert ( tail . position !== undefined )
382
+ tail . position . end = point ( token . end )
354
383
}
355
384
356
385
/**
0 commit comments