我可以使用Google Closure编译器编译SJCL库吗? [英] Can I compile SJCL library with Google closure compiler?

查看:113
本文介绍了我可以使用Google Closure编译器编译SJCL库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Closure Compiler v20181210进行编译和精简的普通javascript项目.我想在该项目中使用SJCL进行加密.

I have a vanilla javascript project that is compiled and minified using Closure Compiler v20181210. I want to use SJCL in that project for crypto.

我将此文件复制到我自己的项目中,并使用该库编写了代码.但是,当我尝试编译它时,Closure Compiler从库中抛出了一系列错误(粘贴在下面).

I copied this file into my own project and wrote code using the library. But when I try to compile it, Closure Compiler throws a bunch of errors from the library (pasted below).

在SJCL网站上,该文件表示使用Google Closure Compressor压缩了文件.所以我想它应该与Closure兼容?为什么不编译呢?

On the SJCL website, it says that the file is compressed using Google Closure Compressor. So I imagine it should be compatible with Closure? Why is it not compiling then?

我还读了一些关于externs的文章.但是我希望所有代码都在一个缩小的文件中.使用externs,看来我需要SJCL的另一个导入.

Also, I read about externs. But I want all the code to be in a single minified file. With externs, it looks like I would need another import for SJCL.

一些Closure编译器错误:

Some of the Closure Compiler Errors:

ERROR - cannot instantiate non-constructor
     [java] sjcl.hash.sha256=function(a){this._key[0]||this._precompute();a?(this._h=a._h.slice(0),this._buffer=a._buffer.slice(0),this._length=a._length):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()};


ERROR - Suspicious code. The result of the 'getprop' operator is not being used.
     [java]     (p^l))+d[b];q=l;l=p;p=h;h=n+g|0;n=k;k=f;f=e;e=g+(f&k^n&(f^k))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0}c[0]=c[0]+e|0;c[1]=c[1]+f|0;c[2]=c[2]+k|0;c[3]=c[3]+n|0;c[4]=c[4]+h|0;c[5]=c[5]+p|0;c[6]=c[6]+l|0;c[7]=c[7]+q|0}};"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl});


ERROR - actual parameter 3 of AnyStorageProvider.prototype.setItem does not match formal parameter
     [java] found   : string
     [java] required: (number|undefined)
     [java]     toucan.storage.Any.setItem(LOGIN_STATE_CACHE_KEY, loginState, 'session');

我正在使用所有这些args运行Closure编译器.当我删除它们时,项目将编译.但是我不确定是否可以安全地删除这些文件?

I am running Closure compiler with all these args. When I remove them, the project compiles. But I am not sure if its safe to remove these?

<arg line="--jscomp_error accessControls --jscomp_error ambiguousFunctionDecl --jscomp_error checkRegExp --jscomp_error checkTypes --jscomp_error checkVars --jscomp_error const --jscomp_error constantProperty --jscomp_error duplicateMessage --jscomp_error externsValidation --jscomp_error fileoverviewTags --jscomp_error globalThis --jscomp_error internetExplorerChecks --jscomp_error invalidCasts --jscomp_error missingProperties --jscomp_error nonStandardJsDocs --jscomp_error strictModuleDepCheck --jscomp_error typeInvalidation --jscomp_error undefinedNames --jscomp_error undefinedVars --jscomp_error unknownDefines --jscomp_error uselessCode --jscomp_error visibility"/>

推荐答案

由于我为自己的项目设置了jscomp_error标志,因此Closure编译器向SJCL抛出错误.没有这些,sjcl.js可以很好地编译.

Closure Compiler was throwing errors for SJCL because of the jscomp_error flags I had on for my own project. Without these, sjcl.js compiles fine.

我通过添加--hide_warnings_for='sjcl.js'

因此,项目的其余部分仍然使用这些标志,但是sjcl可以很好地编译.

So the rest of the project still uses those flags but sjcl compiles fine.

这篇关于我可以使用Google Closure编译器编译SJCL库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆