Closure compiler is a great tool which can be used to compress or minify JavaScripts. It easily out performs yui library. You can read more about Closure from here.
Recently I was trying to compile a third party JS library specifically swagger-ui.js. When compiling the code it produced humongous amounts of errors. Since I could not correct all of the errors since the outcome is unclear I had to compile the code by ignoring some errors I faced.
This is one error I faced.
ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option. 'dblclick .curl': 'selectText', ^
So in this post I'll explain hoe to ignore theses errors when compiling. In closure you can do this by parsing the --jscomp_off flag. Following is an example for this.
java -jar compiler.jar --jscomp_off=suspiciousCode --js swagger-ui.js --js_output_file swagger-ui2.js
You see "suspiciousCode" parameter I'm parsing, this is a predefined error class thats in closure. Inorder to get a list of error classes you can view the help section as shown below.
java -jar compiler.jar --help
This will give the following list under --jscomp_off
Turn off the named class of warnings.
Options:accessControls, ambiguousFunct
ionDecl, checkEventfulObjectDisposal,
checkRegExp, checkStructDictInheritanc
e, checkTypes, checkVars, conformanceV
iolations, const, constantProperty,
deprecated, deprecatedAnnotations,
duplicateMessage, es3, es5Strict,
externsValidation, fileoverviewTags,
globalThis, inferredConstCheck,
internetExplorerChecks, invalidCasts,
misplacedTypeAnnotation, missingGetCss
Name, missingProperties, missingProvid
e, missingRequire, missingReturn,newCh
eckTypes, nonStandardJsDocs, reportUnk
nownTypes, suspiciousCode, strictModul
eDepCheck, typeInvalidation, undefined
Names, undefinedVars, unknownDefines,
uselessCode, useOfGoogBase, visibility
So what if you need to ignore multiple errors when compiling? This is easy you can parse multiple flags as shown below.
java -jar compiler.jar --jscomp_off=suspiciousCode --jscomp_off=internetExplorerChecks --js swagger-ui.js --js_output_file swagger-ui2.js
In closure you also can define your own error classes and groups. This will allow you to ignore any custom errors that are being generated.
Great read thaankyou
ReplyDelete