"use strict";

var WeakMap = require('es6-weak-map');

/**
 * WeakMap for storing metadata: add metadata tree to make gulp.tree() happy.
 */
var _metadata = new WeakMap();

// Reference:
// https://github.com/gulpjs/undertaker/blob/master/lib/parallel.js
// https://github.com/gulpjs/undertaker/blob/master/lib/helpers/buildTree.js
function set(target, label, nodes) {
	var name, meta;

	meta = _metadata.get(target);
	if (!meta) {
		name = target.displayName || target.name || '<anonymous>';
		meta = {
			name: name,
			tree: {
				label: label,
				type: 'function',
				nodes: nodes
			}
		};
		_metadata.set(target, meta);
	}
	return meta.tree;
}

function get(target) {
	return _metadata.get(target);
};

module.exports = {
	get: get,
	set: set
};

@@ -486,16 +486,39 @@
 mous%3E';%0A
+%09%09nodes = nodes %7C%7C %5B%5D;%0A
 %09%09meta =
@@ -613,16 +613,65 @@
 %09%7D%0A%09%09%7D;%0A
+%09%09if (nodes.length) %7B%0A%09%09%09meta.branch = true;%0A%09%09%7D%0A
 %09%09_metad

add branch field to metadata