side-effecting function call being dropped

383 views
Skip to first unread message

Brian Craft

unread,
Mar 23, 2015, 4:43:35 PM3/23/15
to ugli...@googlegroups.com
Trying to use webpack code splits with uglify. webpack emits code like this:

function(module, exports, __webpack_require__) {

    /*global document: false, require: false, __webpack_public_path__: true */
    'use strict';
    var config = __webpack_require__(1);
    __webpack_require__.p = config.baseurl;
    if (document.location.pathname.match(/datapages\/$/)) {
        __webpack_require__.e/* nsure */(1, function () {
            !/* require */(/* empty */[__webpack_require__(2)]);
        });
    } else if (document.location.pathname.match(/hub\/$/)) {
        __webpack_require__.e/* nsure */(2, function () {
            !/* require */(/* empty */[__webpack_require__(4)]);
        });
    ...

Uglify drops the contents of the inner functions:

function(t, n, e) {
    "use strict";
    var a = e(1);
    e.p = a.baseurl, document.location.pathname.match(/datapages\/$/) ? 
         e.e(1, function() {}) : document.location.pathname.match(/hub\/$/) ? 
         e.e(2, function() {}) : ...

and emits warnings:

WARNING in main.js from UglifyJs
Dropping side-effect-free statement [./js/bogorouter.js:7,2]
Dropping side-effect-free statement [./js/bogorouter.js:11,2]
Dropping side-effect-free statement [./js/bogorouter.js:20,2]

Why does it think the __webpack_require__() calls are not side-effecting? They are.

Mihai Călin Bazon

unread,
Mar 23, 2015, 5:11:17 PM3/23/15
to ugli...@googlegroups.com
Looks like a bug, please file an issue at Github about it.

--
You received this message because you are subscribed to the Google Groups "UglifyJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uglifyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Mihai Călin Bazon

unread,
Mar 23, 2015, 5:29:58 PM3/23/15
to ugli...@googlegroups.com
Any case, I pushed a fix.

Brian Craft

unread,
Mar 23, 2015, 6:00:37 PM3/23/15
to ugli...@googlegroups.com
Awesome, thanks!
Reply all
Reply to author
Forward
0 new messages