@@ -88,10 +88,11 @@ async function getMilestone(milestone: string | number, status = 'all') {
8888import { visit } from 'unist-util-visit' ;
8989
9090const remarkMilestonePlugin = function ( ) {
91+ // @ts -ignore
9192 const unified = this as any ;
9293 const tasks : [ number , any , number | null , any ] [ ] = [ ] ;
9394
94- return async function transformer ( tree : any , file : any ) {
95+ return async function transformer ( tree : any ) {
9596 visit ( tree , 'paragraph' , ( node , index , parent ) => {
9697 if (
9798 node . children &&
@@ -118,8 +119,8 @@ const remarkMilestonePlugin = function () {
118119 } ) ;
119120
120121 await Promise . all (
121- tasks . map ( async ( [ id , node , index , parent ] ) => {
122- const { issues, milestone } = await getMilestone ( id ) ;
122+ tasks . map ( async ( [ id , index , parent ] ) => {
123+ const { issues } = await getMilestone ( id ) ;
123124
124125 const content = [
125126 `<table>` ,
@@ -143,7 +144,14 @@ const remarkMilestonePlugin = function () {
143144 '</table>' ,
144145 ] . join ( '' ) ;
145146 const children = unified . parse ( content ) . children ;
146- parent . children . splice ( index , 1 , ...children ) ;
147+
148+ if ( ! parent ) return ;
149+
150+ // @ts -ignore
151+ if ( Array . isArray ( parent . children ) ) {
152+ // @ts -ignore
153+ parent . children . splice ( index , 1 , ...children ) ;
154+ }
147155 } ) ,
148156 ) ;
149157 } ;
0 commit comments