@@ -41,7 +41,6 @@ const WorkerDependency = require("./WorkerDependency");
4141/** @typedef {import("../Dependency").DependencyLocation } DependencyLocation */
4242/** @typedef {import("../Entrypoint").EntryOptions } EntryOptions */
4343/** @typedef {import("../NormalModule") } NormalModule */
44- /** @typedef {import("../Module") } Module */
4544/** @typedef {import("../javascript/JavascriptParser") } JavascriptParser */
4645/** @typedef {import("../javascript/JavascriptParser") } Parser */
4746/** @typedef {import("../javascript/JavascriptParser").JavascriptParserState } JavascriptParserState */
@@ -114,9 +113,6 @@ class WorkerPlugin {
114113 new CreateScriptUrlDependency . Template ( )
115114 ) ;
116115
117- /** @type {WeakMap<Module, Record<string, AsyncDependenciesBlock>> } */
118- const modBlockMap = new WeakMap ( ) ;
119-
120116 /**
121117 * @param {JavascriptParser } parser the parser
122118 * @param {Expression } expr expression
@@ -374,51 +370,38 @@ class WorkerPlugin {
374370 entryOptions . name = options . name ;
375371 }
376372
377- if ( ! modBlockMap . has ( parser . state . module ) ) {
378- modBlockMap . set ( parser . state . module , { } ) ;
379- }
380- // For the same URL, we try to reuse the same AsyncDependenciesBlock
381- const key = `name(${ entryOptions . name } ), url(${ url } )` ;
382- const cache =
383- /** @type {Record<string, AsyncDependenciesBlock> } */ (
384- modBlockMap . get ( parser . state . module )
373+ if ( entryOptions . runtime === undefined ) {
374+ const i = workerIndexMap . get ( parser . state ) || 0 ;
375+ workerIndexMap . set ( parser . state , i + 1 ) ;
376+ const name = `${ cachedContextify (
377+ parser . state . module . identifier ( )
378+ ) } |${ i } `;
379+ const hash = createHash ( compilation . outputOptions . hashFunction ) ;
380+ hash . update ( name ) ;
381+ const digest = hash . digest ( compilation . outputOptions . hashDigest ) ;
382+ entryOptions . runtime = digest . slice (
383+ 0 ,
384+ compilation . outputOptions . hashDigestLength
385385 ) ;
386- if ( ! cache [ key ] ) {
387- if ( entryOptions . runtime === undefined ) {
388- const i = workerIndexMap . get ( parser . state ) || 0 ;
389- workerIndexMap . set ( parser . state , i + 1 ) ;
390- const name = `${ cachedContextify (
391- parser . state . module . identifier ( )
392- ) } |${ i } `;
393- const hash = createHash ( compilation . outputOptions . hashFunction ) ;
394- hash . update ( name ) ;
395- const digest = hash . digest (
396- compilation . outputOptions . hashDigest
397- ) ;
398- entryOptions . runtime = digest . slice (
399- 0 ,
400- compilation . outputOptions . hashDigestLength
401- ) ;
402- }
403- const block = new AsyncDependenciesBlock ( {
404- name : entryOptions . name ,
405- entryOptions : {
406- chunkLoading : this . _chunkLoading ,
407- wasmLoading : this . _wasmLoading ,
408- ...entryOptions
409- }
410- } ) ;
411- block . loc = expr . loc ;
412- parser . state . module . addBlock ( block ) ;
413- cache [ key ] = block ;
414386 }
415- const block = cache [ key ] ;
387+
388+ const block = new AsyncDependenciesBlock ( {
389+ name : entryOptions . name ,
390+ key : url ,
391+ entryOptions : {
392+ chunkLoading : this . _chunkLoading ,
393+ wasmLoading : this . _wasmLoading ,
394+ ...entryOptions
395+ }
396+ } ) ;
397+ block . loc = expr . loc ;
416398 const dep = new WorkerDependency ( url , range , {
417399 publicPath : this . _workerPublicPath ,
418400 needNewUrl
419401 } ) ;
420402 dep . loc = /** @type {DependencyLocation } */ ( expr . loc ) ;
421403 block . addDependency ( dep ) ;
404+ parser . state . module . addBlock ( block ) ;
422405
423406 if ( compilation . outputOptions . trustedTypes ) {
424407 const dep = new CreateScriptUrlDependency (
0 commit comments