diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 0ba1dbba93..a2d0806595 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -18,7 +18,7 @@ function File(opts) { this.ast = {}; } -File.declarations = ["extends", "class-props", "slice"]; +File.declarations = ["extends", "class-props", "slice", "apply-constructor"]; File.normaliseOptions = function (opts) { opts = _.cloneDeep(opts || {}); @@ -30,7 +30,8 @@ File.normaliseOptions = function (opts) { sourceMap: false, filename: "unknown", modules: "common", - runtime: false + runtime: false, + code: true }); // normalise windows path separators to unix @@ -142,6 +143,14 @@ File.prototype.generate = function () { var opts = this.opts; var ast = this.ast; + if (!opts.code) { + return { + code: "", + map: null, + ast: ast + }; + } + var result = generate(ast, opts, this.code); if (this.shebang) { @@ -153,6 +162,8 @@ File.prototype.generate = function () { result.code += "\n" + util.sourceMapToComment(result.map); } + result.ast = result; + return result; }; diff --git a/lib/6to5/templates/apply-constructor.js b/lib/6to5/templates/apply-constructor.js new file mode 100644 index 0000000000..b02f831251 --- /dev/null +++ b/lib/6to5/templates/apply-constructor.js @@ -0,0 +1,5 @@ +(function (Constructor, args) { + var bindArgs = [null].concat(args); + var Factory = Constructor.bind.apply(Constructor, bindArgs); + return new Factory; +}); diff --git a/lib/6to5/templates/values.js b/lib/6to5/templates/values.js new file mode 100644 index 0000000000..306193c7ef --- /dev/null +++ b/lib/6to5/templates/values.js @@ -0,0 +1,5 @@ +(function (obj) { + var arr = []; + for (var val of obj) arr.push(val); + return arr; +});