closure-compiler
closure-compiler copied to clipboard
JSC_INEXISTENT_PROPERTY_WITH_SUGGESTION is hidden if the inexistent property is set in unrelated code.
Hello, not sure if this is expected behavior. Below code is minimal sample tested in ADVANCED mode on: https://closure-compiler.appspot.com/
/**
* @constructor
* @struct
*/
function SGlobal() {
this.className = "SGlobal";
}
/** @type {number}*/
SGlobal.scale = 1;
/**
* @constructor
* @struct
* @param {number} x
*/
function ZoomManager(x) {
this.m_x = x * SGlobal.scale;
}
/**
* @param {number} time
* @param {number} x
*/
ZoomManager.prototype.onDisplace = function(time, x) {
this.m_x = x + time * SGlobal.scaleT; // <--- THIS IS A TYPO, property was 'scale'
};
ZoomManager.prototype.neverCalled = function() {
//SGlobal.scaleT = 4;
};
var obj = new ZoomManager(10);
obj.onDisplace(0.5, 1);
var dist = obj.m_x;
console.log(dist);
This code has a typo and the compiler correctly points the error:
JSC_INEXISTENT_PROPERTY_WITH_SUGGESTION: Property scaleT never defined on SGlobal. Did you mean scale? at line 25 character 31
But if you are unlucky like me and have a second typo in other unrelated part of your code the warning goes away and no warning or error is printed. Here I put the second typo in a method of the class that is never called
ZoomManager.prototype.neverCalled = function() {
SGlobal.scaleT = 4; // <--- SECOND TYPO, replace this code in above example
};
What is interesting is that the compiler somehow knows that the output is undefined because is producing compiled code with NaN:
'use strict';
var a = new function() {
this.g = 10;
}();
a.g = NaN;
console.log(a.g);
I was under the impression that the compiler warned me whenever an undeclared property of a @struct was tried to use.