packages/tree-select/src/index.js
function insertDependentKey( map, key, currentIndex, arr ) {
	const weakMapKey = key || STATIC_FALSY_KEY;

	const existingMap = map.get( weakMapKey );
	if ( existingMap ) {
		return existingMap;
	}

	const newMap = currentIndex === arr.length - 1 ? new Map() : new WeakMap();
	map.set( weakMapKey, newMap );
	return newMap;
}
function insertDependentKey( map, key, currentIndex, arr ) {
	const weakMapKey = key || STATIC_FALSY_KEY;

	const existingMap = map.get( weakMapKey );
	if ( existingMap ) {
		return existingMap;
	}

	const newMap = currentIndex === arr.length - 1 ? new Map() : new WeakMap();
	map.set( weakMapKey, newMap );
	return newMap;
}
/*
First tries to get the value for the key.
If the key is not present, then inserts a new map and returns it

Note: Inserts WeakMaps except for the last map which will be a regular Map.
The last map is a regular one because the the key for the last map is the string results of args.join().