Fix codegen for when comments_before is undefined.
authorMihai Bazon <mihai@bazon.net>
Mon, 28 Oct 2013 07:39:29 +0000 (09:39 +0200)
committerMihai Bazon <mihai@bazon.net>
Mon, 28 Oct 2013 07:39:29 +0000 (09:39 +0200)
Fix #333

bin/uglifyjs
lib/output.js

index 90b71a2..b103cc3 100755 (executable)
@@ -251,7 +251,6 @@ async.eachLimit(files, 1, function (file, cb) {
             else if (ARGS.acorn) {
                 TOPLEVEL = acorn.parse(code, {
                     locations     : true,
-                    trackComments : true,
                     sourceFile    : file,
                     program       : TOPLEVEL
                 });
index e7f3f4d..7eb685a 100644 (file)
@@ -378,14 +378,15 @@ function OutputStream(options) {
             var start = self.start;
             if (start && !start._comments_dumped) {
                 start._comments_dumped = true;
-                var comments = start.comments_before;
+                var comments = start.comments_before || [];
 
                 // XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
                 //      if this node is `return` or `throw`, we cannot allow comments before
                 //      the returned or thrown value.
-                if (self instanceof AST_Exit &&
-                    self.value && self.value.start.comments_before.length > 0) {
-                    comments = (comments || []).concat(self.value.start.comments_before);
+                if (self instanceof AST_Exit && self.value
+                    && self.value.start.comments_before
+                    && self.value.start.comments_before.length > 0) {
+                    comments = comments.concat(self.value.start.comments_before);
                     self.value.start.comments_before = [];
                 }