server/polyfills/lib/aliases.js
/**
	 * Run a name resolver function over each polyfill identifier in an array,
	 * remove duplicates after the resolution and keep track of aliases and
	 * flags.
	 *
	 * @param {array}    polyfillIdentifiers          A list of polyfill identifiers to expand.
	 * @param {Function} polyfillNameResolverFunction The identifier name resolver function to use in
	 *                                                the resolution process.
	 *
	 * @return {array} An expanded list of polyfill identifiers
	 */
Run a name resolver function over each polyfill identifier in an array,
remove duplicates after the resolution and keep track of aliases and
flags.

@param {array}    polyfillIdentifiers          A list of polyfill identifiers to expand.
@param {Function} polyfillNameResolverFunction The identifier name resolver function to use in
the resolution process.

@return {array} An expanded list of polyfill identifiers
Run a name resolver function over each polyfill identifier in an array remove duplicates after the resolution and keep track of aliases and flags . @param { array } polyfillIdentifiers A list of polyfill identifiers to expand . @param { Function } polyfillNameResolverFunction The identifier name resolver function to use in the resolution process . @return { array } An expanded list of polyfill identifiers
function applyResolverToIdentifiers(polyfillIdentifiers, polyfillNameResolverFunction) {
		var expandedPolyfills = flatMap(polyfillIdentifiers, function(polyfillIdentifier) {
			var polyfillIdentifierNames = polyfillNameResolverFunction(polyfillIdentifier.name);
			if (!Array.isArray(polyfillIdentifierNames) || polyfillIdentifierNames.length === 0) {
				return polyfillIdentifier;
			}
			return polyfillIdentifierNames.map(function(name) {
				var aliasOf = polyfillIdentifier.aliasOf || (polyfillIdentifier.name === name ? [] : [polyfillIdentifier.name]);
				return {
					name: name,
					flags: polyfillIdentifier.flags,
					aliasOf: aliasOf
				};
			});
		});
		var polyfillSet = {};
		expandedPolyfills.forEach(function(polyfill) {
			if (!polyfillSet[polyfill.name]) {
				polyfillSet[polyfill.name] = polyfill;
			} else {
				var aliasOf = polyfillSet[polyfill.name].aliasOf;
				var flags = polyfillSet[polyfill.name].flags;
				if (aliasOf && polyfill.aliasOf) {
					polyfillSet[polyfill.name].aliasOf =  aliasOf.concat(polyfill.aliasOf);
				} else if (polyfill.aliasOf) {
					polyfillSet[polyfill.name].aliasOf =  polyfill.aliasOf;
				}
				if (flags && polyfill.flags) {
					polyfillSet[polyfill.name].flags   = flags.concat(polyfill.flags);
				} else if (polyfill.flags) {
					polyfillSet[polyfill.name].flags   = polyfill.flags;
				}
			}
		});
		var arrayOfPolyfills = Object.keys(polyfillSet).map(function(key) { return polyfillSet[key]; });
		return arrayOfPolyfills;
	}
function applyResolverToIdentifiers ( polyfillIdentifiers , polyfillNameResolverFunction ) { var expandedPolyfills = flatMap ( polyfillIdentifiers , function ( polyfillIdentifier ) { var polyfillIdentifierNames = polyfillNameResolverFunction ( polyfillIdentifier . name ) ; if ( ! Array . isArray ( polyfillIdentifierNames ) || polyfillIdentifierNames . length === 0 ) { return polyfillIdentifier ; } return polyfillIdentifierNames . map ( function ( name ) { var aliasOf = polyfillIdentifier . aliasOf || ( polyfillIdentifier . name === name ? [ ] : [ polyfillIdentifier . name ] ) ; return { name : name , flags : polyfillIdentifier . flags , aliasOf : aliasOf } ; } ) ; } ) ; var polyfillSet = { } ; expandedPolyfills . forEach ( function ( polyfill ) { if ( ! polyfillSet [ polyfill . name ] ) { polyfillSet [ polyfill . name ] = polyfill ; } else { var aliasOf = polyfillSet [ polyfill . name ] . aliasOf ; var flags = polyfillSet [ polyfill . name ] . flags ; if ( aliasOf && polyfill . aliasOf ) { polyfillSet [ polyfill . name ] . aliasOf = aliasOf . concat ( polyfill . aliasOf ) ; } else if ( polyfill . aliasOf ) { polyfillSet [ polyfill . name ] . aliasOf = polyfill . aliasOf ; } if ( flags && polyfill . flags ) { polyfillSet [ polyfill . name ] . flags = flags . concat ( polyfill . flags ) ; } else if ( polyfill . flags ) { polyfillSet [ polyfill . name ] . flags = polyfill . flags ; } } } ) ; var arrayOfPolyfills = Object . keys ( polyfillSet ) . map ( function ( key ) { return polyfillSet [ key ] ; } ) ; return arrayOfPolyfills ; }
Run a name resolver function over each polyfill identifier in an array,
 remove duplicates after the resolution and keep track of aliases and
 flags.
Run a name resolver function over each polyfill identifier in an array remove duplicates after the resolution and keep track of aliases and flags .
// If the resolver function returns null, undefined or anything else that // is not an array of size > 0, just return the polyfillIdentifier // to be handled by subsequent steps. // For each polyfill identifier name, apply the aliases and flags // and return an array of Polyfill Identifier Objects // It is possible that the name of an alias may also be the // name of a polyfill.  In this case avoid setting an alias of // itself // Remove duplicates: When removing duplicates, if one is found -> // concat the flags and the aliasOf fields. // Get the object's values (kind of like an imaginary Object.values function) as // an array