简体   繁体   English

我可以使用 Google 闭包编译器编译 SJCL 库吗?

[英]Can I compile SJCL library with Google closure compiler?

I have a vanilla javascript project that is compiled and minified using Closure Compiler v20181210.我有一个普通的 javascript 项目,它是使用 Closure Compiler v20181210 编译和缩小的。 I want to use SJCL in that project for crypto.我想在该项目中使用 SJCL 进行加密。

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).但是当我尝试编译它时,Closure Compiler 从库中抛出一堆错误(粘贴在下面)。

On the SJCL website, it says that the file is compressed using Google Closure Compressor.在 SJCL 网站上,它说该文件是使用 Google Closure Compressor 压缩的。 So I imagine it should be compatible with Closure?所以我想它应该与 Closure 兼容? Why is it not compiling then?那为什么不编译呢?

Also, I read about externs.另外,我读到了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.使用 externs,看来我需要另一个 SJCL 导入。

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');

EDIT: I am running Closure compiler with all these args.编辑:我正在使用所有这些参数运行 Closure 编译器。 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"/>

Closure Compiler was throwing errors for SJCL because of the jscomp_error flags I had on for my own project.由于我为自己的项目使用的jscomp_error标志,Closure Compiler 为 SJCL 抛出错误。 Without these, sjcl.js compiles fine.没有这些,sjcl.js 编译得很好。

I fixed it by adding --hide_warnings_for='sjcl.js'我通过添加--hide_warnings_for='sjcl.js'来修复它

So the rest of the project still uses those flags but sjcl compiles fine.所以项目的 rest 仍然使用这些标志,但 sjcl 编译得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM