Skip to content

Commit a79fa12

Browse files
committed
Add positional info to expression attributes
1 parent 4b0db74 commit a79fa12

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

lib/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,15 @@ export function mdxJsxFromMarkdown() {
282282
const tag = this.data.mdxJsxTag
283283
assert(tag, 'expected `mdxJsxTag`')
284284
enterMdxJsxTagAnyAttribute.call(this, token)
285-
tag.attributes.push({type: 'mdxJsxExpressionAttribute', value: ''})
285+
tag.attributes.push({
286+
type: 'mdxJsxExpressionAttribute',
287+
value: '',
288+
position: {
289+
start: point(token.start),
290+
// @ts-expect-error: `end` will be patched later.
291+
end: undefined
292+
}
293+
})
286294
this.buffer()
287295
}
288296

@@ -298,6 +306,8 @@ export function mdxJsxFromMarkdown() {
298306
const estree = token.estree
299307

300308
tail.value = this.resume()
309+
assert(tail.position !== undefined)
310+
tail.position.end = point(token.end)
301311

302312
if (estree) {
303313
tail.data = {estree}

test.js

+41-5
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,14 @@ test('mdxJsxFromMarkdown', async function (t) {
279279
type: 'mdxJsxTextElement',
280280
name: 'b',
281281
attributes: [
282-
{type: 'mdxJsxExpressionAttribute', value: '1 + 1'}
282+
{
283+
type: 'mdxJsxExpressionAttribute',
284+
value: '1 + 1',
285+
position: {
286+
start: {line: 1, column: 6, offset: 5},
287+
end: {line: 1, column: 13, offset: 12}
288+
}
289+
}
283290
],
284291
children: []
285292
},
@@ -364,7 +371,14 @@ test('mdxJsxFromMarkdown', async function (t) {
364371
type: 'mdxJsxTextElement',
365372
name: 'b',
366373
attributes: [
367-
{type: 'mdxJsxExpressionAttribute', value: '...c'}
374+
{
375+
type: 'mdxJsxExpressionAttribute',
376+
value: '...c',
377+
position: {
378+
start: {line: 1, column: 6, offset: 5},
379+
end: {line: 1, column: 12, offset: 11}
380+
}
381+
}
368382
],
369383
children: []
370384
},
@@ -395,7 +409,11 @@ test('mdxJsxFromMarkdown', async function (t) {
395409
attributes: [
396410
{
397411
type: 'mdxJsxExpressionAttribute',
398-
value: '...{b: 1, c: Infinity, d: false}'
412+
value: '...{b: 1, c: Infinity, d: false}',
413+
position: {
414+
start: {line: 1, column: 4, offset: 3},
415+
end: {line: 1, column: 38, offset: 37}
416+
}
399417
}
400418
],
401419
children: []
@@ -428,6 +446,10 @@ test('mdxJsxFromMarkdown', async function (t) {
428446
{
429447
type: 'mdxJsxExpressionAttribute',
430448
value: '...b',
449+
position: {
450+
start: {line: 1, column: 4, offset: 3},
451+
end: {line: 1, column: 10, offset: 9}
452+
},
431453
data: {
432454
estree: {
433455
type: 'Program',
@@ -1555,7 +1577,14 @@ test('mdxJsxFromMarkdown', async function (t) {
15551577
type: 'mdxJsxTextElement',
15561578
name: 'b',
15571579
attributes: [
1558-
{type: 'mdxJsxExpressionAttribute', value: 'c\nd'}
1580+
{
1581+
type: 'mdxJsxExpressionAttribute',
1582+
value: 'c\nd',
1583+
position: {
1584+
start: {line: 1, column: 8, offset: 7},
1585+
end: {line: 2, column: 5, offset: 14}
1586+
}
1587+
}
15591588
],
15601589
children: []
15611590
},
@@ -1593,7 +1622,14 @@ test('mdxJsxFromMarkdown', async function (t) {
15931622
type: 'mdxJsxTextElement',
15941623
name: 'b',
15951624
attributes: [
1596-
{type: 'mdxJsxExpressionAttribute', value: '...[1,\n2]'}
1625+
{
1626+
type: 'mdxJsxExpressionAttribute',
1627+
value: '...[1,\n2]',
1628+
position: {
1629+
start: {line: 1, column: 8, offset: 7},
1630+
end: {line: 2, column: 6, offset: 20}
1631+
}
1632+
}
15971633
],
15981634
children: []
15991635
},

0 commit comments

Comments
 (0)