@@ -11,10 +11,13 @@ let imageCompressionLibUrl;
11
11
let worker ;
12
12
13
13
function createWorker ( script ) {
14
+ const blobArgs = [ ] ;
14
15
if ( typeof script === 'function' ) {
15
- script = `(${ script } )()` ;
16
+ blobArgs . push ( `(${ script } )()` ) ;
17
+ } else {
18
+ blobArgs . push ( script ) ;
16
19
}
17
- return new Worker ( URL . createObjectURL ( new Blob ( [ script ] ) ) ) ;
20
+ return new Worker ( URL . createObjectURL ( new Blob ( blobArgs ) ) ) ;
18
21
}
19
22
20
23
function createSourceObject ( str ) {
@@ -32,9 +35,12 @@ function parse(o) {
32
35
Object . entries ( o ) . forEach ( ( [ key , value ] ) => {
33
36
if ( typeof value === 'string' && value . startsWith ( 'BIC_FN:::' ) ) {
34
37
try {
38
+ // eslint-disable-next-line no-eval
35
39
result [ key ] = eval ( value . replace ( / ^ B I C _ F N : : : / , '' ) ) ;
36
40
} catch ( e ) {
37
- // console.log(key, e);
41
+ if ( process . env . BUILD === 'development' ) {
42
+ console . error ( key , e ) ;
43
+ }
38
44
throw e ;
39
45
}
40
46
} else {
@@ -335,9 +341,10 @@ function generateWorkerScript() {
335
341
` ) ;
336
342
}
337
343
338
- export function compressOnWebWorker ( file , options ) {
339
- return new Promise ( async ( resolve , reject ) => {
340
- const id = cnt ++ ;
344
+ export default function compressOnWebWorker ( file , options ) {
345
+ return new Promise ( ( resolve , reject ) => {
346
+ cnt += 1 ;
347
+ const id = cnt ;
341
348
342
349
if ( ! imageCompressionLibUrl ) {
343
350
imageCompressionLibUrl = generateLib ( ) ;
0 commit comments