{"size": 806, "ext": "js", "max_stars_repo_path": "src/minimizer/pipes/collapseSmallFunctions.js", "max_stars_repo_name": "brianneisler/firemin", "max_stars_repo_stars_event_min_datetime": "2020-01-15T05:37:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-20T01:42:39.000Z", "max_issues_repo_path": "src/minimizer/pipes/collapseSmallFunctions.js", "max_issues_repo_name": "brianneisler/firemin", "max_issues_repo_issues_event_min_datetime": "2020-01-16T06:10:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-29T23:50:11.000Z", "max_forks_repo_path": "src/minimizer/pipes/collapseSmallFunctions.js", "max_forks_repo_name": "brianneisler/firemin", "max_forks_repo_forks_event_min_datetime": "2020-01-16T22:32:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-15T17:56:06.000Z"}
{"max_stars_count": 13, "max_issues_count": 38, "max_forks_count": 3, "avg_line_length": 28.7857142857, "max_line_length": 97, "alphanum_fraction": 0.6848635236}
import { Map } from 'immutable'
import { curry, reduce } from 'ramda'

import { buildScopes, collapseFunctionDeclaration, findFunctionsWithMaxNodeCount } from '../util'

const MAX_NODE_COUNT = 30

const collapseSmallFunctions = curry((context, ast) => {
  const smallExpressionFunctionIdMap = findFunctionsWithMaxNodeCount(ast, MAX_NODE_COUNT)
  return reduce(
    (accum, functionId) =>
      collapseFunctionDeclaration(
        // NOTE BRN: Need to rebuild the scopes after every function collapse
        // since the scopes will have changed as a result of the collapse
        {
          ...context,
          scopes: buildScopes(Map(), null, accum)
        },
        accum,
        functionId
      ),
    ast,
    smallExpressionFunctionIdMap.keys()
  )
})

export default collapseSmallFunctions
