From e1cc1dcb4b9066505385300900ab9c3651a95ef4 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Sun, 16 Nov 2014 20:28:39 +0100 Subject: [PATCH] Introduce --remove-comments (-c) option --- bin/6to5/index.js | 4 +++- lib/6to5/file.js | 3 ++- lib/6to5/generation/generator.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/6to5/index.js b/bin/6to5/index.js index b492dbb1b7..16966f58d0 100755 --- a/bin/6to5/index.js +++ b/bin/6to5/index.js @@ -17,6 +17,7 @@ commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ON commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list); commander.option("-o, --out-file [out]", "Compile all input files into a single file"); commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory"); +commander.option("-c, --remove-comments", "Remove comments from the compiled code", false); commander.on("--help", function(){ var outKeys = function (title, obj) { @@ -89,7 +90,8 @@ exports.opts = { whitelist: commander.whitelist, sourceMap: commander.sourceMaps || commander.sourceMapsInline, runtime: commander.runtime, - modules: commander.modules + modules: commander.modules, + comments: !commander.removeComments }; var fn; diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 35d9fb22ba..c30ea79d41 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -32,7 +32,8 @@ File.normaliseOptions = function (opts) { filename: "unknown", modules: "common", runtime: false, - code: true + code: true, + comments: true }); // normalise windows path separators to unix diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index 4a75e27b77..fa1f38cfbe 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -17,7 +17,7 @@ var _ = require("lodash"); function CodeGenerator(ast, opts, code) { opts = opts || {}; - this.comments = ast.comments || []; + this.comments = opts.comments ? (ast.comments || []) : []; this.tokens = ast.tokens || []; this.format = CodeGenerator.normaliseOptions(opts); this.ast = ast;