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-
51/**
62 * @typedef {import('hast').Nodes } Nodes
73 * @typedef {import('hast').RootContent } RootContent
3632 * Number of characters to truncate to (default: `140`).
3733 */
3834
35+ import structuredClone from '@ungap/structured-clone'
3936import { unicodePunctuation , unicodeWhitespace } from 'micromark-util-character'
4037
4138/** @type {ReadonlyArray<RootContent> } */
@@ -109,7 +106,7 @@ export function truncate(tree, options) {
109106 }
110107 }
111108
112- return result
109+ return structuredClone ( result )
113110
114111 /**
115112 * Transform in `preorder`.
@@ -141,8 +138,7 @@ export function truncate(tree, options) {
141138 const child = node . children [ index ]
142139
143140 if ( ! ignore . includes ( child ) ) {
144- const result = preorder ( child )
145- // @ts -expect-error: assume content matches.
141+ const result = /** @type {RootContent } */ ( preorder ( child ) )
146142 if ( result ) children . push ( result )
147143 }
148144
@@ -152,7 +148,7 @@ export function truncate(tree, options) {
152148 }
153149 }
154150
155- // @ts -expect-error: assume content matches.
151+ // @ts -expect-error: content model matches.
156152 replacement . children = children
157153 }
158154
0 commit comments