diff --git a/bin/6to5/index.js b/bin/6to5/index.js index 49430d0e82..09d7925e43 100755 --- a/bin/6to5/index.js +++ b/bin/6to5/index.js @@ -25,6 +25,7 @@ commander.option("-I, --indent [width]", "Indent width [2]", 2); commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0 commander.option("-m, --module-ids", "Insert module id in modules", false); commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code"); +commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false); commander.on("--help", function(){ var outKeys = function (title, obj) { @@ -100,18 +101,19 @@ if (errors.length) { // exports.opts = { - sourceMapName: commander.outFile, - experimental: commander.experimental, - playground: commander.playground, - moduleIds: commander.amdModuleIds || commander.moduleIds, - blacklist: commander.blacklist, - whitelist: commander.whitelist, - sourceMap: commander.sourceMaps || commander.sourceMapsInline, - optional: commander.optional, - comments: !commander.removeComments, - runtime: commander.runtime, - modules: commander.modules, - reactCompat: commander.reactCompat, + includeRegenerator: commander.includeRegenerator, + sourceMapName: commander.outFile, + experimental: commander.experimental, + reactCompat: commander.reactCompat, + playground: commander.playground, + moduleIds: commander.amdModuleIds || commander.moduleIds, + blacklist: commander.blacklist, + whitelist: commander.whitelist, + sourceMap: commander.sourceMaps || commander.sourceMapsInline, + optional: commander.optional, + comments: !commander.removeComments, + runtime: commander.runtime, + modules: commander.modules, format: { indent: { style: util.repeat(parseInt(commander.indent)) diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 05eab212f5..17d29b3e99 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -48,21 +48,22 @@ File.normaliseOptions = function (opts) { opts = _.cloneDeep(opts || {}); _.defaults(opts, { - experimental: false, - reactCompat: false, - playground: false, - whitespace: true, - moduleIds: opts.amdModuleIds || false, - blacklist: [], - whitelist: [], - sourceMap: false, - optional: [], - comments: true, - filename: "unknown", - modules: "common", - runtime: false, - code: true, - ast: true + includeRegenerator: false, + experimental: false, + reactCompat: false, + playground: false, + whitespace: true, + moduleIds: opts.amdModuleIds || false, + blacklist: [], + whitelist: [], + sourceMap: false, + optional: [], + comments: true, + filename: "unknown", + modules: "common", + runtime: false, + code: true, + ast: true }); // normalise windows path separators to unix diff --git a/lib/6to5/transformation/transformers/es6-generators.js b/lib/6to5/transformation/transformers/es6-generators.js index c7dc28d55e..caeeec5ef6 100644 --- a/lib/6to5/transformation/transformers/es6-generators.js +++ b/lib/6to5/transformation/transformers/es6-generators.js @@ -1,3 +1,9 @@ +var regenerator = require("regenerator"); + exports.ast = { - before: require("regenerator").transform + before: function (ast, file) { + regenerator.transform(ast, { + includeRuntime: file.opts.includeRegenerator && "if used" + }); + } };