lib/transform-media-list.js
function transformMedia(media, customMedias) {
	const transpiledMedias = [];

	for (const index in media.nodes) {
		const { value, nodes } = media.nodes[index];
		const key = value.replace(customPseudoRegExp, '$1');

		if (key in customMedias) {
			for (const replacementMedia of customMedias[key].nodes) {
				// use the first available modifier unless they cancel each other out
				const modifier = media.modifier !== replacementMedia.modifier
					? media.modifier || replacementMedia.modifier
				: '';
				const mediaClone = media.clone({
					modifier,
					// conditionally use the raws from the first available modifier
					raws: !modifier || media.modifier
						? { ...media.raws }
					: { ...replacementMedia.raws },
					type: media.type || replacementMedia.type,
				});

				// conditionally include more replacement raws when the type is present
				if (mediaClone.type === replacementMedia.type) {
					Object.assign(mediaClone.raws, {
						and: replacementMedia.raws.and,
						beforeAnd: replacementMedia.raws.beforeAnd,
						beforeExpression: replacementMedia.raws.beforeExpression
					});
				}

				mediaClone.nodes.splice(index, 1, ...replacementMedia.clone().nodes.map(node => {
					// use raws and spacing from the current usage
					if (media.nodes[index].raws.and) {
						node.raws = { ...media.nodes[index].raws };
					}

					node.spaces = { ...media.nodes[index].spaces };

					return node;
				}));

				// remove the currently transformed key to prevent recursion
				const nextCustomMedia = getCustomMediasWithoutKey(customMedias, key);
				const retranspiledMedias = transformMedia(mediaClone, nextCustomMedia);

				if (retranspiledMedias.length) {
					transpiledMedias.push(...retranspiledMedias);
				} else {
					transpiledMedias.push(mediaClone);
				}
			}

			return transpiledMedias;
		} else if (nodes && nodes.length) {
			transformMediaList(media.nodes[index], customMedias);
		}
	}

	return transpiledMedias;
}
function transformMedia(media, customMedias) {
	const transpiledMedias = [];

	for (const index in media.nodes) {
		const { value, nodes } = media.nodes[index];
		const key = value.replace(customPseudoRegExp, '$1');

		if (key in customMedias) {
			for (const replacementMedia of customMedias[key].nodes) {
				// use the first available modifier unless they cancel each other out
				const modifier = media.modifier !== replacementMedia.modifier
					? media.modifier || replacementMedia.modifier
				: '';
				const mediaClone = media.clone({
					modifier,
					// conditionally use the raws from the first available modifier
					raws: !modifier || media.modifier
						? { ...media.raws }
					: { ...replacementMedia.raws },
					type: media.type || replacementMedia.type,
				});

				// conditionally include more replacement raws when the type is present
				if (mediaClone.type === replacementMedia.type) {
					Object.assign(mediaClone.raws, {
						and: replacementMedia.raws.and,
						beforeAnd: replacementMedia.raws.beforeAnd,
						beforeExpression: replacementMedia.raws.beforeExpression
					});
				}

				mediaClone.nodes.splice(index, 1, ...replacementMedia.clone().nodes.map(node => {
					// use raws and spacing from the current usage
					if (media.nodes[index].raws.and) {
						node.raws = { ...media.nodes[index].raws };
					}

					node.spaces = { ...media.nodes[index].spaces };

					return node;
				}));

				// remove the currently transformed key to prevent recursion
				const nextCustomMedia = getCustomMediasWithoutKey(customMedias, key);
				const retranspiledMedias = transformMedia(mediaClone, nextCustomMedia);

				if (retranspiledMedias.length) {
					transpiledMedias.push(...retranspiledMedias);
				} else {
					transpiledMedias.push(mediaClone);
				}
			}

			return transpiledMedias;
		} else if (nodes && nodes.length) {
			transformMediaList(media.nodes[index], customMedias);
		}
	}

	return transpiledMedias;
}
function transformMedia ( media , customMedias ) { const transpiledMedias = [ ] ; for ( const index in media . nodes ) { const { value , nodes } = media . nodes [ index ] ; const key = value . replace ( customPseudoRegExp , '$1' ) ; if ( key in customMedias ) { for ( const replacementMedia of customMedias [ key ] . nodes ) { // use the first available modifier unless they cancel each other out const modifier = media . modifier !== replacementMedia . modifier ? media . modifier || replacementMedia . modifier : '' ; const mediaClone = media . clone ( { modifier , // conditionally use the raws from the first available modifier raws : ! modifier || media . modifier ? { ... media . raws } : { ... replacementMedia . raws } , type : media . type || replacementMedia . type , } ) ; // conditionally include more replacement raws when the type is present if ( mediaClone . type === replacementMedia . type ) { Object . assign ( mediaClone . raws , { and : replacementMedia . raws . and , beforeAnd : replacementMedia . raws . beforeAnd , beforeExpression : replacementMedia . raws . beforeExpression } ) ; } mediaClone . nodes . splice ( index , 1 , ... replacementMedia . clone ( ) . nodes . map ( node => { // use raws and spacing from the current usage if ( media . nodes [ index ] . raws . and ) { node . raws = { ... media . nodes [ index ] . raws } ; } node . spaces = { ... media . nodes [ index ] . spaces } ; return node ; } ) ) ; // remove the currently transformed key to prevent recursion const nextCustomMedia = getCustomMediasWithoutKey ( customMedias , key ) ; const retranspiledMedias = transformMedia ( mediaClone , nextCustomMedia ) ; if ( retranspiledMedias . length ) { transpiledMedias . push ( ... retranspiledMedias ) ; } else { transpiledMedias . push ( mediaClone ) ; } } return transpiledMedias ; } else if ( nodes && nodes . length ) { transformMediaList ( media . nodes [ index ] , customMedias ) ; } } return transpiledMedias ; }
return custom pseudo medias replaced with custom medias
return custom pseudo medias replaced with custom medias