Possible bug when compiling BabylonJS with the Closure compiler

I’m using BabylonJS in a Clojurescript project and so far things are going quite well. I’m having an issue when upgrading BabylonJS from version 4.0.3 (which works) to version 4.1.0 (which breaks). I believe it’s triggered by Google’s closure compiler which is internally used by Shadow-cljs. I’m not sure if the issue is a bug with BabylonJS or with the compiler. It’s caused by the following code in src/Misc/depthReducer.ts line 101:

public dispose(disposeAll = true): void {
    super.dispose(disposeAll);

    if (this._depthRenderer && disposeAll) {
        delete this._depthRenderer.getDepthMap().getScene()?._depthRenderer[this._depthRendererId];

        this._depthRenderer.dispose();
        this._depthRenderer = null;
    }
}

This gets transpiled as:

DepthReducer.prototype.dispose = function (disposeAll) {
    if (disposeAll === void 0) { disposeAll = true; }
    var _a;
    _super.prototype.dispose.call(this, disposeAll);
    if (this._depthRenderer && disposeAll) {
        delete ((_a = this._depthRenderer.getDepthMap().getScene()) === null || _a === void 0 ? void 0 : _a._depthRenderer[this._depthRendererId]);
        this._depthRenderer.dispose();
        this._depthRenderer = null;
    }
};

This triggers the following error: “Invalid delete operand. Only properties can be deleted.”. Replacing the “?.” operator by an if statement fixes the error.

I’m guessing my setup is not supported but I’ve seen other people were interested in Closure compiler support (Using Closure Compiler to compile BabylonJS ). Should I submit a patch ? It seems to be the only issue related to closure at the moment.

1 Like

Yes I think you can submit a PR, delete void 0 seems borderline, I don’t know what the spec is saying about this…

2 Likes