import { Expression , isParenthesizedExpression , Node , SyntaxKind } from 'typescript' ; export function skipParens ( node ) { while ( isParenthesizedExpression ( node ) ) { node = node . expression ; } return node ; } export function isDef < T > ( v ) { return v !== null && v !== undefined ; } export function assertDef < T > ( v ) { if ( isDef ( v ) ) { return v ; } throw new Error ( 'invalid assert def' ) ; } export function cast < T extends Node , U extends T > ( node , cb ) { if ( ! cb ( node ) ) { throw new Error ( 'invalid cast: ' + SyntaxKind [ node . kind ] ) ; } return node ; } export function lastOrUndefined < T > ( list ) { if ( ! list || ! list . length ) { return undefined ; } return list [ list . length - 1 ] ; } export function last < T > ( list ) { const result = lastOrUndefined ( list ) ; if ( ! result ) { throw new Error ( 'index out of range: last' ) ; } return result ; } export function isNumber ( v ) { return typeof v === 'number' ; } export function numericalEnumValues < T > ( e ) { return Object . values ( e ) . filter ( isNumber ) ; }