'use strict';

// MODULES //

var programSummary = require( '@stdlib/_tools/static-analysis/js/program-summary' );
var createState = require( './state.js' );
var update = require( './update.js' );


// MAIN //

/**
* Returns an accumulator function for incrementally computing a program summary.
*
* @returns {Function} accumulator function
*
* @example
* var acc = analyze();
*/
function analyze() {
	var engine;
	var state;

	// Initialize the accumulator state:
	state = createState();

	// De-structure:
	engine = state[ 0 ];
	state = state[ 1 ];

	return accumulator;

	/**
	* If provided a value, the accumulator function returns an updated summary. If not provided a value, the accumulator function returns the current summary.
	*
	* @param {(string|Buffer)} [input] - input program
	* @throws {TypeError} must provide either a string or Buffer
	* @returns {Object} summary
	*
	* @example
	* var summary = accumulator();
	* // returns {...}
	*
	* summary = accumulator( '"use strict";\n\nvar y = 5;\n' );
	* // returns {...}
	*
	* summary = accumulator( '"use strict";\n\nmodule.exports = "beep";\n' );
	* // returns {...}
	*
	* summary = accumulator();
	* // returns {...}
	*/
	function accumulator( input ) {
		var out;
		if ( arguments.length === 0 ) {
			return state;
		}
		out = programSummary( input );
		return update( state, engine, out );
	} // end FUNCTION accumulator()
} // end FUNCTION analyze()


// EXPORTS //

module.exports = analyze;


'use strict';

// MODULES //

var programSummary = require( '@stdlib/_tools/static-analysis/js/program-summary' );
var createState = require( './state.js' );
var update = require( './update.js' );


// MAIN //

/**
* Returns an accumulator function for incrementally computing a program summary.
*
* @returns {Function} accumulator function
*
* @example
* var acc = analyze();
*/
function analyze() {
	var engine;
	var state;

	// Initialize the accumulator state:
	state = createState();

	// De-structure:
	engine = state[ 0 ];
	state = state[ 1 ];

	return accumulator;

	/**
	* If provided a value, the accumulator function returns an updated summary. If not provided a value, the accumulator function returns the current summary.
	*
	* @private
	* @param {(string|Buffer)} [input] - input program
	* @throws {TypeError} must provide either a string or Buffer
	* @returns {Object} summary
	*
	* @example
	* var summary = accumulator();
	* // returns {...}
	*
	* summary = accumulator( '"use strict";\n\nvar y = 5;\n' );
	* // returns {...}
	*
	* summary = accumulator( '"use strict";\n\nmodule.exports = "beep";\n' );
	* // returns {...}
	*
	* summary = accumulator();
	* // returns {...}
	*/
	function accumulator( input ) {
		var out;
		if ( arguments.length === 0 ) {
			return state;
		}
		out = programSummary( input );
		return update( state, engine, out );
	} // end FUNCTION accumulator()
} // end FUNCTION analyze()


// EXPORTS //

module.exports = analyze;


Add missing private annotation