Do you want to request a feature or report a bug?
Bug
What is the current behavior?
(I wanna cry: )The optimization of Scope Hoisting could break core-js
Array.from
.
After updated to webpack v3. My code will throw the error:
Uncaught TypeError: Cannot assign to read only property 'length' of function 'function from() { [native code] }'
If the current behavior is a bug, please provide the steps to reproduce.
The error due to wrong context:
- webpack use
__webpack_require__.n
&__webpack_require__.d
to mangle exports name; - Array.from transformed to
__WEBPACK_IMPORTED_MODULE_4_babel_runtime_core_js_array_from___default.a
; - While calling
arrayfrom.a(arraylike)
, the context will befunction getDefault
; - es6.array.from.js#L15,
C
will begetDefault
; - #L25
new C()
will returnfunction from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {...}
; createProperty
will make the returned function propertylength
read only;- finally when it call
result.length = index
, the errorUncaught TypeError
will be threw.
What is the expected behavior?
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
webpack v3
See also #5111 (comment)
This ticket is about
3.0.0
, no need to corroborate that you have this bug with the same version of webpack in the original issue.@blade254353074 why did you close this? It’s not fixed AFAIK. 🙂
…
Aint sure where this should be fixed, but I’ve proposed a quick fix in the
core-js. Maybe @zloirock <https://github.com/zloirock> will have some
insight what should be done to fix it properly.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5135 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABJFPypSDiFEGcZsNq7xcbGimtLhbrWVks5sJMbhgaJpZM4OB8nB>
.
The problem is a size optimization that webpack does by default by not correctly setting the
this
when calling an import directly as a function.Enable
strictThisContextOnImports
to fix this, as mentioned in #5135 (comment). It will change your invocation fromarrayfrom.a(arraylike)
to__webpack__require__.i(arrayfrom.a)(arraylike)
, so that it will correctly have no context.babel does the same without using a helper function, though (the babel equivalent would be
(0, arrayfrom.a)(arraylike)
); maybe webpack could do that too.