gulpgoogle-closure-compilergoogle-closure

Remove debugger keyword during compilation in google closure


UPDATE: The JS version of closure-compiler is no longer supported or maintained. https://github.com/google/closure-compiler-npm/blob/master/packages/google-closure-compiler-js/readme.md


Im trying to find if there is a way to remove the "debugger" keyword during compilation process, im using the javascript version google-closure-compiler with gulp.

Looking through the documentation it is clear we can set the flag to stop/show error messages during compilation by doing the following.

https://github.com/google/closure-compiler/wiki/Flags-and-Options

--jscomp_off

translating this to gulp, it is:

const googleClosureOptions = {
  ...
  jscomp_error:"checkDebuggerStatement"
}

however this works on stopping the compilation by throwing error or to show a warning.

zyxcdafg.js:1444: ERROR - [JSC_DEBUGGER_STATEMENT_PRESENT] Using the debugger statement can halt your application if the user has a JavaScript debugger running.
                    debugger;
                    ^^^^^^^^^

but what I am trying to achieve is to remove the debugger keyword. Is this possible to achieve using googleclosure. I can not find any flags or options relating to this.


UPDATE: The JS version of closure-compiler is no longer supported or maintained. https://github.com/google/closure-compiler-npm/blob/master/packages/google-closure-compiler-js/readme.md


Solution

  • No I don't think so. I'd suggest you use something else to do it. Like sed:

    find dist -name "*.js" -exec sed -i 's/\sdebugger;//' {} +
    

    Something like that will find files in your dist folder that end with .js and then exec-ute sed to replace all instances of debugger; with nothing.

    You could add that to a script that calls your Closure Compiler build.