Skip to content

Commit 8dee2ab

Browse files
committed
Fix support for functions in data
1 parent 0d78ebb commit 8dee2ab

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

lib/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@
346346
* be stored on the `result` field of {@link VFile `VFile`}.
347347
*/
348348

349-
import structuredClone from '@ungap/structured-clone'
350349
import {bail} from 'bail'
350+
import extend from 'extend'
351351
import {ok as assert} from 'devlop'
352352
import isPlainObj from 'is-plain-obj'
353353
import {trough} from 'trough'
@@ -507,7 +507,7 @@ export class Processor extends CallableInstance {
507507
destination.use(...attacher)
508508
}
509509

510-
destination.data(structuredClone(this.namespace))
510+
destination.data(extend(true, {}, this.namespace))
511511

512512
return destination
513513
}
@@ -1115,10 +1115,7 @@ export class Processor extends CallableInstance {
11151115
addList(result.plugins)
11161116

11171117
if (result.settings) {
1118-
namespace.settings = {
1119-
...namespace.settings,
1120-
...structuredClone(result.settings)
1121-
}
1118+
namespace.settings = extend(true, namespace.settings, result.settings)
11221119
}
11231120
}
11241121

@@ -1166,7 +1163,7 @@ export class Processor extends CallableInstance {
11661163
let [primary, ...rest] = parameters
11671164
const currentPrimary = attachers[entryIndex][1]
11681165
if (isPlainObj(currentPrimary) && isPlainObj(primary)) {
1169-
primary = structuredClone({...currentPrimary, ...primary})
1166+
primary = extend(true, currentPrimary, primary)
11701167
}
11711168

11721169
attachers[entryIndex] = [plugin, primary, ...rest]

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@
4646
],
4747
"dependencies": {
4848
"@types/unist": "^3.0.0",
49-
"@ungap/structured-clone": "^1.0.0",
5049
"bail": "^2.0.0",
5150
"devlop": "^1.0.0",
51+
"extend": "^3.0.0",
5252
"is-plain-obj": "^4.0.0",
5353
"trough": "^2.0.0",
5454
"vfile": "^6.0.0"
5555
},
5656
"devDependencies": {
57+
"@types/extend": "^3.0.0",
5758
"@types/hast": "^3.0.0",
5859
"@types/mdast": "^4.0.0",
5960
"@types/node": "^20.0.0",
60-
"@types/ungap__structured-clone": "^0.3.0",
6161
"c8": "^8.0.0",
6262
"prettier": "^3.0.0",
6363
"remark-cli": "^11.0.0",

test/data.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ test('`data`', async function (t) {
3939
baz: 'qux'
4040
})
4141
})
42+
43+
await t.test('should support functions in data', async function () {
44+
const fn = unified().data('fn', func)().data('fn')
45+
46+
assert(typeof fn === 'function')
47+
assert.equal(fn, func)
48+
49+
function func() {
50+
return 'alpha'
51+
}
52+
})
4253
})

test/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare module 'unified' {
33
baz?: 'qux' | undefined
44
foo?: 'bar' | undefined
55
x?: boolean | undefined
6+
fn?: Function | undefined
67
}
78

89
interface Settings {

0 commit comments

Comments
 (0)