javascriptmicrosoft-ajax-minifierajaxmin

Ajaxmin MinifyJavascript adding {} before object


I am facing an issue while minifying a javascript file using AjaxMin's MinifyJavaScript method.

Unminified Code

if (typeof define === 'function' && define.amd) {
        define(['moment'], function (moment) {
            root.moment = factory(moment)
            return root.moment
        })
    } else if (typeof exports === 'object') {
        module.exports = factory(require('moment'))
    } else {
        root.moment = factory(root.moment)
    }

Minified Code

if(typeof define=="function"&&define.amd)define(["moment"],function(i){return n.moment=t(i),n.moment});else if(typeof exports=="object"){module{}.exports=t(require("moment"))}else n.moment=t(n.moment)}

Here in minified code "{}" is added after module object e.g.: module{}.exports but it should be module.exports

There are few more files before minifying the file: 1. jquery-3.3.1.min.js 2. moment.min.js

All the files are bundled in single file and after that minification is done.


Solution

  • I think this are the causes to the problem

    1. ajaxmin source code module seems to be a reserved word
    2. If/else scopes doesn't compiles properly to the output.

    This seems to causing the issue

    var blockType = AjaxMin.BlockTypeModule.FormatInvariant
    (moduleScope.ScopeName.IfNullOrWhiteSpace(AjaxMin.ModuleNameImplicit));
    

    Workaround (this is what I did in my project):