import { predicateRace } from '../util'; import { Parser } from './parser'; export abstract class ChainParser
> implements Pick ();
/** A simple node cache to increase the performance at parse() when getting the correct parser */
protected cache = new WeakMap [0]) {
// Checks if the cache already has the node
if (this.cache.get(node)) {
return true;
}
// Asynchronously checks if any of the parsers supports the node
const parser = await predicateRace(this.parsers, this.parsers.size, 'supports', node);
// No parser was found
if (!parser) {
return false;
}
this.cache.set(node, parser);
return true;
}
}