条件付き置き換え:閉鎖コンパイラは明らかに、私は次のテストを持っている間違った三元表現
「最後の項目はZEROと一致していません」:
goog.provide('testing.Test');
goog.require('goog.array');
/**
* @constructor
*/
testing.Test = function() {
/**
* @type {!Array.<number>}
* @private
*/
this.array_ = [];
};
/**
* @enum {number}
*/
testing.Test.Constant = {
ZERO: 0,
ONE: 1
};
testing.Test.prototype.run = function() {
if (goog.array.peek(this.array_) === testing.Test.Constant.ZERO) {
console.log('last item matches ZERO');
} else {
console.log('last item does not match ZERO');
}
};
var test = new testing.Test();
console.log(test.run());
デフォルトの最適化してコンパイルし、実行しているが期待される結果が得られ
ただし、ADVANCED_OPTIMIZATIONSでコンパイルして実行すると、予期しない結果が発生します。
「最後の項目はゼロと一致します」。
私は最適化コンパイルからの出力に問題をトレースしました:
function b(){this.a=[]}console.log(function(){var a=(new b).a;a[a.length-1]?console.log("last item does not match ZERO"):console.log("last item matches ZERO")}());
コンパイラは、三元で、条件を交換するように見えますが、平等のチェックを落とします。
これは予期された動作ですか、もしそうなら、私は何が欠けていますか?
私は20170124.0.0 NPMパッケージを使用してコンパイラとライブラリを実行しています。しかし、NPMからテストしたコンパイラのすべてのバージョンで同じ結果が得られます。
コンパイラjarfileの以前のバージョンでは、動作を表示していません。私のメモによれば、このバージョンは2016年6月上旬にソースからダウンロードまたはコンパイルされています。