@@ -6,22 +6,38 @@ import { fromJref } from "./jref-util.js";
66 * @import { Plugin } from "unified"
77 * @import { VFile } from "vfile"
88 * @import { Options } from "vfile-message"
9- * @import { JrefDocumentNode } from "./jref-ast.js"
9+ * @import { JrefDocumentNode, JrefNode } from "./jref-ast.js"
10+ * @import { Reviver } from "./jref-util.js"
1011 */
1112
1213
13- /** @type Plugin<[], string, JrefDocumentNode> */
14- export function jrefParse ( ) {
14+ /**
15+ * @typedef {{
16+ * reviver?: Reviver<JrefNode | undefined>;
17+ * }} JrefParseOptions
18+ */
19+
20+ /** @type Plugin<[JrefParseOptions?], string, JrefDocumentNode> */
21+ export function jrefParse ( options ) {
1522 /** @type (document: string, file: VFile) => JrefDocumentNode */
1623 this . parser = function ( document , file ) {
1724 try {
1825 const uri = pathToFileURL ( file . path ) . toString ( ) ;
19- return {
26+
27+ /** @type JrefDocumentNode */
28+ const jrefDocumentNode = {
2029 type : "jref-document" ,
21- children : [ fromJref ( document , uri ) ] ,
30+ children : [ ] ,
2231 uri : uri ,
2332 fragmentKind : "json-pointer"
2433 } ;
34+
35+ const jrefNode = fromJref ( document , uri , options ?. reviver ) ;
36+ if ( jrefNode ) {
37+ jrefDocumentNode . children . push ( jrefNode ) ;
38+ }
39+
40+ return jrefDocumentNode ;
2541 } catch ( error ) {
2642 if ( error instanceof VFileMessage ) {
2743 return file . fail ( error . message , /** @type Options */ ( error ) ) ;
0 commit comments