implement annotations (#4763)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user