import { parse } from '@typescript-eslint/typescript-estree' ; const { walk } = require ( 'estree-walker' ) ; param { string } FILETEXT returns { any } export function getRanges ( FILETEXT ) { const output = { } ; const ast = parse ( FILETEXT , { loc : true , } ) ; walk ( ast , { enter ( node , parent ) { if ( node . type === 'MemberExpression' && [ 'get' , 'GET' , 'post' , 'POST' , 'put' , 'PUT' , 'delete' , 'DELETE' ] . includes ( node . property . name ) ) { const startNum = node . property . loc . start . line ; const endNum = parent . loc . end . line ; output [ startNum ] = endNum ; } } , } ) ; return output ; } param { string } FILETEXT returns { ExpressId } export function getExpressIdentifier ( FILETEXT ) { const ast = parse ( FILETEXT , { loc : true , } ) ; walk ( ast , { enter ( node , parent ) { if ( node . type === 'CallExpression' && node . callee . type === 'Identifier' && node . callee . name === 'require' ) { node . arguments . forEach ( ( el ) => { if ( el . type === 'Literal' && el . value === 'express' ) { if ( parent . type === 'VariableDeclarator' && parent . id . type === 'Identifier' ) { const expressId = parent . id . name ; return expressId ; } } } ) ; } } , } ) ; }