Issue of jsTree in combination with Babel #1684

Closed
apfelbox opened this Issue Jan 10, 2017 · 1 comment

Projects

None yet

2 participants

@apfelbox

Hi,

Installed versions

babel-core@6.21.0
babel-preset-es2015@6.18.0
jstree@3.3.3

The es2015 preset is used with the global: true option.

The issue

Babel replaces the typeof operator with a forward compatible function:

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

This breaks jsTree when using service workers for parsing JSON, as the service worker is created by just copying the function code to the worker:

this._wrk = window.URL.createObjectURL(new window.Blob(['self.onmessage = ' + func.toString()], { type: "text/javascript" }));

This is an issue, as all usages of typeof x in the service worker code will be replaced by _typeof(x) by Babel. In the newly created service worker context, _typeof is undefined, which will break the parsing and therefore jsTree.

Quickfix

The quick fix is to just disable the worker:

$pageTree.jstree({
    core: {
        // ...
        worker: false,
    },
    // ...
});

Summary

This probably isn't a direct issue with jstree, as it does nothing wrong and probably very hard to fix for Babel. So I am not sure whether there is a immediate and obvious fix.

Nevertheless I think this issue might come up for others too, so here is a description + quickfix solution.

@vakata
Owner
vakata commented Jan 12, 2017

Thank you for the contribution - I will close the issue, as there is nothing I can do about it. I will see if I can improve in v.4. Once again - thanks.

@vakata vakata closed this Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment