import { types as t , NodePath } from '@babel/core' ; export function declareVar ( kind , id , expr ? ) { const declarator = t . variableDeclarator ( t . identifier ( id ) , expr ) ; return t . variableDeclaration ( kind , [ declarator ] ) ; } export function importNamespace ( id , source ) { const specifier = t . importNamespaceSpecifier ( t . identifier ( id ) ) ; return t . importDeclaration ( [ specifier ] , t . stringLiteral ( source ) ) ; } export function variableExpr ( expr ) { const parts = expr . split ( '.' ) ; const id = t . identifier ( parts . shift ( ) ) ; return parts . reduce < t . Expression > ( ( acc , part ) => { return t . memberExpression ( acc , t . identifier ( part ) ) ; } , id ) as t . MemberExpression ; } export function callExpr ( expr , args ) { return t . callExpression ( variableExpr ( expr ) , args ) ; } export function assignVarExpr ( operator , name , expr ) { const assignmentExpr = t . assignmentExpression ( operator , t . identifier ( name ) , expr ) ; return t . expressionStatement ( assignmentExpr ) ; } export function generateUids ( node ) { return [ node . scope . generateUid ( 'kireiComponent' ) , node . scope . generateUid ( 'kireiOptions' ) ] ; }