lib/index.js
function compile(
  source,
  filename = '',
  includeModule = false,
  debugMode = false,
) {
  let res
  let resName
  let errors

  try {
    const [moduleName, bsCode, diagnosticErrors] = Retyped.compile(filename, source, debugMode)
    const fmtCode = format(bsCode)
    res = fmtCode
    resName = moduleName
    errors = diagnosticErrors
  } catch (e) {
    console.error(e)
    throw new Error(`${e[0][0]}`)
  }

  if (res.includes('SYNTAX ERROR>')) {
    throw new Error(res)
  }

  if (!includeModule) {
    return res
  } else {
    return {
      moduleName: resName,
      bsCode: res,
      diagnosticErrors: errors
    }
  }
}
function compile(
  source,
  filename = '',
  includeModule = false,
  debugMode = false,
) {
  let res
  let resName
  let errors

  try {
    const [moduleName, bsCode, diagnosticErrors] = Retyped.compile(filename, source, debugMode)
    const fmtCode = format(bsCode)
    res = fmtCode
    resName = moduleName
    errors = diagnosticErrors
  } catch (e) {
    console.error(e)
    throw new Error(`${e[0][0]}`)
  }

  if (res.includes('SYNTAX ERROR>')) {
    throw new Error(res)
  }

  if (!includeModule) {
    return res
  } else {
    return {
      moduleName: resName,
      bsCode: res,
      diagnosticErrors: errors
    }
  }
}
function compile ( source , filename = '' , includeModule = false , debugMode = false , ) { let res let resName let errors try { const [ moduleName , bsCode , diagnosticErrors ] = Retyped . compile ( filename , source , debugMode ) const fmtCode = format ( bsCode ) res = fmtCode resName = moduleName errors = diagnosticErrors } catch ( e ) { console . error ( e ) throw new Error ( ` ${ e [ 0 ] [ 0 ] } ` ) } if ( res . includes ( 'SYNTAX ERROR>' ) ) { throw new Error ( res ) } if ( ! includeModule ) { return res } else { return { moduleName : resName , bsCode : res , diagnosticErrors : errors } } }
Compiles a Flow libdef to a Reason interface, formatted and error handled

@param {string} source Flow libdef to compile
@param {string} [filename] Name of file being compiled for better error messages
@return {string} Reason interface
Compiles a Flow libdef to a Reason interface formatted and error handled