add apply-constructor declaration and add support for not returning generated code in opts.code
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
5
lib/6to5/templates/apply-constructor.js
Normal file
5
lib/6to5/templates/apply-constructor.js
Normal file
@@ -0,0 +1,5 @@
|
||||
(function (Constructor, args) {
|
||||
var bindArgs = [null].concat(args);
|
||||
var Factory = Constructor.bind.apply(Constructor, bindArgs);
|
||||
return new Factory;
|
||||
});
|
||||
5
lib/6to5/templates/values.js
Normal file
5
lib/6to5/templates/values.js
Normal file
@@ -0,0 +1,5 @@
|
||||
(function (obj) {
|
||||
var arr = [];
|
||||
for (var val of obj) arr.push(val);
|
||||
return arr;
|
||||
});
|
||||
Reference in New Issue
Block a user