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

Setting of global object property is optimized away despite being used in constructor #2924

Closed
atom-b opened this issue May 14, 2018 · 1 comment
Assignees

Comments

@atom-b
Copy link

atom-b commented May 14, 2018

This only repros with SIMPLE_OPTIMIZATIONS. Advanced generates code that behaves as expected.

Repro:

// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level SIMPLE_OPTIMIZATIONS
// @formatting pretty_print
// ==/ClosureCompiler==

var flags = {internal: false};

/** @constructor */
var checkFlag = function() {
	if(!flags.internal ) {
		throw ("Error: flags.internal is " + flags.internal + "!");
    }
};

var getCheckFlag = function() {
    flags.internal = true;
    var cf = new checkFlag();
    // flags.checkFlag = checkFlag(); // works
    flags.internal = false;
    return cf;
};

var myCheckFlag = getCheckFlag();

Output:

var flags = {internal:!1}, checkFlag = function() {
  if (!flags.internal) {
    throw "Error: flags.internal is " + flags.internal + "!";
  }
}, getCheckFlag = function() {
  var a = new checkFlag;
  flags.internal = !1;
  return a;
}, myCheckFlag = getCheckFlag();

checkFlag() throws because there is no flags.internal = !0; before var a = new checkFlag;.

Possibly related to #2874 ?

@lauraharker lauraharker self-assigned this May 16, 2018
Yannic pushed a commit to Yannic/com_google_closure_compiler that referenced this issue Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants