UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.setTSInstanceInCache = exports.getTSInstanceFromCache = void 0;
4// Some loaders (e.g. thread-loader) will set the _compiler property to undefined.
5// We can't use undefined as a WeakMap key as it will throw an error at runtime,
6// thus we keep a dummy "marker" object to use as key in those situations.
7const marker = {};
8// Each TypeScript instance is cached based on the webpack instance (key of the WeakMap)
9// and also the name that was generated or passed via the options (string key of the
10// internal Map)
11const cache = new WeakMap();
12function getTSInstanceFromCache(key, name) {
13 const compiler = key !== null && key !== void 0 ? key : marker;
14 let instances = cache.get(compiler);
15 if (!instances) {
16 instances = new Map();
17 cache.set(compiler, instances);
18 }
19 return instances.get(name);
20}
21exports.getTSInstanceFromCache = getTSInstanceFromCache;
22function setTSInstanceInCache(key, name, instance) {
23 var _a;
24 const compiler = key !== null && key !== void 0 ? key : marker;
25 const instances = (_a = cache.get(compiler)) !== null && _a !== void 0 ? _a : new Map();
26 instances.set(name, instance);
27 cache.set(compiler, instances);
28}
29exports.setTSInstanceInCache = setTSInstanceInCache;
30//# sourceMappingURL=instance-cache.js.map
\No newline at end of file