webpack 5.54.0 → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/lib/Compilation.js +363 -149
- package/lib/Compiler.js +5 -5
- package/lib/Dependency.js +11 -0
- package/lib/FlagDependencyExportsPlugin.js +9 -27
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +90 -21
- package/lib/NormalModuleFactory.js +8 -43
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
- package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
- package/lib/dependencies/ContextDependency.js +8 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
- package/lib/dependencies/HarmonyImportDependency.js +4 -1
- package/lib/dependencies/ModuleDependency.js +8 -0
- package/lib/dependencies/NullDependency.js +8 -4
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
- package/lib/util/WeakTupleMap.js +95 -92
- package/package.json +1 -1
- package/types.d.ts +52 -18
- package/lib/MemCache.js +0 -45
package/lib/util/WeakTupleMap.js
CHANGED
@@ -7,87 +7,20 @@
|
|
7
7
|
|
8
8
|
const isWeakKey = thing => typeof thing === "object" && thing !== null;
|
9
9
|
|
10
|
-
class WeakTupleNode {
|
11
|
-
constructor() {
|
12
|
-
this.f = 0;
|
13
|
-
/** @type {any} */
|
14
|
-
this.v = undefined;
|
15
|
-
/** @type {Map<object, WeakTupleNode> | undefined} */
|
16
|
-
this.m = undefined;
|
17
|
-
/** @type {WeakMap<object, WeakTupleNode> | undefined} */
|
18
|
-
this.w = undefined;
|
19
|
-
}
|
20
|
-
|
21
|
-
getValue() {
|
22
|
-
return this.v;
|
23
|
-
}
|
24
|
-
|
25
|
-
hasValue() {
|
26
|
-
return (this.f & 1) === 1;
|
27
|
-
}
|
28
|
-
|
29
|
-
setValue(v) {
|
30
|
-
this.f |= 1;
|
31
|
-
this.v = v;
|
32
|
-
}
|
33
|
-
|
34
|
-
deleteValue() {
|
35
|
-
this.f &= 6;
|
36
|
-
this.v = undefined;
|
37
|
-
}
|
38
|
-
|
39
|
-
peek(thing) {
|
40
|
-
if (isWeakKey(thing)) {
|
41
|
-
if ((this.f & 4) !== 4) return undefined;
|
42
|
-
return this.w.get(thing);
|
43
|
-
} else {
|
44
|
-
if ((this.f & 2) !== 2) return undefined;
|
45
|
-
return this.m.get(thing);
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
get(thing) {
|
50
|
-
if (isWeakKey(thing)) {
|
51
|
-
if ((this.f & 4) !== 4) {
|
52
|
-
const newMap = new WeakMap();
|
53
|
-
this.f |= 4;
|
54
|
-
const newNode = new WeakTupleNode();
|
55
|
-
(this.w = newMap).set(thing, newNode);
|
56
|
-
return newNode;
|
57
|
-
}
|
58
|
-
const entry = this.w.get(thing);
|
59
|
-
if (entry !== undefined) {
|
60
|
-
return entry;
|
61
|
-
}
|
62
|
-
const newNode = new WeakTupleNode();
|
63
|
-
this.w.set(thing, newNode);
|
64
|
-
return newNode;
|
65
|
-
} else {
|
66
|
-
if ((this.f & 2) !== 2) {
|
67
|
-
const newMap = new Map();
|
68
|
-
this.f |= 2;
|
69
|
-
const newNode = new WeakTupleNode();
|
70
|
-
(this.m = newMap).set(thing, newNode);
|
71
|
-
return newNode;
|
72
|
-
}
|
73
|
-
const entry = this.m.get(thing);
|
74
|
-
if (entry !== undefined) {
|
75
|
-
return entry;
|
76
|
-
}
|
77
|
-
const newNode = new WeakTupleNode();
|
78
|
-
this.m.set(thing, newNode);
|
79
|
-
return newNode;
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
10
|
/**
|
85
11
|
* @template {any[]} T
|
86
12
|
* @template V
|
87
13
|
*/
|
88
14
|
class WeakTupleMap {
|
89
15
|
constructor() {
|
90
|
-
|
16
|
+
/** @private */
|
17
|
+
this.f = 0;
|
18
|
+
/** @private @type {any} */
|
19
|
+
this.v = undefined;
|
20
|
+
/** @private @type {Map<object, WeakTupleMap<T, V>> | undefined} */
|
21
|
+
this.m = undefined;
|
22
|
+
/** @private @type {WeakMap<object, WeakTupleMap<T, V>> | undefined} */
|
23
|
+
this.w = undefined;
|
91
24
|
}
|
92
25
|
|
93
26
|
/**
|
@@ -95,11 +28,12 @@ class WeakTupleMap {
|
|
95
28
|
* @returns {void}
|
96
29
|
*/
|
97
30
|
set(...args) {
|
98
|
-
|
31
|
+
/** @type {WeakTupleMap<T, V>} */
|
32
|
+
let node = this;
|
99
33
|
for (let i = 0; i < args.length - 1; i++) {
|
100
|
-
node = node.
|
34
|
+
node = node._get(args[i]);
|
101
35
|
}
|
102
|
-
node.
|
36
|
+
node._setValue(args[args.length - 1]);
|
103
37
|
}
|
104
38
|
|
105
39
|
/**
|
@@ -107,12 +41,13 @@ class WeakTupleMap {
|
|
107
41
|
* @returns {boolean} true, if the tuple is in the Set
|
108
42
|
*/
|
109
43
|
has(...args) {
|
110
|
-
|
44
|
+
/** @type {WeakTupleMap<T, V>} */
|
45
|
+
let node = this;
|
111
46
|
for (let i = 0; i < args.length; i++) {
|
112
|
-
node = node.
|
47
|
+
node = node._peek(args[i]);
|
113
48
|
if (node === undefined) return false;
|
114
49
|
}
|
115
|
-
return node.
|
50
|
+
return node._hasValue();
|
116
51
|
}
|
117
52
|
|
118
53
|
/**
|
@@ -120,12 +55,13 @@ class WeakTupleMap {
|
|
120
55
|
* @returns {V} the value
|
121
56
|
*/
|
122
57
|
get(...args) {
|
123
|
-
|
58
|
+
/** @type {WeakTupleMap<T, V>} */
|
59
|
+
let node = this;
|
124
60
|
for (let i = 0; i < args.length; i++) {
|
125
|
-
node = node.
|
61
|
+
node = node._peek(args[i]);
|
126
62
|
if (node === undefined) return undefined;
|
127
63
|
}
|
128
|
-
return node.
|
64
|
+
return node._getValue();
|
129
65
|
}
|
130
66
|
|
131
67
|
/**
|
@@ -133,14 +69,15 @@ class WeakTupleMap {
|
|
133
69
|
* @returns {V} the value
|
134
70
|
*/
|
135
71
|
provide(...args) {
|
136
|
-
|
72
|
+
/** @type {WeakTupleMap<T, V>} */
|
73
|
+
let node = this;
|
137
74
|
for (let i = 0; i < args.length - 1; i++) {
|
138
|
-
node = node.
|
75
|
+
node = node._get(args[i]);
|
139
76
|
}
|
140
|
-
if (node.
|
77
|
+
if (node._hasValue()) return node._getValue();
|
141
78
|
const fn = args[args.length - 1];
|
142
79
|
const newValue = fn(...args.slice(0, -1));
|
143
|
-
node.
|
80
|
+
node._setValue(newValue);
|
144
81
|
return newValue;
|
145
82
|
}
|
146
83
|
|
@@ -149,19 +86,85 @@ class WeakTupleMap {
|
|
149
86
|
* @returns {void}
|
150
87
|
*/
|
151
88
|
delete(...args) {
|
152
|
-
|
89
|
+
/** @type {WeakTupleMap<T, V>} */
|
90
|
+
let node = this;
|
153
91
|
for (let i = 0; i < args.length; i++) {
|
154
|
-
node = node.
|
92
|
+
node = node._peek(args[i]);
|
155
93
|
if (node === undefined) return;
|
156
94
|
}
|
157
|
-
node.
|
95
|
+
node._deleteValue();
|
158
96
|
}
|
159
97
|
|
160
98
|
/**
|
161
99
|
* @returns {void}
|
162
100
|
*/
|
163
101
|
clear() {
|
164
|
-
this.
|
102
|
+
this.f = 0;
|
103
|
+
this.v = undefined;
|
104
|
+
this.w = undefined;
|
105
|
+
this.m = undefined;
|
106
|
+
}
|
107
|
+
|
108
|
+
_getValue() {
|
109
|
+
return this.v;
|
110
|
+
}
|
111
|
+
|
112
|
+
_hasValue() {
|
113
|
+
return (this.f & 1) === 1;
|
114
|
+
}
|
115
|
+
|
116
|
+
_setValue(v) {
|
117
|
+
this.f |= 1;
|
118
|
+
this.v = v;
|
119
|
+
}
|
120
|
+
|
121
|
+
_deleteValue() {
|
122
|
+
this.f &= 6;
|
123
|
+
this.v = undefined;
|
124
|
+
}
|
125
|
+
|
126
|
+
_peek(thing) {
|
127
|
+
if (isWeakKey(thing)) {
|
128
|
+
if ((this.f & 4) !== 4) return undefined;
|
129
|
+
return this.w.get(thing);
|
130
|
+
} else {
|
131
|
+
if ((this.f & 2) !== 2) return undefined;
|
132
|
+
return this.m.get(thing);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
_get(thing) {
|
137
|
+
if (isWeakKey(thing)) {
|
138
|
+
if ((this.f & 4) !== 4) {
|
139
|
+
const newMap = new WeakMap();
|
140
|
+
this.f |= 4;
|
141
|
+
const newNode = new WeakTupleMap();
|
142
|
+
(this.w = newMap).set(thing, newNode);
|
143
|
+
return newNode;
|
144
|
+
}
|
145
|
+
const entry = this.w.get(thing);
|
146
|
+
if (entry !== undefined) {
|
147
|
+
return entry;
|
148
|
+
}
|
149
|
+
const newNode = new WeakTupleMap();
|
150
|
+
this.w.set(thing, newNode);
|
151
|
+
return newNode;
|
152
|
+
} else {
|
153
|
+
if ((this.f & 2) !== 2) {
|
154
|
+
const newMap = new Map();
|
155
|
+
this.f |= 2;
|
156
|
+
const newNode = new WeakTupleMap();
|
157
|
+
(this.m = newMap).set(thing, newNode);
|
158
|
+
return newNode;
|
159
|
+
}
|
160
|
+
const entry = this.m.get(thing);
|
161
|
+
if (entry !== undefined) {
|
162
|
+
return entry;
|
163
|
+
}
|
164
|
+
const newNode = new WeakTupleMap();
|
165
|
+
this.m.set(thing, newNode);
|
166
|
+
return newNode;
|
167
|
+
}
|
165
168
|
}
|
166
169
|
}
|
167
170
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.55.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
package/types.d.ts
CHANGED
@@ -1299,7 +1299,7 @@ declare class Compilation {
|
|
1299
1299
|
/**
|
1300
1300
|
* Creates an instance of Compilation.
|
1301
1301
|
*/
|
1302
|
-
constructor(compiler: Compiler);
|
1302
|
+
constructor(compiler: Compiler, params: CompilationParams);
|
1303
1303
|
hooks: Readonly<{
|
1304
1304
|
buildModule: SyncHook<[Module]>;
|
1305
1305
|
rebuildModule: SyncHook<[Module]>;
|
@@ -1455,18 +1455,22 @@ declare class Compilation {
|
|
1455
1455
|
outputOptions: OutputNormalized;
|
1456
1456
|
bail: boolean;
|
1457
1457
|
profile: boolean;
|
1458
|
+
params: CompilationParams;
|
1458
1459
|
mainTemplate: MainTemplate;
|
1459
1460
|
chunkTemplate: ChunkTemplate;
|
1460
1461
|
runtimeTemplate: RuntimeTemplate;
|
1461
1462
|
moduleTemplates: { javascript: ModuleTemplate };
|
1462
|
-
|
1463
|
-
moduleMemCaches?: WeakMap<Module, MemCache>;
|
1463
|
+
moduleMemCaches?: WeakMap<Module, WeakTupleMap<any, any>>;
|
1464
1464
|
moduleGraph: ModuleGraph;
|
1465
1465
|
chunkGraph: ChunkGraph;
|
1466
1466
|
codeGenerationResults: CodeGenerationResults;
|
1467
1467
|
processDependenciesQueue: AsyncQueue<Module, Module, Module>;
|
1468
1468
|
addModuleQueue: AsyncQueue<Module, string, Module>;
|
1469
|
-
factorizeQueue: AsyncQueue<
|
1469
|
+
factorizeQueue: AsyncQueue<
|
1470
|
+
FactorizeModuleOptions,
|
1471
|
+
string,
|
1472
|
+
Module | ModuleFactoryResult
|
1473
|
+
>;
|
1470
1474
|
buildQueue: AsyncQueue<Module, Module, Module>;
|
1471
1475
|
rebuildQueue: AsyncQueue<Module, Module, Module>;
|
1472
1476
|
|
@@ -1549,10 +1553,6 @@ declare class Compilation {
|
|
1549
1553
|
__0: HandleModuleCreationOptions,
|
1550
1554
|
callback: (err?: WebpackError, result?: Module) => void
|
1551
1555
|
): void;
|
1552
|
-
factorizeModule(
|
1553
|
-
options: FactorizeModuleOptions,
|
1554
|
-
callback: (err?: WebpackError, result?: Module) => void
|
1555
|
-
): void;
|
1556
1556
|
addModuleChain(
|
1557
1557
|
context: string,
|
1558
1558
|
dependency: Dependency,
|
@@ -1719,6 +1719,16 @@ declare class Compilation {
|
|
1719
1719
|
callback: (err?: WebpackError, result?: ExecuteModuleResult) => void
|
1720
1720
|
): void;
|
1721
1721
|
checkConstraints(): void;
|
1722
|
+
factorizeModule: {
|
1723
|
+
(
|
1724
|
+
options: FactorizeModuleOptions & { factoryResult?: false },
|
1725
|
+
callback: (err?: WebpackError, result?: Module) => void
|
1726
|
+
): void;
|
1727
|
+
(
|
1728
|
+
options: FactorizeModuleOptions & { factoryResult: true },
|
1729
|
+
callback: (err?: WebpackError, result?: ModuleFactoryResult) => void
|
1730
|
+
): void;
|
1731
|
+
};
|
1722
1732
|
|
1723
1733
|
/**
|
1724
1734
|
* Add additional assets to the compilation.
|
@@ -1897,7 +1907,10 @@ declare class Compiler {
|
|
1897
1907
|
context: string;
|
1898
1908
|
requestShortener: RequestShortener;
|
1899
1909
|
cache: Cache;
|
1900
|
-
moduleMemCaches?: WeakMap<
|
1910
|
+
moduleMemCaches?: WeakMap<
|
1911
|
+
Module,
|
1912
|
+
{ hash: string; memCache: WeakTupleMap<any, any> }
|
1913
|
+
>;
|
1901
1914
|
compilerPath: string;
|
1902
1915
|
running: boolean;
|
1903
1916
|
idle: boolean;
|
@@ -1921,7 +1934,7 @@ declare class Compiler {
|
|
1921
1934
|
plugins?: WebpackPluginInstance[]
|
1922
1935
|
): Compiler;
|
1923
1936
|
isChild(): boolean;
|
1924
|
-
createCompilation(): Compilation;
|
1937
|
+
createCompilation(params?: any): Compilation;
|
1925
1938
|
newCompilation(params: CompilationParams): Compilation;
|
1926
1939
|
createNormalModuleFactory(): NormalModuleFactory;
|
1927
1940
|
createContextModuleFactory(): ContextModuleFactory;
|
@@ -2241,6 +2254,7 @@ declare class ConstDependency extends NullDependency {
|
|
2241
2254
|
static Template: typeof ConstDependencyTemplate;
|
2242
2255
|
static NO_EXPORTS_REFERENCED: string[][];
|
2243
2256
|
static EXPORTS_OBJECT_REFERENCED: string[][];
|
2257
|
+
static TRANSITIVE: typeof TRANSITIVE;
|
2244
2258
|
}
|
2245
2259
|
declare class ConstDependencyTemplate extends NullDependencyTemplate {
|
2246
2260
|
constructor();
|
@@ -2554,6 +2568,7 @@ declare class Dependency {
|
|
2554
2568
|
readonly category: string;
|
2555
2569
|
loc: DependencyLocation;
|
2556
2570
|
getResourceIdentifier(): null | string;
|
2571
|
+
couldAffectReferencingModule(): boolean | typeof TRANSITIVE;
|
2557
2572
|
|
2558
2573
|
/**
|
2559
2574
|
* Returns the referenced module and export
|
@@ -2608,6 +2623,7 @@ declare class Dependency {
|
|
2608
2623
|
readonly disconnect: any;
|
2609
2624
|
static NO_EXPORTS_REFERENCED: string[][];
|
2610
2625
|
static EXPORTS_OBJECT_REFERENCED: string[][];
|
2626
|
+
static TRANSITIVE: typeof TRANSITIVE;
|
2611
2627
|
}
|
2612
2628
|
declare interface DependencyConstructor {
|
2613
2629
|
new (...args: any[]): Dependency;
|
@@ -3819,6 +3835,11 @@ declare interface FactorizeModuleOptions {
|
|
3819
3835
|
currentProfile: ModuleProfile;
|
3820
3836
|
factory: ModuleFactory;
|
3821
3837
|
dependencies: Dependency[];
|
3838
|
+
|
3839
|
+
/**
|
3840
|
+
* return full ModuleFactoryResult instead of only module
|
3841
|
+
*/
|
3842
|
+
factoryResult?: boolean;
|
3822
3843
|
originModule: null | Module;
|
3823
3844
|
contextInfo?: Partial<ModuleFactoryCreateDataContextInfo>;
|
3824
3845
|
context?: string;
|
@@ -6313,11 +6334,6 @@ declare interface MapOptions {
|
|
6313
6334
|
columns?: boolean;
|
6314
6335
|
module?: boolean;
|
6315
6336
|
}
|
6316
|
-
declare abstract class MemCache {
|
6317
|
-
get<T extends any[], V>(...args: T): undefined | V;
|
6318
|
-
set<T extends [any, ...any[]]>(...args: T): void;
|
6319
|
-
provide<T extends [any, ...((...args: any[]) => V)[]], V>(...args: T): V;
|
6320
|
-
}
|
6321
6337
|
|
6322
6338
|
/**
|
6323
6339
|
* Options object for in-memory caching.
|
@@ -6524,6 +6540,7 @@ declare class ModuleDependency extends Dependency {
|
|
6524
6540
|
static Template: typeof DependencyTemplate;
|
6525
6541
|
static NO_EXPORTS_REFERENCED: string[][];
|
6526
6542
|
static EXPORTS_OBJECT_REFERENCED: string[][];
|
6543
|
+
static TRANSITIVE: typeof TRANSITIVE;
|
6527
6544
|
}
|
6528
6545
|
declare abstract class ModuleFactory {
|
6529
6546
|
create(
|
@@ -6550,6 +6567,11 @@ declare interface ModuleFactoryResult {
|
|
6550
6567
|
fileDependencies?: Set<string>;
|
6551
6568
|
contextDependencies?: Set<string>;
|
6552
6569
|
missingDependencies?: Set<string>;
|
6570
|
+
|
6571
|
+
/**
|
6572
|
+
* allow to use the unsafe cache
|
6573
|
+
*/
|
6574
|
+
cacheable?: boolean;
|
6553
6575
|
}
|
6554
6576
|
declare class ModuleFederationPlugin {
|
6555
6577
|
constructor(options: ModuleFederationPluginOptions);
|
@@ -6707,12 +6729,16 @@ declare class ModuleGraph {
|
|
6707
6729
|
setAsync(module: Module): void;
|
6708
6730
|
getMeta(thing?: any): Object;
|
6709
6731
|
getMetaIfExisting(thing?: any): Object;
|
6710
|
-
freeze(): void;
|
6732
|
+
freeze(cacheStage?: string): void;
|
6711
6733
|
unfreeze(): void;
|
6712
6734
|
cached<T extends any[], V>(
|
6713
6735
|
fn: (moduleGraph: ModuleGraph, ...args: T) => V,
|
6714
6736
|
...args: T
|
6715
6737
|
): V;
|
6738
|
+
setModuleMemCaches(
|
6739
|
+
moduleMemCaches: WeakMap<Module, WeakTupleMap<any, any>>
|
6740
|
+
): void;
|
6741
|
+
dependencyCacheProvide(dependency: Dependency, ...args: any[]): any;
|
6716
6742
|
static getModuleGraphForModule(
|
6717
6743
|
module: Module,
|
6718
6744
|
deprecateMessage: string,
|
@@ -7366,8 +7392,6 @@ declare abstract class NormalModuleFactory extends ModuleFactory {
|
|
7366
7392
|
}>;
|
7367
7393
|
resolverFactory: ResolverFactory;
|
7368
7394
|
ruleSet: RuleSet;
|
7369
|
-
unsafeCache: boolean;
|
7370
|
-
cachePredicate: Function;
|
7371
7395
|
context: string;
|
7372
7396
|
fs: InputFileSystem;
|
7373
7397
|
parserCache: Map<string, WeakMap<Object, any>>;
|
@@ -7511,6 +7535,7 @@ declare class NullDependency extends Dependency {
|
|
7511
7535
|
static Template: typeof NullDependencyTemplate;
|
7512
7536
|
static NO_EXPORTS_REFERENCED: string[][];
|
7513
7537
|
static EXPORTS_OBJECT_REFERENCED: string[][];
|
7538
|
+
static TRANSITIVE: typeof TRANSITIVE;
|
7514
7539
|
}
|
7515
7540
|
declare class NullDependencyTemplate extends DependencyTemplate {
|
7516
7541
|
constructor();
|
@@ -11283,6 +11308,7 @@ declare interface SyntheticDependencyLocation {
|
|
11283
11308
|
index?: number;
|
11284
11309
|
}
|
11285
11310
|
declare const TOMBSTONE: unique symbol;
|
11311
|
+
declare const TRANSITIVE: unique symbol;
|
11286
11312
|
declare const TRANSITIVE_ONLY: unique symbol;
|
11287
11313
|
declare interface TagInfo {
|
11288
11314
|
tag: any;
|
@@ -11647,6 +11673,14 @@ declare abstract class Watching {
|
|
11647
11673
|
resume(): void;
|
11648
11674
|
close(callback: CallbackFunction<void>): void;
|
11649
11675
|
}
|
11676
|
+
declare abstract class WeakTupleMap<T extends any[], V> {
|
11677
|
+
set(...args: [T, ...V[]]): void;
|
11678
|
+
has(...args: T): boolean;
|
11679
|
+
get(...args: T): V;
|
11680
|
+
provide(...args: [T, ...(() => V)[]]): V;
|
11681
|
+
delete(...args: T): void;
|
11682
|
+
clear(): void;
|
11683
|
+
}
|
11650
11684
|
declare interface WebAssemblyRenderContext {
|
11651
11685
|
/**
|
11652
11686
|
* the chunk
|
package/lib/MemCache.js
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
|
6
|
-
"use strict";
|
7
|
-
|
8
|
-
const WeakTupleMap = require("./util/WeakTupleMap");
|
9
|
-
|
10
|
-
class MemCache {
|
11
|
-
constructor() {
|
12
|
-
this._cache = new WeakTupleMap();
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* @template {any[]} T
|
17
|
-
* @template V
|
18
|
-
* @param {T} args arguments
|
19
|
-
* @returns {V | undefined} cached value
|
20
|
-
*/
|
21
|
-
get(...args) {
|
22
|
-
return this._cache.get(...args);
|
23
|
-
}
|
24
|
-
|
25
|
-
/**
|
26
|
-
* @template {[...any[], any]} T
|
27
|
-
* @param {T} args arguments
|
28
|
-
* @returns {void}
|
29
|
-
*/
|
30
|
-
set(...args) {
|
31
|
-
this._cache.set(...args);
|
32
|
-
}
|
33
|
-
|
34
|
-
/**
|
35
|
-
* @template {[...any[], (...args: any[]) => V]} T
|
36
|
-
* @template V
|
37
|
-
* @param {T} args arguments
|
38
|
-
* @returns {V} computed value or cached
|
39
|
-
*/
|
40
|
-
provide(...args) {
|
41
|
-
return this._cache.provide(...args);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
module.exports = MemCache;
|