闭包编译器--调试解决了我的错误

Closure compiler --debug solves my bug

本文关键字:我的 错误 解决 调试 编译器 闭包      更新时间:2023-09-26

所以调试似乎有了新的意义,至少在闭包编译器中是这样。

我有一个相当大的代码库,隔离问题是一项艰巨的任务。在我的入口点类中,我实例化依赖项。其中一个没有正确创建,对象在那里,但它的构造函数没有被调用。

这只发生在ADVANCED模式下,所以我尝试传递--debug标志,瞧,bug消失了,构造函数被调用了。这真是令人震惊。我不能复制粘贴任何特定的代码,你有什么建议?

/**
 * @param {Element} parent
 * @param {Object}  opts
 * @constructor
 */
ns.App = function(parent, opts) {
    this.options = new ns.Options(opts || {});
    var w = this.options.width || parent.offsetWidth;
    var h = this.options.height || parent.offsetHeight;
    this.view = new ns.AppView(w, h);
    this.history = new ns.CommandManager();
    // ....
    // this one doesn't get called
    this.amx_ = new ns.ActivityManager(this, this.options);
    // this one does
    this.output_ = new ns.Writer();
    this.bind_();
};

使用Closure编译器,当调试标志使错误消失时,通常表明存在重命名冲突。这可能是由于在外部定义的对象上设置属性而导致的,该对象的属性没有完全定义给编译器。编译器将您的属性重命名为与现有属性相同的名称。

这也可能是由于使用点式语法(obj.prop)引用属性而导致的,在点式语法中,属性是使用引号(obj['prop'])声明的。根据定义,编译器将这些视为不同的属性。

请确保打开--warning_level VERBOSE以帮助识别访问未定义的属性。尽管你的特殊情况仍有可能得不到认可。