UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

38 lines (36 loc) 974 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class KeyValueCache { constructor() { this.cacheItems = new Map(); } getEntries() { return this.cacheItems.entries(); } getOrCreate(key, createFunc) { let item = this.get(key); if (item == null) { item = createFunc(); this.set(key, item); } return item; } get(key) { return this.cacheItems.get(key) || undefined; } set(key, value) { this.cacheItems.set(key, value); } replaceKey(key, newKey) { if (!this.cacheItems.has(key)) throw new Error("Key not found."); const value = this.cacheItems.get(key); this.cacheItems.delete(key); this.cacheItems.set(newKey, value); } removeByKey(key) { this.cacheItems.delete(key); } } exports.KeyValueCache = KeyValueCache; //# sourceMappingURL=KeyValueCache.js.map