Open lidangzzz opened 4 years ago
currently, i can't make babel-template being compiled correctly. But if it works, we can write web workers like this.
importScripts("https://unpkg.com/comlink/dist/umd/comlink.js");
importScripts("https://unpkg.com/core/dist/umd/core.js");
const compiler = {
compile(source) {
return core.compile(source)
},
};
Comlink.expose(obj)
you can just use it without installing it and using worker-loader in your webpack
@lidangzzz can you upgrade babel-template to @babel/template, because i can't compile babel-template correctly but @babel/template works well. Upgrading to @babel/template will break current operator-overload.js because
path.node.hasOwnProperty('_fromTemplate')
is always false, so recursion will not stop.
And i found a operator-overload-plugin might help you to rewrite the current code
Hi @promer94 ,
I will try to upgrade babel template later, could you explain a little bit more about what's the compiling error? Also my implementation of operator overload is TOTALLY different from Rob's implementation( https://github.com/rob-blackbourn/babel-operator-overload-plugin ). Here are all scenarios that we need to consider:
Mat_object [op] Mat_object
Mat_object [op] scalar
Mat_object [op] 1D/2D_array_of_number
number [op] Mat_object
1D/2D Array of number [op] Mat_object
Sym_object [op] scalar
scalar [op] Sym_object
Sym_object [op] Sym_object
So when we are trying to implement a Babel plugin, it's NOT an operator overload of ClassFoo [op] ClassFoo. Instead it should always cover all possible combination above.
Here is a reference: https://zhuanlan.zhihu.com/p/159128811
I have made my attempt at https://github.com/promer94/hedgehog-lab-core
install
And use it at my fork