Erroneous detection of dependencies can lead to syntax error in Worker
This library attempts to find dependencies using a regular expression:
https://github.com/borisirota/webworkify-webpack/blob/2e7827dc8e88a4eb45055d0cc7a0597de0d4fd99/index.js#L97-L103
In minified code, webpackRequireName will often be a single-character function name like r, so this regex will detect all occurrences of r(…). Unfortuantely, the r() function name may also be used in other scopes for a totally different function, so this dependency detection can pick up a totally random argument and treat it as a dependency.
In our case (as users of hls.min.js) this function call is minified to r('init', null), and so 'init' is erroneously detected as a dependency.
Ordinarily this fails silently and doesn't affect functionality. When assembling the WebWorker blob, for id='init', the call to sources.main[id] returns undefined and things carry on without raising any errors. However, if there is variable/function defined on the Array class with the name init, then it will be returned, stringified, and lead to a syntax error in the Worker. (In our case, that init function is added to the Array prototype by ember.js)
So, with both of those very unlucky circumstances, we end up with this when the Worker is initialized:
Uncaught SyntaxError: Unexpected token '{' (at efc643e5-eb1d-4408-939d-225e166586ac:135:20)
I imagine a robust fix to the dependency-detection will be tricky - parsing JS with Regex is naturally not going to be perfect. But I wonder if it might be possible to mitigate the errors when it does happen 🤔