* Returns parser. * @template {string} T * @param {T} type type * @param {ParserOptions} parserOptions parser options * @returns {ParserByType[T]} parser
(type, parserOptions = EMPTY_PARSER_OPTIONS)
| 1419 | * @returns {ParserByType[T]} parser |
| 1420 | */ |
| 1421 | getParser(type, parserOptions = EMPTY_PARSER_OPTIONS) { |
| 1422 | let cache = this.parserCache.get(type); |
| 1423 | |
| 1424 | if (cache === undefined) { |
| 1425 | cache = new WeakMap(); |
| 1426 | this.parserCache.set(type, cache); |
| 1427 | } |
| 1428 | |
| 1429 | let parser = cache.get(parserOptions); |
| 1430 | |
| 1431 | if (parser === undefined) { |
| 1432 | parser = this.createParser(type, parserOptions); |
| 1433 | cache.set(parserOptions, parser); |
| 1434 | } |
| 1435 | |
| 1436 | return /** @type {ParserByType[T]} */ (parser); |
| 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * Creates a parser from the provided type. |
no test coverage detected