add apply-constructor declaration and add support for not returning generated code in opts.code

This commit is contained in:
Sebastian McKenzie
2014-11-12 18:29:03 +11:00
parent a47a7dc347
commit ed7378cc2d
3 changed files with 23 additions and 2 deletions

View File

@@ -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;
};

View File

@@ -0,0 +1,5 @@
(function (Constructor, args) {
var bindArgs = [null].concat(args);
var Factory = Constructor.bind.apply(Constructor, bindArgs);
return new Factory;
});

View File

@@ -0,0 +1,5 @@
(function (obj) {
var arr = [];
for (var val of obj) arr.push(val);
return arr;
});