"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.walkAllowedTypes = exports.walkNodeSchema = void 0;
/**
 * Traverses all {@link TreeNodeSchema} schema reachable from `schema`, applying the visitor pattern.
 */
function walkNodeSchema(schema, visitor, visitedSet) {
    if (visitedSet.has(schema)) {
        return;
    }
    visitedSet.add(schema);
    walkAllowedTypes(schema.childTypes, visitor, visitedSet);
    // This visit is done at the end so the traversal order is most inner types first.
    // This was picked since when fixing errors,
    // working from the inner types out to the types that use them will probably go better than the reverse.
    // This does not however ensure all types referenced by a type are visited before it, since in recursive cases thats impossible.
    visitor.node?.(schema);
}
exports.walkNodeSchema = walkNodeSchema;
/**
 * Traverses all {@link TreeNodeSchema} schema reachable from `allowedTypes`, applying the visitor pattern.
 */
function walkAllowedTypes(allowedTypes, visitor, visitedSet = new Set()) {
    for (const childType of allowedTypes) {
        walkNodeSchema(childType, visitor, visitedSet);
    }
    visitor.allowedTypes?.(allowedTypes);
}
exports.walkAllowedTypes = walkAllowedTypes;
//# sourceMappingURL=walkSchema.js.map