fix up comments option

This commit is contained in:
Sebastian McKenzie
2014-11-17 11:59:52 +11:00
parent 885d65f9de
commit 8a9a205122
4 changed files with 16 additions and 18 deletions

View File

@@ -29,11 +29,11 @@ File.normaliseOptions = function (opts) {
blacklist: [],
whitelist: [],
sourceMap: false,
comments: true,
filename: "unknown",
modules: "common",
runtime: false,
code: true,
comments: true
code: true
});
// normalise windows path separators to unix

View File

@@ -17,11 +17,10 @@ var _ = require("lodash");
function CodeGenerator(ast, opts, code) {
opts = opts || {};
this.keepComments = opts.comments !== false;
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
this.format = CodeGenerator.normaliseOptions(opts);
this.ast = ast;
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
this.format = CodeGenerator.normaliseOptions(opts);
this.ast = ast;
this.whitespace = new Whitespace(this.tokens, this.comments);
this.position = new Position;
@@ -41,7 +40,7 @@ CodeGenerator.normaliseOptions = function (opts) {
opts = _.merge({
parentheses: true,
semicolons: true,
comments: true,
comments: opts.comments,
compact: false,
indent: {
adjustMultilineComment: true,
@@ -142,10 +141,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
};
if (this[node.type]) {
if(this.keepComments) {
this.printLeadingComments(node, parent);
}
this.printLeadingComments(node, parent);
newline(true);
@@ -166,9 +162,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
newline(false);
if(this.keepComments) {
this.printTrailingComments(node, parent);
}
this.printTrailingComments(node, parent);
} else {
throw new ReferenceError("unknown node " + node.type + " " + JSON.stringify(node));
}