@@ -20,6 +20,7 @@ import {
2020 GenericCFGBuilder ,
2121 type StatementHandlers ,
2222} from "./generic-cfg-builder.ts" ;
23+ import { treeSitterNoNullNodes } from "./hacks.ts" ;
2324import { buildSwitch , collectCases } from "./switch-utils.ts" ;
2425
2526export function createCFGBuilder ( options : BuilderOptions ) : CFGBuilder {
@@ -115,9 +116,9 @@ const caseTypes = new Set(["switch_case", "switch_default"]);
115116
116117function getCases ( switchSyntax : SyntaxNode ) : SyntaxNode [ ] {
117118 const switchBody = switchSyntax . namedChildren [ 1 ] as SyntaxNode ;
118- return switchBody . namedChildren
119- . filter ( ( x ) => x !== null )
120- . filter ( ( child ) => caseTypes . has ( child . type ) ) ;
119+ return treeSitterNoNullNodes ( switchBody . namedChildren ) . filter ( ( child ) =>
120+ caseTypes . has ( child . type ) ,
121+ ) ;
121122}
122123
123124function parseCase ( caseSyntax : SyntaxNode ) : {
@@ -126,9 +127,9 @@ function parseCase(caseSyntax: SyntaxNode): {
126127 hasFallthrough : boolean ;
127128} {
128129 const isDefault = caseSyntax . type === "switch_default" ;
129- const consequence = caseSyntax . namedChildren
130- . filter ( ( x ) => x !== null )
131- . slice ( isDefault ? 0 : 1 ) ;
130+ const consequence = treeSitterNoNullNodes ( caseSyntax . namedChildren ) . slice (
131+ isDefault ? 0 : 1 ,
132+ ) ;
132133 const hasFallthrough = true ;
133134 return { isDefault, consequence, hasFallthrough } ;
134135}
0 commit comments