diff options
Diffstat (limited to 'lib/output.js')
-rw-r--r-- | lib/output.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/output.js b/lib/output.js index ff05356e..fc71a62b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -52,6 +52,7 @@ function OutputStream(options) { var readonly = !options; options = defaults(options, { + annotations : false, ascii_only : false, beautify : false, braces : false, @@ -500,12 +501,14 @@ function OutputStream(options) { space(); } } + var value = c.value.replace(/[@#]__PURE__/g, " "); + if (/^\s*$/.test(value)) return; if (/comment[134]/.test(c.type)) { - print("//" + c.value.replace(/[@#]__PURE__/g, " ") + "\n"); + print("//" + value + "\n"); indent(); last_nlb = true; } else if (c.type == "comment2") { - print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/"); + print("/*" + value + "*/"); last_nlb = false; } }); @@ -558,11 +561,13 @@ function OutputStream(options) { } else if (i > 0 || !tail) { space(); } + var value = c.value.replace(/[@#]__PURE__/g, " "); + if (/^\s*$/.test(value)) return; if (/comment[134]/.test(c.type)) { - print("//" + c.value.replace(/[@#]__PURE__/g, " ")); + print("//" + value); need_newline_indented = true; } else if (c.type == "comment2") { - print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/"); + print("/*" + value + "*/"); need_space = true; } }); @@ -1436,6 +1441,17 @@ function OutputStream(options) { }); /* -----[ other expressions ]----- */ + function print_annotation(self, output) { + if (!output.option("annotations")) return; + if (!self.pure) return; + var level = 0, parent = self, node; + do { + node = parent; + parent = output.parent(level++); + if (parent instanceof AST_Call && parent.expression === node) return; + } while (parent instanceof AST_PropAccess && parent.expression === node); + output.print("/*" + self.pure + "*/"); + } function print_call_args(self, output) { if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) { output.add_mapping(self.start); @@ -1448,11 +1464,14 @@ function OutputStream(options) { }); } DEFPRINT(AST_Call, function(output) { - this.expression.print(output); - print_call_args(this, output); + var self = this; + print_annotation(self, output); + self.expression.print(output); + print_call_args(self, output); }); DEFPRINT(AST_New, function(output) { var self = this; + print_annotation(self, output); output.print("new"); output.space(); self.expression.print(output); |