Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Excessing object wrapping. #5600
I'm noticing with webpack v3 there's a lot of this kind of generated code:
Object(__WEBPACK_IMPORTED_MODULE_3__module_resolve_filename_js__["a" /* default */])(foo)
What's the reason for wrapping all references with
The reason is to call the function with the correct this context:
import x from "module"; x(foo); // <- called without this (undefined/root)
var __WEBPACK_IMPORTED_MODULE_1__module__ = __webpack_require__(1); __WEBPACK_IMPORTED_MODULE_1__module__.default(foo); // ^ called with this = __WEBPACK_IMPORTED_MODULE_1__module__ Object(__WEBPACK_IMPORTED_MODULE_1__module__.default)(foo); // ^ called without this (undefined/root)
The Object() is generated when calling a imported symbol directly. I omitted this in an older version, assuming nobody care about
Most of these are optimized away with the ModuleConcatenationPlugin.
A bit of history of this: (This started 1.5 years ago)
Here are up-to-date results:
Our Parser is not so clever to track what's before the identifier.
@bmeurer Caching the export is not always correct as these are live bindings which can change anytime.
pushed a commit
Aug 31, 2017
Great to see. If you want to you could improve the error messages for this cases a bit:
This would help people debugging undefined/null functions.
I noticed that
Narrowed it down that when