1
- // To do next major: use `structuredClone` (or so?) to deep clone `properties`
2
- // and the like: the return value has to be a clone (not shallow copy) of the
3
- // passed tree.
4
-
5
1
/**
6
2
* @typedef {import('hast').Nodes } Nodes
7
3
* @typedef {import('hast').RootContent } RootContent
36
32
* Number of characters to truncate to (default: `140`).
37
33
*/
38
34
35
+ import structuredClone from '@ungap/structured-clone'
39
36
import { unicodePunctuation , unicodeWhitespace } from 'micromark-util-character'
40
37
41
38
/** @type {ReadonlyArray<RootContent> } */
@@ -109,7 +106,7 @@ export function truncate(tree, options) {
109
106
}
110
107
}
111
108
112
- return result
109
+ return structuredClone ( result )
113
110
114
111
/**
115
112
* Transform in `preorder`.
@@ -141,8 +138,7 @@ export function truncate(tree, options) {
141
138
const child = node . children [ index ]
142
139
143
140
if ( ! ignore . includes ( child ) ) {
144
- const result = preorder ( child )
145
- // @ts -expect-error: assume content matches.
141
+ const result = /** @type {RootContent } */ ( preorder ( child ) )
146
142
if ( result ) children . push ( result )
147
143
}
148
144
@@ -152,7 +148,7 @@ export function truncate(tree, options) {
152
148
}
153
149
}
154
150
155
- // @ts -expect-error: assume content matches.
151
+ // @ts -expect-error: content model matches.
156
152
replacement . children = children
157
153
}
158
154
0 commit comments