"use strict"; /** * @license * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ Object.defineProperty(exports, "__esModule", { value: true }); const predicates_1 = require("./predicates"); const util_1 = require("./util"); /** * Applies `mapfn` to `node` and the tree below `node`, yielding a flattened * list of results. */ function* treeMap(node, mapfn, getChildNodes) { for (const child of depthFirst(node, getChildNodes)) { yield* mapfn(child); } } exports.treeMap = treeMap; /** * Yields `node` and all of its children, recursively. * * Yields `node` first, then yields each descendent in depth first order. */ function* depthFirst(node, getChildNodes = util_1.defaultChildNodes) { yield node; const childNodes = getChildNodes(node); if (childNodes === undefined) { return; } for (const child of childNodes) { yield* depthFirst(child, getChildNodes); } } exports.depthFirst = depthFirst; /** * Yields node and all its descendents in reverse document order. * * Equivalent to: * yield* [...depthFirst(node)].reverse() */ function* depthFirstReversed(node, getChildNodes = util_1.defaultChildNodes) { const childNodes = getChildNodes(node); if (childNodes !== undefined) { for (const child of reversedView(childNodes)) { yield* depthFirstReversed(child, getChildNodes); } } yield node; } exports.depthFirstReversed = depthFirstReversed; /** * Like `depthFirst`, but descends into the bodies of `