import { Undefinable } from '@easytype/core' ; import * as ts from 'typescript' ; import { PACKAGE_NAME , PACKAGE_NAMESPACE } from '../constants' ; import { ITranslator } from '../interfaces/translator.interface' ; export const ImportTranslator = ( node ) : Undefinable < ts . Node > => { if ( ts . isSourceFile ( node ) ) { createImportDeclaration ( node , PACKAGE_NAMESPACE , PACKAGE_NAME ) ; return ; } } ; const imports = new Map ( ) ; export function createImportDeclaration ( file , clause , module ) { if ( imports . get ( file ) ) { return null ; } imports . set ( file , true ) ; const exp = ts . createImportDeclaration ( undefined , undefined , ts . createImportClause ( undefined , ts . createNamespaceImport ( ts . createIdentifier ( clause ) ) ) , ts . createStringLiteral ( module ) ) ; file . statements = ts . createNodeArray ( [ exp , ... file . statements ] ) ; return exp ; }