0

First of all, I know javascript isnt compiled. Uglifyjs acts as a compiler to spot out possible errors...now for my question

I just downloaded/installed uglifyjs https://github.com/mishoo/UglifyJS . I want to to compile my javascript code before minifying it. I have a fle called badjs.js and here it is:

    var a=10  //notice no semicolon
    a = b + 3;   // b is not declared
    alert('the value of a is ' + a);

The first 2 lines of badjs.js should cause uglifyjs to bark at me, but it doesn't. I run this:

  uglifyjs badjs.js

All it does is just output the minified version. How do i tell uglifyjs to notify me of errors? Thanks

9
  • What do you mean by compile the js code? Javascript is only compiled by some engines that execute it e.g., inside the browser, like V8 that is used by Google Chrome. Commented Nov 26, 2012 at 15:25
  • @fegemo Did you read the part about using UglifyJS? I know it doesn't necessarily "compile", but that's not the point... Commented Nov 26, 2012 at 15:27
  • I agree, @lan, but the term makes the question misleading for those who may not know about this. Commented Nov 26, 2012 at 15:30
  • @Ian...i tried this uglifyjs badjs.js --verbose, but got the same result..meaning no warnings about the bad code Commented Nov 26, 2012 at 15:30
  • I\m guessing by compile OP means check for syntax errors etc? Commented Nov 26, 2012 at 15:32

2 Answers 2

1

I know the thread is outdated but still as google returns it I have to mention now we've got a "--lint" option:

uglifyjs main.js -o main.min.js --lint
Sign up to request clarification or add additional context in comments.

1 Comment

@darwin-thanks for answering. I haven't used uglify.js in awhile, but i might in the future
0

It shouldn't "bark" at you. Uglify follows the js specification which says that semicolons are optional at line ends. Uglify will add the semicolon for you when it compresses it:

> uglifyjs --version
uglify-js 2.2.3
> uglifyjs ~/Desktop/test.js -c
var a=10;a=b+3,alert("the value of a is "+a);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.