diff --git a/bin/6to5/index.js b/bin/6to5/index.js index 16966f58d0..a76af2a6fd 100755 --- a/bin/6to5/index.js +++ b/bin/6to5/index.js @@ -89,9 +89,9 @@ exports.opts = { blacklist: commander.blacklist, whitelist: commander.whitelist, sourceMap: commander.sourceMaps || commander.sourceMapsInline, + comments: !commander.removeComments, runtime: commander.runtime, - modules: commander.modules, - comments: !commander.removeComments + modules: commander.modules }; var fn; diff --git a/doc/usage.md b/doc/usage.md index d784703123..c27b25e5a2 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -124,7 +124,11 @@ to5.transformFile("filename.js", options, function (err, result) { // Optionally replace all 6to5 helper declarations with a referenece to this // variable. If set to `true` then the default namespace is used "to5Runtime". // Default: false - runtime: true + runtime: true, + + // Output comments in generated output + // Default: true + comments: false } ``` diff --git a/lib/6to5/file.js b/lib/6to5/file.js index c30ea79d41..d8ecb685bf 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -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 diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index a625fafe92..4db00aecf6 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -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)); }