/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const MethodParser = require( './methodparser' );
const ReflectionKind = require( './reflectionkind' );

module.exports = class ConstructorParser extends MethodParser {
	/**
	 * @param {BaseReflection} item
	 * @returns {Boolean}
	 */
	canParse( item ) {
		return item.kind === ReflectionKind.Constructor;
	}

	/**
	 * @param {ConstructorReflection} item
	 * @param {String} parentName
	 * @returns {Array.<Object>}
	 */
	parse( item, parentName ) {
		// Absence of sources means that the actual class does not have a constructor.
		if ( !item.sources ) {
			return null;
		}

		const results = super.parse( item, parentName );

		for ( const item of results ) {
			// Constructors cannot return any value.
			delete item.returns;
		}

		return results;
	}
};
