简体   繁体   中英

Problems minifying javascript file (asp.net application)

I have the following javascript code:

class UrlParameters {

constructor() {
    this.initVariablesWithDefaultValues();
    var serverUrlData = HelperJSViewBag.getValue("UrlData", true);
    var urlVariables = serverUrlData ? serverUrlData : HLinks.getAllUrlVariables();
    var sessionID = this.convertToString(urlVariables["sessionID"]);
    var idSession = this.convertToString(urlVariables["idSession"]);
    var sessionid = this.convertToString(urlVariables["sessionid"]);

    if (idSession.length > 0)
        this.sessionID = idSession;
    else if (sessionid.length > 0)
        this.sessionID = sessionid;
    else 
        this.sessionID = sessionID;

    var countryISO = this.convertToString(urlVariables["countryISO"]);
    var country = this.convertToString(urlVariables["country"]);
    this.countryISO = countryISO.length > 0 ? countryISO : country;

    var productRef = this.convertToString(urlVariables["productRef"]);
    var pRef = this.convertToString(urlVariables["ref"]);
    var refproduct = this.convertToString(urlVariables["refproduct"]);
    var productReference = this.convertToString(urlVariables["productReference"]);

    if (productRef.length > 0)
        this.productReference = productRef;
    else if (pRef.length > 0)
        this.productReference = pRef;
    else if (refproduct.length > 0)
        this.productReference = refproduct;
    else
        this.productReference = productReference;

    var PartnerCode = this.convertToString(urlVariables["PartnerCode"]);
    var partnerCode = this.convertToString(urlVariables["partnerCode"]);

    this.partnerCode = PartnerCode.length > 0 ? PartnerCode : partnerCode;

    var themeReference = this.convertToString(urlVariables["themeReference"]);
    var theme = this.convertToString(urlVariables["theme"]);
    this.themeReference = themeReference.length > 0 ? themeReference : theme;

    this.projectName = this.convertToString(urlVariables["projectName"]);

    var coverReference = this.convertToString(urlVariables["coverReference"]);
    var refCover = this.convertToString(urlVariables["refCover"]);
    this.coverReference = coverReference.length > 0 ? coverReference : refCover;

    this.themeFill = this.convertToInt(urlVariables["themeFill"], 0);  // 0 -> directly without autofill ; 1 -> not directly without autofill ; 2 -> not directly quick autofill ; 3 -> not directly smart autofill
    this.smartOpt = this.convertToInt(urlVariables["smartOpt"], 2);  //1->faces,colors,dimentions; 2-> colors and dimentions; 3-> dimentions

    var open = this.convertToString(urlVariables["open"]);
    var projectCode = this.convertToString(urlVariables["projectCode"]);

    this.projectCode = open.length > 0 ? open : projectCode;

    this.productCode = this.convertToString(urlVariables["productCode"]);

    this.projectID = this.convertToString(urlVariables["projectID"]);

    var categoryID = this.convertToInt(urlVariables["categoryID"]);
    var cat = this.convertToInt(urlVariables["cat"]);
    this.categoryID = categoryID > 0 ? categoryID : cat;

    var subCategoryReference = this.convertToString(urlVariables["subCategoryReference"]);
    var subCat = this.convertToString(urlVariables["subCat"]);
    this.subCategoryReference = subCategoryReference.length > 0 ? subCategoryReference : subCat;

    var typeFinishID = this.convertToInt(urlVariables["typeFinishID"]);
    var refProdutFinish = this.convertToInt(urlVariables["refProdutFinish"]);
    var productTypeFinishID = this.convertToInt(urlVariables["productTypeFinishID"]);

    if (typeFinishID > 0)
        this.productTypeFinishID = typeFinishID;
    else if (refProdutFinish > 0)
        this.productTypeFinishID = refProdutFinish;
    else
        this.productTypeFinishID = productTypeFinishID;

    var coverTypeFinishID = this.convertToInt(urlVariables["coverTypeFinishID"]);
    var coverFinishID = this.convertToInt(urlVariables["coverFinishID"]);
    var refCoverFinish = this.convertToInt(urlVariables["refCoverFinish"]);

    if (coverTypeFinishID > 0) this.coverTypeFinishID = coverTypeFinishID;
    else if (coverFinishID > 0) this.coverTypeFinishID = coverFinishID;
    else this.coverTypeFinishID = refCoverFinish;

    var numPages = this.convertToInt(urlVariables["numPages"]);
    var refPages = this.convertToInt(urlVariables["refPages"]);
    var numberOfPages = this.convertToInt(urlVariables["numberOfPages"]);

    if (numPages > 0)
        this.numberOfPages = numPages;
    else if (refPages > 0)
        this.numberOfPages = refPages;
    else
        this.numberOfPages = numberOfPages;

    this.coverType = this.convertToString(urlVariables["coverType"]);

    var textureID = this.convertToString(urlVariables["textureID"]);
    var textureReference = this.convertToString(urlVariables["textureReference"]);

    if (textureID.length > 0) this.textureReference = textureID;
    else this.textureReference = textureReference;

    var textureColorID = this.convertToString(urlVariables["textureColorID"]);
    var textureColorReference = this.convertToString(urlVariables["textureColorReference"]);
    var refColor = this.convertToString(urlVariables["refColor"]);

    if (textureColorID.length > 0) this.textureColorReference = textureColorID;
    else if (refColor.length > 0) this.textureColorReference = refColor;
    else this.textureColorReference = textureColorReference;

    var windowID = this.convertToString(urlVariables["windowID"]);
    var refWindow = this.convertToString(urlVariables["refWindow"]);
    var windowReference = this.convertToString(urlVariables["windowReference"]);

    if (windowID.length > 0)
        this.windowReference = windowID;
    else if (refWindow.length > 0)
        this.windowReference = refWindow;
    else
        this.windowReference = windowReference;

    this.savedProject = this.convertToBoolean(urlVariables["savedProject"]);

    this.startMonth = this.convertToInt(urlVariables["startMonth"]);
    this.startYear = this.convertToInt(urlVariables["startYear"]);
    this.wantHolidays = this.convertToBoolean(urlVariables["wantHolidays"]);

    var frameID = this.convertToString(urlVariables["frameID"]);
    var frameReference = this.convertToString(urlVariables["frameReference"]);
    var canvasRef = this.convertToString(urlVariables["canvasRef"]);

    if (frameID.length > 0)
        this.frameReference = frameID;
    else if (canvasRef.length > 0)
        this.frameReference = canvasRef;
    else
        this.frameReference = frameReference;

    this.frameReference = frameID.length > 0 ? frameID : frameReference;

    var colorFrameID = this.convertToString(urlVariables["colorFrameID"]);
    var frameColorReference = this.convertToString(urlVariables["frameColorReference"]);
    var canvasColor = this.convertToString(urlVariables["canvasColor"]);

    if (colorFrameID.length > 0)
        this.frameColorReference = colorFrameID;
    else if (canvasColor.length > 0)
        this.frameColorReference = canvasColor;
    else
        this.frameColorReference = frameColorReference;

    this.albumXML = this.convertToString(urlVariables["albumXML"]);
    this.pagesXML = this.convertToString(urlVariables["pagesXML"]);

    var languageISO = this.convertToString(urlVariables["languageISO"]);
    var lang = this.convertToString(urlVariables["lang"]);

    if (languageISO.length > 0)
        this.languageISO = languageISO;
    else if (lang.length > 0)
        this.languageISO = lang;

    this.openThemeAccordion = this.convertToBoolean(urlVariables["openThemeAccordion"]);

    var galleryID = this.convertToString(urlVariables["galleryID"]);
    var galleryReference = this.convertToString(urlVariables["galleryReference"]);
    this.galleryReference = galleryID.length > 0 ? galleryID : galleryReference;

    var login_page = this.convertToString(urlVariables["login_page"]);
    var Login_Page = this.convertToString(urlVariables["Login_Page"]);
    this.Login_Page = this.convertToBoolean(login_page.length > 0 ? login_page : Login_Page);
    this.forceMobile = this.convertToBoolean(urlVariables["forceMobile"]);
    this.clientApplication = this.convertToString(urlVariables["clientApplication"]);
    this.goToPreview = this.convertToInt(urlVariables["goToPreview"]);
    this.orderID = this.convertToInt(urlVariables["orderID"], -1);

    this.CID = this.convertToString(urlVariables["CID"]);
    this.unblock = this.convertToBoolean(urlVariables["unblock"]);

    var idPartner = this.convertToInt(urlVariables["idPartner"]);
    var partnerID = this.convertToInt(urlVariables["partnerID"]);
    var idEmp = this.convertToInt(urlVariables["idEmp"]);
    this.forceException = this.convertToBoolean(urlVariables["forceException"]);

    if (idPartner > 0)
        this.partnerID = idPartner;
    else if (partnerID > 0)
        this.partnerID = partnerID;
    else if (idEmp > 0)
        this.partnerID = idEmp;

    this.goDirectlyToEditor = this.convertToBoolean(urlVariables["goDirectlyToEditor"]);
}

static getInstance() {
    if (typeof UrlParameters.urlParameters === "undefined")
        UrlParameters.urlParameters = new UrlParameters();

    return UrlParameters.urlParameters;
}

getData() {
    return {
        sessionID : this.sessionID,
        countryISO: this.countryISO,
        productReference: this.productReference,
        partnerCode: this.partnerCode,
        themeReference: this.themeReference,
        projectName: this.projectName,
        coverReference: this.coverReference,
        themeFill: this.themeFill,
        smartOpt: this.smartOpt,
        projectCode: this.projectCode,
        productCode: this.productCode,
        projectID: this.projectID,
        categoryID: this.categoryID,
        subCategoryReference: this.subCategoryReference,
        productTypeFinishID: this.productTypeFinishID,
        coverTypeFinishID: this.coverTypeFinishID,
        numberOfPages: this.numberOfPages,
        coverType: this.coverType,
        textureReference: this.textureReference,
        textureColorReference: this.textureColorReference,
        windowReference: this.windowReference,
        savedProject: this.savedProject,
        startMonth: this.startMonth,
        startYear: this.startYear,
        wantHolidays: this.wantHolidays,
        frameReference: this.frameReference,
        frameColorReference: this.frameColorReference,
        albumXML: this.albumXML,
        pagesXML: this.pagesXML,
        languageISO: this.languageISO,
        openThemeAccordion: this.openThemeAccordion,
        galleryReference: this.galleryReference,
        Login_Page: this.Login_Page,
        forceMobile: this.forceMobile,
        clientApplication: this.clientApplication,
        goToPreview: this.goToPreview,
        orderID: this.orderID,
        CID: this.CID,
        unblock: this.unblock,
        partnerID: this.partnerID,
        forceException: this.forceException,
        goDirectlyToEditor: this.goDirectlyToEditor

    }
}

getVariableOnce(name) {
    if (!this.variableOnce) this.variableOnce = this.getData();

    var value = this.variableOnce[name];
    delete this.variableOnce[name];

    return value;
}

initVariablesWithDefaultValues() {
    this.projectName = "";
    this.productReference = "";
    this.coverReference = "";
    this.textureReference = "";
    this.colorReference = "";
    this.windowReference = "";
    this.numberOfPages = 0;
    this.productTypeFinishID = 0;
    this.coverTypeFinishID = 0;
    this.canvasColor = "";
    this.projectCode = "";
    this.sessionID = "";
    this.countryISO = "";
    this.themeReference = "";
    this.themeFill = 0;
    this.smartOpt = 2;
    this.projectID = "";
    this.productCode = "";
    this.categoryID = -1;
    this.savedProject = false;
    this.startMonth = 0;
    this.startYear = 0;
    this.wantHolidays = false;
    this.albumXML = "";
    this.pagesXML = "";
    this.languageISO = "";
    this.Login_Page = false;
    this.frameReference = "";
    this.frameColorReference = "";
    this.partnerCode = "";
    this.partnerID = "";
    this.coverType = "";
    this.textureColorReference = ""
    this.subCategoryReference = "";
    this.openThemeAccordion = false;
    this.galleryReference = "";
    this.clientApplication = "";
    this.forceMobile = false;
    this.idUpload = 0;
    this.orderID = -1;
    this.idControl = 0;
    this.goToPreview = 0;
    this.unblock = false;
    this.CID = "";
    this.forceException = false;
    this.goDirectlyToEditor = false;
}

convertToString(value, defaultValue) {
    if (typeof defaultValue !== "var") defaultValue = "";

    if (value)
        return value;
    else
        return defaultValue;
}

convertToInt(value, defaultValue) {
    if (typeof defaultValue !== "number") defaultValue = 0;

    if (value)
        return parseInt(value);
    else
        return defaultValue;
}

convertToBoolean(value, defaultValue) {
    if (typeof defaultValue !== "boolean") defaultValue = false;

    if (value)
        return value;
    else
        return defaultValue;
}
}

When I run my application with the BundleTable.EnableOptimizations = true the asp.net does not minify this files. Istead, return a new file with the following errors:

/* Minification failed. Returning unminified contents.
(1,1-6): run-time error JS1195: Expected expression: class
(3,19-20): run-time error JS1004: Expected ';': {
(201,12-23): run-time error JS1004: Expected ';': getInstance
(201,26-27): run-time error JS1004: Expected ';': {
(208,15-16): run-time error JS1004: Expected ';': {
(256,27-28): run-time error JS1004: Expected ';': {
(265,38-39): run-time error JS1004: Expected ';': {
(314,42-43): run-time error JS1004: Expected ';': {
(323,39-40): run-time error JS1004: Expected ';': {
(332,43-44): run-time error JS1004: Expected ';': {
(341,1-2): run-time error JS1002: Syntax error: }
(336,13-25): run-time error JS1018: 'return' statement outside of function: return value
(338,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(327,13-35): run-time error JS1018: 'return' statement outside of function: return parseInt(value)
(329,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(318,13-25): run-time error JS1018: 'return' statement outside of function: return value
(320,13-32): run-time error JS1018: 'return' statement outside of function: return defaultValue
(262,9-21): run-time error JS1018: 'return' statement outside of function: return value
(209,9,253,10): run-time error JS1018: 'return' statement outside of function: return {
            sessionID : this.sessionID,
            countryISO: this.countryISO,
            productReference: this.productReference,
            partnerCode: this.partnerCode,
            themeReference: this.themeReference,
            projectName: this.projectName,
            coverReference: this.coverReference,
            themeFill: this.themeFill,
            smartOpt: this.smartOpt,
            projectCode: this.projectCode,
            productCode: this.productCode,
            projectID: this.projectID,
            categoryID: this.categoryID,
            subCategoryReference: this.subCategoryReference,
            productTypeFinishID: this.productTypeFinishID,
            coverTypeFinishID: this.coverTypeFinishID,
            numberOfPages: this.numberOfPages,
            coverType: this.coverType,
            textureReference: this.textureReference,
            textureColorReference: this.textureColorReference,
            windowReference: this.windowReference,
            savedProject: this.savedProject,
            startMonth: this.startMonth,
            startYear: this.startYear,
            wantHolidays: this.wantHolidays,
            frameReference: this.frameReference,
            frameColorReference: this.frameColorReference,
            albumXML: this.albumXML,
            pagesXML: this.pagesXML,
            languageISO: this.languageISO,
            openThemeAccordion: this.openThemeAccordion,
            galleryReference: this.galleryReference,
            Login_Page: this.Login_Page,
            forceMobile: this.forceMobile,
            clientApplication: this.clientApplication,
            goToPreview: this.goToPreview,
            orderID: this.orderID,
            CID: this.CID,
            unblock: this.unblock,
            partnerID: this.partnerID,
            forceException: this.forceException,
            goDirectlyToEditor: this.goDirectlyToEditor

        }
(205,9-43): run-time error JS1018: 'return' statement outside of function: return UrlParameters.urlParameters
 */

I search a lot on the internet but I didn't find any solution for this case. Maybe, it's because I'm using the ES6 standard?

I'm using the 1.1.0.0 version of System.Web.Optimization.

System.Web.Optimization doesn't support ES6 syntax

I suggest you to integrate gulp , grunt or webpack into your build process in order to minify your scripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM