"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._pinTypeMatch = exports.pinTypeMatch = void 0;
const parser_1 = require("../spec/parser");
const _typeMatchCache = {};
const __isTypeMatch = (a, b, specs) => {
    const cacheKey = `${a.value}/${b.value}`;
    if (_typeMatchCache[cacheKey]) {
        return _typeMatchCache[cacheKey];
    }
    else {
        const typeMatch = (0, parser_1._isTypeMatch)(a, b, specs);
        _typeMatchCache[cacheKey] = typeMatch;
        return typeMatch;
    }
};
const pinTypeMatch = (aTypeStr, aKind, bTypeStr, bKind, specs) => {
    const aType = (0, parser_1.getTree)(aTypeStr);
    const bType = (0, parser_1.getTree)(bTypeStr);
    return (0, exports._pinTypeMatch)(aType, aKind, bType, bKind, specs);
};
exports.pinTypeMatch = pinTypeMatch;
const _pinTypeMatch = (aType, aKind, bType, bKind, specs) => {
    if (aKind === 'input' && bKind === 'input') {
        return (__isTypeMatch(aType, bType, specs) || __isTypeMatch(bType, aType, specs));
    }
    else if (aKind === 'input' && bKind === 'output') {
        return __isTypeMatch(bType, aType, specs);
    }
    else if (aKind === 'output' && bKind === 'input') {
        return __isTypeMatch(aType, bType, specs);
    }
    else {
        return true;
    }
};
exports._pinTypeMatch = _pinTypeMatch;
//# sourceMappingURL=parser.js.map