Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython

ClosureCompiler is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Failed View build log
Windows (64-bit)
0.1 Failed View build log
Mac OS X (10.5+)
0.1 Failed View build log
Linux (32-bit)
0.1 Failed View build log
Linux (64-bit)
0.1 Failed View build log
 
Links
Author
License
MIT
Dependencies
Lastest release
version 0.1 on Jan 5th, 2011

SYNONPSIS

closurecompiler [options] <jsfile>

DESCRIPTION

This man page is just a copy&paste of the Google Closure Compiler Service API Reference. Because all the options of closurecompiler is highly (really, really high) inspired of this apis, I rewrote the page in this man page.

The closurecompiler use the `online compiler`_, for an offline version use the `Closure Compiler Application`_ from Google. If the server fails to process your request, you will receive a server error message and the application will exit with an error code. These messages are described in the ERRORS section.

OPTIONS

Required Parameters

--jscode <code>, -j <code> The code option must be a string containing JavaScript, such as:

System Message: WARNING/2 (<string>, line 42)

Literal block expected; none found.

alert('hello').

--codeurl <url>, -u <url> The --codeurl option must contain the URL of a JavaScript file. You can include multiple codeurl option to specify multiple input files.

You must include at least one of --jscode or --codeurl options and you can include both multiples times.

--level <level>, -l <level> The degree of compression and optimization to apply to your JavaScript. There are three possible compilation levels:

whitespace Just removes whitespace and comments from your JavaScript.

simple Performs compression and optimization that does not interfere with the interaction between the compiled JavaScript and other JavaScript. This level renames only local variables. See `Communicating with the API`_ for more information about compiling with simple optimizations.

advanced Achieves the highest level of compression by renaming symbols in your JavaScript. When using advanced optimizations compilation you must perform extra steps to preserve references to external symbols. See `Advanced Compilation and Externs`_ for more information about advanced optimizations.

Defaults to a value of simple.

--format <format>, -f <format> The format for the Closure Compiler service's output. There are three possible output formats:

xml The xml output format wraps the requested information in valid XML.

The XML output looks like this:

<compilationResult>
<compiledCode>var a="hello";alert(a);</compiledCode>
<statistics>
<originalSize>98</originalSize>
<compressedSize>35</compressedSize>
<compileTime>0</compileTime>
</statistics>
</compilationResult>

The compiledCode section contains the compressed JavaScript that the Closure Compiler service produced. This section only appears if you use the --info option with a value of compiled_code. Similarly, the statistics section only appears if you use --info option with a value of statistics.

If you use --info option with a value of warnings and the compiler produces a warning, the output will include a warnings tag:

<compilationResult>

System Message: ERROR/3 (<string>, line 101)

Inconsistent literal block quoting.

... <warnings> <warning type="JSC_NO_SIDE_EFFECT" file="default.js" lineno="12" charno="3" line="delete 1;">warning 1</warning> <warning type="JSC_UNUSED_VAR" file="default.js" lineno="13" charno="13" line="delete 1;">warning 2 </warning> </warnings> ... </compilationResult>

If you use --info with a value of errors, the Closure Compiler service will include an errors tag if your code contains a syntax error or other problem that prevents compilation. The errors tag looks like this:

<compilationResult>

System Message: ERROR/3 (<string>, line 119)

Inconsistent literal block quoting.

... <errors> <error type="JSC_NO_SIDE_EFFECT" file="default.js" lineno="12" charno="3" line="var x=-'hello';">error 1 </error> <error type="JSC_UNUSED_VAR" file="default.js" lineno="13" charno="13" line="var x=-'hello'">error 2 </error> </errors> ... </compilationResult>

The file, line, and col attributes of the error and warning tags indicate where the Closure Compiler service encountered the error.

If the Closure Compiler service encounters an error that prevents the processing of your input, the output looks like this:

<compilationResult>
<serverErrors>
<error code="1">Over quota</error>
</serverErrors>
</compilationResult>

json The json output format wraps the requested information in a JavaScript Object Notation (JSON) string. Evaluation of this string as JavaScript returns a JavaScript Object.

The JSON output looks like this:

{

System Message: ERROR/3 (<string>, line 151)

Inconsistent literal block quoting.

"compiledCode":/* raw code here */, {"errors": [ {"charno":4321, "error":"ERROR: You failed.", "lineno":1234, "file":"default.js", "type":"ERROR_TYPE", "line":"var x=-'hello';"}], "warnings": [ {"charno":4321, "lineno":1234, "file":"default.js", "type":"ERROR_TYPE", "warning":"Warning: You did something wrong!", "line":"delete 1;"}] "serverErrors":[ {"code":123,"error":"Over quota"} ], "statistics":{ "originalSize":10, "compressedSize":3000 "compileTime":10 } }

System Message: WARNING/2 (<string>, line 151); backlink

Inline emphasis start-string without end-string.

The JSON format is similar to the XML format: every tag in the XML output corresponds to a property of the same name in the JSON object

text The text output format returns raw text without tags or JSON brackets. If the --info includes compiled_code, the text contains JavaScript. If the --info includes warnings, the text contains warning messages. If the --info includes statistics, the text contains statistics.

The format option defaults to a value of text.

--info <type>, -i <type> Indicates the kind of output you want from the compiler. There are four possible kinds of output:

compiled_code A compressed and optimized version of your input JavaScript.

warnings Messages that indicate possible bugs in your JavaScript.

errors Messages that indicate syntax errors or other errors in your JavaScript.

statistics Information about the degree of compression that the Closure Compiler achieves. For xml output, the Closure Compiler service returns statistics in the following format:

<compilationResult>

System Message: ERROR/3 (<string>, line 207)

Inconsistent literal block quoting.

... <statistics> <firstStatisticName>24</firstStatisticName> <secondStatisticName>15</secondStatisticName> </statistics> </compilationResult>

Optional Parameters

--externs <code>, -x <code> The value of this option must be JavaScript code that declares function names or other symbols. Use --externs to preserve symbols that are defined outside of the code you are compiling. The --externs option only has an effect if you are using a --level of advanced. See `Advanced Compilation`_ for more information.

--externurl <url>, -e <url> The value of this option must be the URL of a file containing JavaScript that declares function names or other symbols. The symbols declared in this file are preserved in exactly the same way as symbols listed directly in the --externs option. The --externurl option only has an effect if you are using a --level of advanced. See `Advanced Compilation`_ for more information.

You can specify this option multiple times if you have multiple externs files.

--nodefault By default, the Closure Compiler service uses a standard externs file that declares common externally defined symbols like document and all its methods. If you do NOT want to use these common externs, use this option.

See `Advanced Compilation and Externs`_ for more information about externs.

--filename <name>, -f <name> If present, the Closure Compiler service caches the compiled code for one hour and makes it available through a special URL. During this hour you can test the compiled code by pointing your browser to this URL. The URL has this form:

System Message: WARNING/2 (<string>, line 248)

Literal block expected; none found.

http://closure-compiler.appspot.com/code/[sesssion]/[name]

--formatting If present, this option must have a value of pretty_print or print_input_delimiter. You can provide multiple --formatting options in the. The pretty_print and print_input_delimiter values affect different aspects of the formatting, so you can include both without affecting the way either works.

pretty_print Te Closure Compiler service adds line breaks and indentation to its output code to make the code easier for humans to read. For example, output with pretty_print turned on looks like this:

System Message: WARNING/2 (<string>, line 262)

Literal block expected; none found.

function hello(a) { alert("Hello, " + a) } hello("New user");

Output with pretty_print turned off looks like this:

System Message: WARNING/2 (<string>, line 269)

Literal block expected; none found.

function hello(a){alert("Hello, "+a)}hello("New user");

print_input_delimiter The Closure Compiler service adds a separator between the compiler outputs for each file you compile. For example, if you compile two files together, the output looks like this:

// Input 0

System Message: ERROR/3 (<string>, line 277)

Inconsistent literal block quoting.

alert("hi"); // Input 1 alert("bye");

The compiler inserts the // Input X delimiters to mark the boundaries between files. Note that the delimiters are comments, so they do not interfere with the execution of the JavaScript.

Each JavaScript file you provide with a --codeurl parameter has a corresponding delimited section in the compiler output. The Closure Compiler service treats all input from --jscode options as if it comes from a single file.

Input delimiters have many potential uses, including helping you to figure out which inputs are contributing the most to the size of the compiled code.

--closure If you use this option the compiler looks for goog.require() statements in the source code and supplies the Closure Library code requested by any such statements. It also performs optimizations designed specifically for Closure Library code. See the `Closure Library documentation`_ for more information about the Closure Library. See `Finding Your Way around the Closure Library`_ for more information about the goog.require() function.

Defaults to false.

--warning <level>, -w <level> Indicates the amount of information you want from the compiler about possible problems in your code. The --warning parameter only has an effect when an --info parameter with a value of warnings is also supplied. There are three possible warning levels:

QUIET Outputs only syntax error messages and warnings generated by the optimization passes included in the --level for the current compiler run.

DEFAULT In addition to syntax errors and warnings generated by optimization passes, outputs warnings generated by selected code-checking passes.

VERBOSE In addition to syntax errors and warnings generated by optimization passes, outputs warnings generated by all code-checking passes.

Defaults to a value of DEFAULT.

ERRORS

If the server fails to process your request, you will receive one of the server error messages listed in the table below. Note that these server error messages are different from compiler errors and warnings. Compiler errors and warnings indicate that Closure Compiler found a problem in your JavaScript code. Server error messages indicate that the compiler is not able to process your code at all because of an error in your request.

2 Unknown output mode. The value of the output_format parameter is something other than xml, json, or text.

4 Unknown compression level. The value of the --level parameter is something other than WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, or ADVANCED_OPTIMIZATIONS.

9 File too large. The total amount of code from all --codeurl files, all --externurl files, all --jscode code and all --externs code exceeds 500k.

10 Cannot retrieve content from URL. An error occurred when the Closure Compiler service tried to retrieve either a JavaScript file indicated in the --codeurl parameter or an externs file indicated in the --externurl parameter. Check that the URL is correct and that the permissions of the file allow it to be viewed.

12 URL is not formed properly. The value of either the --codeurl parameter or the --externurl parameter is not a well-formed URL.

13 No output information to produce, yet compilation was requested. No --info parameter has been specified.

14 Unknown --info value. The value of an --info parameter is something other than compiled_code, warnings, or statistics.

16 Unknown warning level. The value of the --warning parameter is something other than QUIET, DEFAULT, or VERBOSE.

17 Unknown formatting option. The value of the --formatting parameter is something other than pretty_print or print_input_delimiter.

18 Unknown parameter in HTTP request. The HTTP request contains a parameter other than one of the ones listed in this document.

19 Illegal value for --filename. The output file name contains a character a number, letter, dot, underscore, or dash, or it contains two consecutive dots (..)

22 Too many compiles performed recently. Try again later. You have submitted too many compiles from your machine. After an hour, you should be able to perform compiles again.

23 Compiler exception (with backtrace). The compiler crashed. The text of the error will contain information to help Google debug the problem.

24 Unsupported input resource type. The resource type is not http and so the input file will not be retrieved.

System Message: WARNING/2 (<string>, line 394)

Explicit markup ends without a blank line; unexpected unindent.

http://code.google.com/intl/it/closure/compiler/docs/api-ref.html .. _online compiler: http://closure-compiler.appspot.com/compile .. _Closure Compiler Application: http://code.google.com/intl/it/closure/compiler/docs/gettingstarted_app.html .. _Communicating with the API: http://code.google.com/intl/it/closure/compiler/docs/api-tutorial2.html .. _Advanced Compilation and Externs: http://code.google.com/intl/it/closure/compiler/docs/api-tutorial3.html .. _Advanced Compilation: `Advanced Compilation and Externs`_ .. _Closure Library documentation: http://code.google.com/closure/library/ .. _Finding Your Way around the Closure Library: http://code.google.com/closure/library/docs/introduction.html#deps

System Message: WARNING/2 (<string>, line 408)

Explicit markup ends without a blank line; unexpected unindent.

vi: set ft=rst tw=80 :

Docutils System Messages

System Message: ERROR/3 (<string>, line 28); backlink

Unknown target name: "online compiler".

System Message: ERROR/3 (<string>, line 28); backlink

Unknown target name: "closure compiler application".

System Message: ERROR/3 (<string>, line 58); backlink

Unknown target name: "communicating with the api".

System Message: ERROR/3 (<string>, line 64); backlink

Unknown target name: "advanced compilation and externs".

System Message: ERROR/3 (<string>, line 217); backlink

Unknown target name: "advanced compilation".

System Message: ERROR/3 (<string>, line 224); backlink

Unknown target name: "advanced compilation".

System Message: ERROR/3 (<string>, line 240); backlink

Unknown target name: "advanced compilation and externs".

System Message: ERROR/3 (<string>, line 294); backlink

Unknown target name: "closure library documentation".

System Message: ERROR/3 (<string>, line 294); backlink

Unknown target name: "finding your way around the closure library".

System Message: ERROR/3 (<string>, line 394); backlink

Unknown target name: "advanced compilation and externs".

Subscribe to package updates

Last updated Jan 5th, 2011

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.