@@ -3,7 +3,6 @@ import { mock, it, describe } from 'node:test';
33
44import { SKIP } from 'unist-util-visit' ;
55
6- // Mock dependencies
76mock . module ( 'classNames' , {
87 defaultExport : ( ...args ) => args . filter ( Boolean ) . join ( ' ' ) ,
98} ) ;
@@ -17,20 +16,13 @@ mock.module('hast-util-to-string', {
1716mock . module ( 'unist-util-visit' , {
1817 namedExports : {
1918 visit : ( tree , nodeType , visitor ) => {
20- const traverseNode = ( node , index , parent ) => {
21- if ( node . type === nodeType ) {
22- const result = visitor ( node , index , parent ) ;
23- if ( result ?. [ 0 ] === SKIP ) return true ;
24- }
25-
26- if ( node . children ) {
27- for ( let i = 0 ; i < node . children . length ; i ++ ) {
28- if ( traverseNode ( node . children [ i ] , i , node ) ) return true ;
29- }
30- }
31- } ;
32-
33- traverseNode ( tree , null , null ) ;
19+ if ( tree . type === nodeType ) visitor ( tree , null , null ) ;
20+ tree . children ?. forEach ( ( child , i ) => {
21+ if ( child . type === nodeType ) visitor ( child , i , tree ) ;
22+ child . children ?. forEach ( ( subChild , j ) => {
23+ if ( subChild . type === nodeType ) visitor ( subChild , j , child ) ;
24+ } ) ;
25+ } ) ;
3426 } ,
3527 SKIP ,
3628 } ,
@@ -48,7 +40,6 @@ mock.module('../highlighter', {
4840 {
4941 type : 'element' ,
5042 tagName : 'code' ,
51- properties : { } ,
5243 children : [ { type : 'text' , value : `highlighted ${ code } ` } ] ,
5344 } ,
5445 ] ,
@@ -68,7 +59,7 @@ const {
6859describe ( 'rehypeShikiji module' , ( ) => {
6960 describe ( 'Utility functions' , ( ) => {
7061 it ( 'getMetaParameter extracts values from meta strings' , ( ) => {
71- const testCases = [
62+ const tests = [
7263 {
7364 meta : 'displayName="JavaScript"' ,
7465 param : 'displayName' ,
@@ -91,7 +82,7 @@ describe('rehypeShikiji module', () => {
9182 { meta : 'otherKey="value"' , param : 'key' , expected : undefined } ,
9283 ] ;
9384
94- testCases . forEach ( ( { meta, param, expected } ) => {
85+ tests . forEach ( ( { meta, param, expected } ) => {
9586 assert . equal ( getMetaParameter ( meta , param ) , expected ) ;
9687 } ) ;
9788 } ) ;
@@ -126,9 +117,7 @@ describe('rehypeShikiji module', () => {
126117 ] ;
127118
128119 assert . ok ( isCodeBlock ( validBlock ) ) ;
129- invalidCases . forEach ( testCase => {
130- assert . ok ( ! isCodeBlock ( testCase ) ) ;
131- } ) ;
120+ invalidCases . forEach ( testCase => assert . ok ( ! isCodeBlock ( testCase ) ) ) ;
132121 } ) ;
133122 } ) ;
134123
0 commit comments