-
Notifications
You must be signed in to change notification settings - Fork 38
Description
This library attempts to find dependencies using a regular expression:
Lines 97 to 103 in 2e7827d
| // main bundle deps | |
| var re = new RegExp('(\\\\n|\\W)' + quoteRegExp(webpackRequireName) + dependencyRegExp, 'g') | |
| var match | |
| while ((match = re.exec(fnString))) { | |
| if (match[3] === 'dll-reference') continue | |
| retval[queueName].push(match[3]) | |
| } |
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 🤔