我在我的 React 应用程序中使用第 3 方库“FoamTree”来制作树可视化。当我在我的组件中导入它的文件 ‘carrotsearch.foamtree.js’ 时,它在多行中给我这个错误:
Expected an assignment or function call and instead saw an expression no-unused-expressions
它在普通 Javascript 中运行良好。它仅在将其导入反应时才给出错误该文件中有很多行给我这个错误。其中我分享的很少:
this.j = function (m, k) {
var f = a[m];
f || (f = [], a[m] = f);
f.push(k);
};
function m(a) {
var d = a.O,
c = a.Sb[0].length - 1;
a.Ib[c] && (d.setLineDash(a.Ib[c]), d.Uj = a.Ld[c]);
d.miterLimit = a.Qd[c];
d.lineWidth = a.Md[c];
d.shadowBlur = a.ie[c];
d.shadowOffsetX = a.je[c];
d.shadowOffsetY = a.ke[c];
d.font = a.Nc[c].replace("#SIZE#", a.hc[c].toString());
}
for (e = 0; e < g; e++) {
h = c[e].kd, m[h.index] = !0, 0 > r * (h.x - k.x) + s * (h.y - k.y) + l * (h.z - k.z) && a.d(b, h);
}
this.kc = function (a, b) {
D.V(b) || (n[a] = b, m(a));
return n[a];
};
编辑:当我更改此块时:
this.kc = function (a, b) {
D.V(b) || (n[a] = b, m(a));
return n[a];
};
对此:
this.kc = function (a, b) {
if( D.V(b) || (n[a] = b, m(a)) ){
return n[a];
}
};
然后错误消失了
原文由 Ankit Kaushal 发布,翻译遵循 CC BY-SA 4.0 许可协议
通过将其添加到文件顶部解决了这个问题: