Search code examples
google-closure-compiler

Google closure compiler with ADVANCED_OPTIMIZATIONS giving me empty file


Command i am using is

java -jar closure-compiler-v20181028.jar --compilation_level ADVANCED_OPTIMIZATIONS --js_output_file=out.js input.js

my input.js contains only

function base() {
    var b='xyz';
                if (b.tagName && 0 == b.tagName.search(this.TAGS_)) {
                    if (b.hasAttribute("href") && void 0 !== self.angular) {
                        var f = b.getAttribute("href");
                        if (f.indexOf("{{") >= 0 && f.indexOf("}}") > 0 && !b.hasAttribute("ng-href"))
                            return b.setAttribute("ng-href", f), void b.removeAttribute("href");
                    }
                    for (var a = 0; a < this.URL_ATTRIBUTES_.length; ++a)
                        if (b.hasAttribute(this.URL_ATTRIBUTES_[a]))
                            return this.updateAttributes_(b, a);
                }
            }

i tried with gradle script, also same result .Any help would be appreciated.


Solution

  • From the documentation:

    "...code compiled with ADVANCED_OPTIMIZATIONS may not work with uncompiled code unless you take special steps to ensure interoperability. If you do not flag external functions and properties referenced in your code, Closure Compiler will inappropriately rename references in your code, causing mismatches between the names in your code and in the external code."

    By "flag" here, they mean "export". For more information see this documentation on the different compilations levels:

    https://developers.google.com/closure/compiler/docs/compilation_levels

    This blog post:

    http://closuretools.blogspot.com/2012/09/which-compilation-level-is-right-for-me.html

    And the documentation on exports here:

    https://developers.google.com/closure/compiler/docs/api-tutorial3