import * as t from "@babel/types" ; import { parseSync } from "@babel/core" ; import traverse , { Hub , NodePath } from "@babel/traverse" ; export function createNodePath < T extends t . Node > ( node ) { const path = new NodePath ( new Hub ( null , { } ) , null ) ; path . node = node ; return path ; } export function getNodePathForType < Type extends t . Node [ "type" ] , NodeType = Extract < t . Node , { type : Type ; } > , NodePathType = NodePath < NodeType > > ( node , type ) { const paths = [ ] ; traverse ( node , { [ type ] : ( path ) => { paths . push ( path ) ; } } ) ; return paths ; } export function parseJSX ( code ) { return parseSync ( code , { plugins : [ "@babel/plugin-syntax-jsx" ] } ) ; }