File tree Expand file tree Collapse file tree 3 files changed +33
-25
lines changed Expand file tree Collapse file tree 3 files changed +33
-25
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const { validate } = require("schema-utils");
5
5
6
6
const {
7
7
throttleAll,
8
+ memoize,
8
9
terserMinify,
9
10
uglifyJsMinify,
10
11
swcMinify,
@@ -149,31 +150,6 @@ const { minify } = require("./minify");
149
150
* @typedef {BasePluginOptions & { minimizer: { implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> } } } InternalPluginOptions
150
151
*/
151
152
152
- /**
153
- * @template T
154
- * @param fn {(function(): any) | undefined}
155
- * @returns {function(): T }
156
- */
157
- const memoize = ( fn ) => {
158
- let cache = false ;
159
- /** @type {T } */
160
- let result ;
161
-
162
- return ( ) => {
163
- if ( cache ) {
164
- return result ;
165
- }
166
- result = /** @type {function(): any } */ ( fn ) ( ) ;
167
- cache = true ;
168
- // Allow to clean up memory for fn
169
- // and all dependent resources
170
- // eslint-disable-next-line no-undefined, no-param-reassign
171
- fn = undefined ;
172
-
173
- return result ;
174
- } ;
175
- } ;
176
-
177
153
const getTraceMapping = memoize ( ( ) =>
178
154
// eslint-disable-next-line global-require
179
155
require ( "@jridgewell/trace-mapping" )
Original file line number Diff line number Diff line change @@ -755,8 +755,34 @@ esbuildMinify.getMinimizerVersion = () => {
755
755
return packageJson && packageJson . version ;
756
756
} ;
757
757
758
+ /**
759
+ * @template T
760
+ * @param fn {(function(): any) | undefined}
761
+ * @returns {function(): T }
762
+ */
763
+ function memoize ( fn ) {
764
+ let cache = false ;
765
+ /** @type {T } */
766
+ let result ;
767
+
768
+ return ( ) => {
769
+ if ( cache ) {
770
+ return result ;
771
+ }
772
+ result = /** @type {function(): any } */ ( fn ) ( ) ;
773
+ cache = true ;
774
+ // Allow to clean up memory for fn
775
+ // and all dependent resources
776
+ // eslint-disable-next-line no-undefined, no-param-reassign
777
+ fn = undefined ;
778
+
779
+ return result ;
780
+ } ;
781
+ }
782
+
758
783
module . exports = {
759
784
throttleAll,
785
+ memoize,
760
786
terserMinify,
761
787
uglifyJsMinify,
762
788
swcMinify,
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ export type ExtractedComments = Array<string>;
27
27
* @returns {Promise<T[]> } A promise that fulfills to an array of the results
28
28
*/
29
29
export function throttleAll < T > ( limit : number , tasks : Task < T > [ ] ) : Promise < T [ ] > ;
30
+ /**
31
+ * @template T
32
+ * @param fn {(function(): any) | undefined}
33
+ * @returns {function(): T }
34
+ */
35
+ export function memoize < T > ( fn : ( ( ) => any ) | undefined ) : ( ) => T ;
30
36
/**
31
37
* @param {Input } input
32
38
* @param {SourceMapInput | undefined } sourceMap
You can’t perform that action at this time.
0 commit comments