sources.js (638B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 const cachedSources = new Map(); 6 7 export function setSource(source) { 8 cachedSources.set(source.id, source); 9 } 10 11 export function getSource(sourceId) { 12 const source = cachedSources.get(sourceId); 13 if (!source) { 14 throw new Error(`Parser: source ${sourceId} was not provided.`); 15 } 16 17 return source; 18 } 19 20 export function clearSources(sourceIds) { 21 for (const sourceId of sourceIds) { 22 cachedSources.delete(sourceId); 23 } 24 }