Skip to content

Commit 380b71b

Browse files
committed
Add patch on state
This commit adds a helper utility to copy positional info from one node into another.
1 parent 35db2db commit 380b71b

31 files changed

+60
-195
lines changed

lib/handlers/a.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ export function a(state, node) {
2626
// @ts-expect-error: assume valid children.
2727
children: all(state, node)
2828
}
29-
30-
// To do: clean.
31-
if (node.position) {
32-
result.position = node.position
33-
}
34-
29+
state.patch(node, result)
3530
return result
3631
}

lib/handlers/blockquote.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ import {wrapChildren} from '../util/wrap-children.js'
1616
*/
1717
export function blockquote(state, node) {
1818
/** @type {Blockquote} */
19-
const result = {
20-
type: 'blockquote',
21-
children: wrapChildren(state, node)
22-
}
23-
24-
// To do: clean.
25-
if (node.position) {
26-
result.position = node.position
27-
}
28-
19+
const result = {type: 'blockquote', children: wrapChildren(state, node)}
20+
state.patch(node, result)
2921
return result
3022
}

lib/handlers/br.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
export function br(state, node) {
1717
/** @type {Break | Text} */
1818
const result = state.wrapText ? {type: 'break'} : {type: 'text', value: ' '}
19-
20-
// To do: clean.
21-
if (node.position) {
22-
result.position = node.position
23-
}
24-
19+
state.patch(node, result)
2520
return result
2621
}

lib/handlers/code.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ export function code(state, node) {
6161
meta: null,
6262
value: trimTrailingLines(wrapText(state, toText(node)))
6363
}
64-
65-
// To do: clean.
66-
if (node.position) {
67-
result.position = node.position
68-
}
69-
64+
state.patch(node, result)
7065
return result
7166
}

lib/handlers/comment.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export function comment(state, node) {
2020
type: 'html',
2121
value: '<!--' + wrapText(state, node.value) + '-->'
2222
}
23-
24-
// To do: clean.
25-
if (node.position) {
26-
result.position = node.position
27-
}
28-
23+
state.patch(node, result)
2924
return result
3025
}

lib/handlers/del.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export function del(state, node) {
2121
// @ts-expect-error: assume valid children.
2222
children: all(state, node)
2323
}
24-
25-
// To do: clean.
26-
if (node.position) {
27-
result.position = node.position
28-
}
29-
24+
state.patch(node, result)
3025
return result
3126
}

lib/handlers/dl.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ export function dl(state, node) {
103103
spread: listItemsSpread(content),
104104
children: content
105105
}
106-
107-
// To do: clean.
108-
if (node.position) {
109-
result.position = node.position
110-
}
111-
106+
state.patch(node, result)
112107
return result
113108
}
114109
}

lib/handlers/em.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export function em(state, node) {
2121
// @ts-expect-error: assume valid children.
2222
children: all(state, node)
2323
}
24-
25-
// To do: clean.
26-
if (node.position) {
27-
result.position = node.position
28-
}
29-
24+
state.patch(node, result)
3025
return result
3126
}

lib/handlers/heading.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export function heading(state, node) {
3333
// @ts-expect-error: assume valid children.
3434
children
3535
}
36-
37-
// To do: clean.
38-
if (node.position) {
39-
result.position = node.position
40-
}
41-
36+
state.patch(node, result)
4237
return result
4338
}

lib/handlers/hr.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
export function hr(state, node) {
1616
/** @type {ThematicBreak} */
1717
const result = {type: 'thematicBreak'}
18-
19-
// To do: clean.
20-
if (node.position) {
21-
result.position = node.position
22-
}
23-
18+
state.patch(node, result)
2419
return result
2520
}

0 commit comments

Comments
 (0)