@@ -10,7 +10,7 @@ const streamAndGetSourceAndMap = require("./helpers/streamAndGetSourceAndMap");
10
10
const streamChunksOfRawSource = require ( "./helpers/streamChunksOfRawSource" ) ;
11
11
const streamChunksOfSourceMap = require ( "./helpers/streamChunksOfSourceMap" ) ;
12
12
const {
13
- isDualStringBufferCachingEnabled
13
+ isDualStringBufferCachingEnabled,
14
14
} = require ( "./helpers/stringBufferUtils" ) ;
15
15
16
16
/** @typedef {import("./Source").HashLike } HashLike */
@@ -26,13 +26,13 @@ const {
26
26
27
27
/**
28
28
* @typedef {object } BufferedMap
29
- * @property {number } version
30
- * @property {string[] } sources
31
- * @property {string[] } names
32
- * @property {string= } sourceRoot
33
- * @property {(Buffer | "")[]= } sourcesContent
34
- * @property {Buffer= } mappings
35
- * @property {string } file
29
+ * @property {number } version version
30
+ * @property {string[] } sources sources
31
+ * @property {string[] } names name
32
+ * @property {string= } sourceRoot source root
33
+ * @property {(Buffer | "")[]= } sourcesContent sources content
34
+ * @property {Buffer= } mappings mappings
35
+ * @property {string } file file
36
36
*/
37
37
38
38
/**
@@ -41,14 +41,15 @@ const {
41
41
*/
42
42
const mapToBufferedMap = ( map ) => {
43
43
if ( typeof map !== "object" || ! map ) return map ;
44
- /** @type {BufferedMap } */
45
- const bufferedMap = Object . assign ( /** @type {BufferedMap } */ ( { } ) , map ) ;
44
+ const bufferedMap =
45
+ /** @type {BufferedMap } */
46
+ ( /** @type {unknown } */ ( { ...map } ) ) ;
46
47
if ( map . mappings ) {
47
- bufferedMap . mappings = Buffer . from ( map . mappings , "utf-8 " ) ;
48
+ bufferedMap . mappings = Buffer . from ( map . mappings , "utf8 " ) ;
48
49
}
49
50
if ( map . sourcesContent ) {
50
51
bufferedMap . sourcesContent = map . sourcesContent . map (
51
- ( str ) => str && Buffer . from ( str , "utf-8" )
52
+ ( str ) => str && Buffer . from ( str , "utf8" ) ,
52
53
) ;
53
54
}
54
55
return bufferedMap ;
@@ -60,14 +61,15 @@ const mapToBufferedMap = (map) => {
60
61
*/
61
62
const bufferedMapToMap = ( bufferedMap ) => {
62
63
if ( typeof bufferedMap !== "object" || ! bufferedMap ) return bufferedMap ;
63
- /** @type {RawSourceMap } */
64
- const map = Object . assign ( /** @type {RawSourceMap } */ ( { } ) , bufferedMap ) ;
64
+ const map =
65
+ /** @type {RawSourceMap } */
66
+ ( /** @type {unknown } */ ( { ...bufferedMap } ) ) ;
65
67
if ( bufferedMap . mappings ) {
66
- map . mappings = bufferedMap . mappings . toString ( "utf-8 " ) ;
68
+ map . mappings = bufferedMap . mappings . toString ( "utf8 " ) ;
67
69
}
68
70
if ( bufferedMap . sourcesContent ) {
69
71
map . sourcesContent = bufferedMap . sourcesContent . map (
70
- ( buffer ) => buffer && buffer . toString ( "utf-8" )
72
+ ( buffer ) => buffer && buffer . toString ( "utf8" ) ,
71
73
) ;
72
74
}
73
75
return map ;
@@ -78,15 +80,14 @@ const bufferedMapToMap = (bufferedMap) => {
78
80
79
81
/**
80
82
* @typedef {object } CachedData
81
- * @property {boolean= } source
82
- * @property {Buffer } buffer
83
- * @property {number= } size
84
- * @property {BufferedMaps } maps
85
- * @property {(string | Buffer)[]= } hash
83
+ * @property {boolean= } source source
84
+ * @property {Buffer } buffer buffer
85
+ * @property {number= } size size
86
+ * @property {BufferedMaps } maps maps
87
+ * @property {(string | Buffer)[]= } hash hash
86
88
*/
87
89
88
90
class CachedSource extends Source {
89
- // eslint-disable-next-line valid-jsdoc
90
91
/**
91
92
* @param {Source | (() => Source) } source source
92
93
* @param {CachedData= } cachedData cached data
@@ -117,15 +118,15 @@ class CachedSource extends Source {
117
118
/** @type {BufferedMaps } */
118
119
const bufferedMaps = new Map ( ) ;
119
120
for ( const pair of this . _cachedMaps ) {
120
- let cacheEntry = pair [ 1 ] ;
121
+ const [ , cacheEntry ] = pair ;
121
122
if ( cacheEntry . bufferedMap === undefined ) {
122
123
cacheEntry . bufferedMap = mapToBufferedMap (
123
- this . _getMapFromCacheEntry ( cacheEntry )
124
+ this . _getMapFromCacheEntry ( cacheEntry ) ,
124
125
) ;
125
126
}
126
127
bufferedMaps . set ( pair [ 0 ] , {
127
128
map : undefined ,
128
- bufferedMap : cacheEntry . bufferedMap
129
+ bufferedMap : cacheEntry . bufferedMap ,
129
130
} ) ;
130
131
}
131
132
return {
@@ -140,13 +141,13 @@ class CachedSource extends Source {
140
141
this . _cachedSourceType !== undefined
141
142
? this . _cachedSourceType
142
143
: typeof this . _cachedSource === "string"
143
- ? true
144
- : Buffer . isBuffer ( this . _cachedSource )
145
- ? false
146
- : undefined ,
144
+ ? true
145
+ : Buffer . isBuffer ( this . _cachedSource )
146
+ ? false
147
+ : undefined ,
147
148
size : this . _cachedSize ,
148
149
maps : bufferedMaps ,
149
- hash : this . _cachedHashUpdate
150
+ hash : this . _cachedHashUpdate ,
150
151
} ;
151
152
}
152
153
@@ -193,7 +194,7 @@ class CachedSource extends Source {
193
194
if ( this . _cachedSource !== undefined ) return this . _cachedSource ;
194
195
if ( this . _cachedBuffer && this . _cachedSourceType !== undefined ) {
195
196
const value = this . _cachedSourceType
196
- ? this . _cachedBuffer . toString ( "utf-8 " )
197
+ ? this . _cachedBuffer . toString ( "utf8 " )
197
198
: this . _cachedBuffer ;
198
199
if ( isDualStringBufferCachingEnabled ( ) ) {
199
200
this . _cachedSource = /** @type {string } */ ( value ) ;
@@ -210,7 +211,7 @@ class CachedSource extends Source {
210
211
if ( this . _cachedSource !== undefined ) {
211
212
const value = Buffer . isBuffer ( this . _cachedSource )
212
213
? this . _cachedSource
213
- : Buffer . from ( this . _cachedSource , "utf-8 " ) ;
214
+ : Buffer . from ( this . _cachedSource , "utf8 " ) ;
214
215
if ( isDualStringBufferCachingEnabled ( ) ) {
215
216
this . _cachedBuffer = value ;
216
217
}
@@ -223,7 +224,7 @@ class CachedSource extends Source {
223
224
if ( Buffer . isBuffer ( bufferOrString ) ) {
224
225
return ( this . _cachedBuffer = bufferOrString ) ;
225
226
}
226
- const value = Buffer . from ( bufferOrString , "utf-8 " ) ;
227
+ const value = Buffer . from ( bufferOrString , "utf8 " ) ;
227
228
if ( isDualStringBufferCachingEnabled ( ) ) {
228
229
this . _cachedBuffer = value ;
229
230
}
@@ -275,7 +276,7 @@ class CachedSource extends Source {
275
276
}
276
277
this . _cachedMaps . set ( key , {
277
278
map,
278
- bufferedMap : undefined
279
+ bufferedMap : undefined ,
279
280
} ) ;
280
281
return { source, map } ;
281
282
}
@@ -302,33 +303,32 @@ class CachedSource extends Source {
302
303
onChunk ,
303
304
onSource ,
304
305
onName ,
305
- ! ! ( options && options . finalSource ) ,
306
- true
307
- ) ;
308
- } else {
309
- return streamChunksOfRawSource (
310
- /** @type {string } */
311
- ( source ) ,
312
- onChunk ,
313
- onSource ,
314
- onName ,
315
- ! ! ( options && options . finalSource )
306
+ Boolean ( options && options . finalSource ) ,
307
+ true ,
316
308
) ;
317
309
}
310
+ return streamChunksOfRawSource (
311
+ /** @type {string } */
312
+ ( source ) ,
313
+ onChunk ,
314
+ onSource ,
315
+ onName ,
316
+ Boolean ( options && options . finalSource ) ,
317
+ ) ;
318
318
}
319
- const { result , source , map } = streamAndGetSourceAndMap (
319
+ const sourceAndMap = streamAndGetSourceAndMap (
320
320
this . original ( ) ,
321
321
options ,
322
322
onChunk ,
323
323
onSource ,
324
- onName
324
+ onName ,
325
325
) ;
326
- this . _cachedSource = source ;
326
+ this . _cachedSource = sourceAndMap . source ;
327
327
this . _cachedMaps . set ( key , {
328
- map : /** @type {RawSourceMap } */ ( map ) ,
329
- bufferedMap : undefined
328
+ map : /** @type {RawSourceMap } */ ( sourceAndMap . map ) ,
329
+ bufferedMap : undefined ,
330
330
} ) ;
331
- return result ;
331
+ return sourceAndMap . result ;
332
332
}
333
333
334
334
/**
@@ -344,7 +344,7 @@ class CachedSource extends Source {
344
344
const map = this . original ( ) . map ( options ) ;
345
345
this . _cachedMaps . set ( key , {
346
346
map,
347
- bufferedMap : undefined
347
+ bufferedMap : undefined ,
348
348
} ) ;
349
349
return map ;
350
350
}
@@ -361,7 +361,7 @@ class CachedSource extends Source {
361
361
/** @type {(string | Buffer)[] } */
362
362
const update = [ ] ;
363
363
/** @type {string | undefined } */
364
- let currentString = undefined ;
364
+ let currentString ;
365
365
const tracker = {
366
366
/**
367
367
* @param {string | Buffer } item item
@@ -385,7 +385,7 @@ class CachedSource extends Source {
385
385
}
386
386
update . push ( item ) ;
387
387
}
388
- }
388
+ } ,
389
389
} ;
390
390
this . original ( ) . updateHash ( /** @type {HashLike } */ ( tracker ) ) ;
391
391
if ( currentString !== undefined ) {
0 commit comments