Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES6] bug: TypeError: Assignment to constant variable #2854

Closed
Cweili opened this issue Jan 31, 2018 · 3 comments
Closed

[ES6] bug: TypeError: Assignment to constant variable #2854

Cweili opened this issue Jan 31, 2018 · 3 comments
Labels

Comments

@Cweili
Copy link

Cweili commented Jan 31, 2018

Bug report or feature request?

Bug

ES5 or ES6+ input?

ES6+

Uglify version (uglifyjs -V)

3.3.9

JavaScript input

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});
function foo(a) {
  return console.log(a);
}

exports.default = async function bar(arg) {
  try {
    const a = {};
    if (arg) {
      a[0] = 1;
    }
    console.log((await foo(a)));
  } catch (err) {
    console.log(err);
  }
};

/***/ })
/******/ ]);

The uglifyjs CLI command executed or minify() options used.

uglify-es -ecma 8 -b -o test.min.js test.js

JavaScript output or error produced.

!function(n) {
    const t = {};
    function e(o) {
        if (t[o]) return t[o].exports;
        const r = t[o] = {
            i: o,
            l: !1,
            exports: {}
        };
        return n[o].call(r.exports, r, r.exports, e), r.l = !0, r.exports;
    }
    e.m = n, e.c = t, e.d = function(n, t, o) {
        e.o(n, t) || Object.defineProperty(n, t, {
            configurable: !1,
            enumerable: !0,
            get: o
        });
    }, e.n = function(n) {
        const t = n && n.__esModule ? function() {
            return n.default;
        } : function() {
            return n;
        };
        return e.d(t, "a", t), t;
    }, e.o = function(n, t) {
        return Object.prototype.hasOwnProperty.call(n, t);
    }, e.p = "", e(e.s = 0);
}([ function(n, t, e) {
    Object.defineProperty(t, "__esModule", {
        value: !0
    }), t.default = async function(n) {
        try {
            const t = {};
            n && (t[0] = 1), console.log(await (t = t, console.log(t))); // TypeError: Assignment to constant variable.
        } catch (n) {
            console.log(n);
        }
        var t;
    };
} ]);

uglify-es generates code t = t, courses "TypeError: Assignment to constant variable."

@Cweili Cweili changed the title [ES6]bug: TypeError: Assignment to constant variable [ES6] bug: TypeError: Assignment to constant variable Jan 31, 2018
@Cweili
Copy link
Author

Cweili commented Jan 31, 2018

uglify-es v3.3.7 is fine.
uglify-es v3.3.8 also produce this bug.

@kzc
Copy link
Contributor

kzc commented Jan 31, 2018

The uglify options provided in the bug report were incorrect.

Reduced test case:

$ cat t2854b.js
(async function bar(arg) {
    function foo(a) {
        return typeof a + 123;
    }
    try {
        const a = {};
        if (arg) {
            a[0] = 1;
        }
        console.log(await foo(a));
    } catch (err) {
        console.log(err);
    }
})();
$ cat t2854b.js | node800
object123
$ cat t2854b.js | bin/uglifyjs -bmc | node800
TypeError: Assignment to constant variable.

Anyway, this is a dup of #2842 and can be closed.

@alexlamsl
Copy link
Collaborator

@kzc thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants