Skip to content

Commit 6e80d01

Browse files
committed
fixup! feat(json): add legacy JSON generator
1 parent 35a89cf commit 6e80d01

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/queries.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import { u as createTree } from 'unist-builder';
4-
import { SKIP } from 'unist-util-visit';
4+
import { SKIP, visit } from 'unist-util-visit';
55

66
import { DOC_API_STABILITY_SECTION_REF_URL } from './constants.mjs';
77

@@ -81,8 +81,15 @@ const createQueries = () => {
8181
transformTypeToReferenceLink
8282
);
8383

84-
const newNode = remark.parse(replacedTypes);
84+
const {
85+
children: [newNode],
86+
} = remark.parse(replacedTypes);
8587
const index = parent.children.indexOf(node);
88+
const originalPosition = node.position;
89+
visit(newNode, node => {
90+
(node.position.start += originalPosition.start),
91+
(node.position.end += originalPosition.end);
92+
});
8693
parent.children.splice(index, 1, ...newNode.children);
8794

8895
return [SKIP];

src/test/metadata.test.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('createMetadata', () => {
7272
deprecated_in: undefined,
7373
heading,
7474
n_api_version: undefined,
75+
rawContent: '',
7576
removed_in: undefined,
7677
slug: 'test-heading',
7778
source_link: 'test.com',

src/test/queries.test.mjs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@ describe('createQueries', () => {
1515
});
1616

1717
// valid type
18-
it('should update type to reference correctly', () => {
18+
it.only('should update type to reference correctly', () => {
1919
const queries = createQueries();
20-
const node = { value: 'This is a {string} type.' };
21-
queries.updateTypeReference(node);
22-
strictEqual(node.type, 'html');
23-
strictEqual(
24-
node.value,
25-
'This is a [`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) type.'
20+
const node = {
21+
value: 'This is a {string} type.',
22+
position: { start: 0, end: 0 },
23+
};
24+
const parent = { children: [node] };
25+
queries.updateTypeReference(node, parent);
26+
deepStrictEqual(
27+
parent.children.map(c => c.value),
28+
[
29+
'This is a ',
30+
undefined, // link
31+
' type.',
32+
]
2633
);
2734
});
2835

2936
it('should update type to reference not correctly if no match', () => {
3037
const queries = createQueries();
31-
const node = { value: 'This is a {test} type.' };
32-
queries.updateTypeReference(node);
33-
strictEqual(node.type, 'html');
34-
strictEqual(node.value, 'This is a {test} type.');
38+
const node = {
39+
value: 'This is a {test} type.',
40+
position: { start: 0, end: 0 },
41+
};
42+
const parent = { children: [node] };
43+
queries.updateTypeReference(node, parent);
44+
strictEqual(parent.children[0].type, 'text');
45+
strictEqual(parent.children[0].value, 'This is a {test} type.');
3546
});
3647

3748
it('should add heading metadata correctly', () => {

0 commit comments

Comments
 (0)