UNPKG

six

Version:

JavaScript you can bet on.

3 lines 1.41 kB
exports.filter = function anonymous(it) { var out=''; var id = it.id ? it.id.compile() : "_Class"; var dec = it.type === "ClassDeclaration"; if(dec){out+='var '+( id)+' =';}out+='(function(';if(it.superClass){out+='_super';}out+=') {';if(it.superClass){out+='function __ctor() { this.constructor = '+( id)+'; }__ctor.prototype = _super.prototype;'+( id)+'.prototype = new __ctor();'+( id)+'.__super__ = _super.prototype;';}out+='function '+( id)+'(';if(it.constructor){if(it.constructor.value.params && it.constructor.value.params.ast){out+=( it.constructor.value.params.compile() );}out+=')'+( it.constructor.value.body.compile() );}else{out+='){}';}var arr1=it.methods;if(arr1){var method,index=-1,l1=arr1.length-1;while(index<l1){method=arr1[index+=1];var params = method.value.params && method.value.params.ast;if(method.kind === 'set' || method.kind === 'get'){out+='Object.defineProperty('+( id)+'.prototype, "'+( method.key.compile() )+'", {configurable: true,enumerable: true,'+( method.kind )+': function(';if(params){out+=( method.value.params.compile() );}out+=')'+( method.value.body.compile() )+'});';}else{out+=( id)+'.prototype.'+( method.key.compile() )+' = function(';if(params){out+=( method.value.params.compile() );}out+=')'+( method.value.body.compile() )+';';}} } out+='return '+( id )+';})(';if(it.superClass){out+=( it.superClass.compile());}out+=')';if(dec){out+=';';}return out; }