Jonathan Miles, Freelance Web Designer

Debugger statements make YUI Compressor error

YUI Compressor 2.4.2 gave me this error when I tried to minify a JavaScript file:

1
[java] [ERROR] 4447:21:identifier is a reserved word

Line number 4447 is a code block like this:

1
2
if (debugging)
    debugger;

The problem is the debugger statement – I’m not sure why because it isn’t being used as the name for a variable like the error seems to imply (reserved words, like debugger, have special meanings and so can never be used as identifiers).

Removing the debugger statement would avoid this error but the statement’s there for a reason, so that’s not an option in this case.

The trick is to hide debugger from YUI Compressor:

1
2
if (debugging)
    eval("debugger");

Now all YUI Compressor sees is an innocent eval statement.

Comments

All comments are subject to the comments policy.

Leave a Reply