Ugly hack to print comments before return/throw statements
authorMihai Bazon <mihai@bazon.net>
Tue, 5 Feb 2013 17:10:33 +0000 (19:10 +0200)
committerMihai Bazon <mihai@bazon.net>
Tue, 5 Feb 2013 17:11:39 +0000 (19:11 +0200)
Close #112

lib/output.js

index cafb28f..5e66820 100644 (file)
@@ -375,6 +375,16 @@ function OutputStream(options) {
             if (start && !start._comments_dumped) {
                 start._comments_dumped = true;
                 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);
+                    self.value.start.comments_before = [];
+                }
+
                 if (c.test) {
                     comments = comments.filter(function(comment){
                         return c.test(comment.value);