Can I compile SJCL library with Google closure compiler?

China☆狼群 提交于 2020-06-29 03:20:08

问题


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.

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).

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?

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.

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. 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"/>


回答1:


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.

I fixed it by adding --hide_warnings_for='sjcl.js'

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



来源:https://stackoverflow.com/questions/62464109/can-i-compile-sjcl-library-with-google-closure-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!