Skip to content

Instantly share code, notes, and snippets.

@termi
Last active August 29, 2015 14:05
Show Gist options
  • Save termi/66f16011c1a331faabc2 to your computer and use it in GitHub Desktop.
Save termi/66f16011c1a331faabc2 to your computer and use it in GitHub Desktop.
Generator comprehation transpiling test
var S_ITER$0 = typeof Symbol !== 'undefined' && Symbol && Symbol.iterator || '@@iterator';
var S_MARK$0 = typeof Symbol !== 'undefined' && Symbol && Symbol["__setObjectSetter__"];
function GET_ITER$0(v) {
if( v ) {
if( Array.isArray(v) )return 0;
var f;
if( S_MARK$0 )S_MARK$0(v);
if( typeof v === 'object' && typeof (f = v[S_ITER$0]) === 'function' ) {
if( S_MARK$0 )S_MARK$0(void 0);
return f.call(v);
}
if( S_MARK$0 )S_MARK$0(void 0);
if( (v + '') === '[object Generator]' )return v;
}
throw new Error(v + ' is not iterable')
};
var $D$6;
var $D$7;
var $D$8;
var arr1 = [1, 2, 3], arr2 = [
{a: 'a'},
{a: 'b'},
{a: 'c'}
];
var gen = (function() {
var S_STAG$0 = typeof Symbol !== 'undefined' && Symbol && Symbol["toStringTag"] || '@@toStringTag';
var Generator$0 = function Generator() {
if( !(this instanceof Generator$0) )throw new TypeError('incompatible' + this);
this["__next__"] = arguments[0];
this["__throw__"] = arguments[1];
};
Generator$0.prototype = {constructor: Generator$0, "next": function(val) {
if( !(this instanceof Generator$0) )throw new TypeError('next method called on incompatible ' + this);
if( this["__next__"] ) {
try {
return this["__next__"](val);
} catch( e ) {
if( this["__throw__"] )return this["__throw__"](e);
else throw e;
}
}
else return {"value": void 0, "done": true};
}, "throw": function(e) {
if( !(this instanceof Generator$0) )throw new TypeError('throw method called on incompatible ' + this);
if( this && this["__throw__"] )return this["__throw__"](e);
else throw e
}, "toString": function() {
return '[object Generator]'
}};
if( S_MARK$0 )S_MARK$0(Generator$0.prototype);
Generator$0.prototype[S_STAG$0] = 'Generator';
Generator$0.prototype[S_ITER$0] = function() {
return this
};
if( S_MARK$0 )S_MARK$0(void 0);
var $D$0;
var $D$1;
var $D$2;
var $D$3;
var $D$4;
var $D$5;
var x;
var y;
var done$0 = false;
var init$0 = false;
var init$1 = false;
var state$0 = 1, next$0 = false;
return new Generator$0(function next(throw_error$0, throw$0) {
if( throw$0 === true ) {
done$0 = true;
}
if( done$0 === false ) {
while( true ) {
next$0 = false;
switch( state$0 ) {
case 1:
if( init$0 === false ) {
$D$0 = GET_ITER$0(arr1);
$D$2 = $D$0 === 0;
$D$1 = ($D$2 ? arr1.length : void 0);
init$0 = true;
}
next$0 = $D$2 ? ($D$0 < $D$1) : !($D$1 = $D$0["next"]())["done"];
if( next$0 ) {
x = ($D$2 ? arr1[$D$0++] : $D$1["value"]);
state$0 = 2;
}
else {
break;
}
case 2:
if( init$1 === false ) {
y = void 0;
$D$3 = GET_ITER$0(arr2);
$D$5 = $D$3 === 0;
$D$4 = ($D$5 ? arr2.length : void 0);
init$1 = true;
}
next$0 = $D$5 ? ($D$3 < $D$4) : !($D$4 = $D$3["next"]())["done"];
if( next$0 ) {
y = ($D$5 ? arr2[$D$3++] : $D$4["value"]).a;
}
else {
state$0 = 1;
init$1 = false;
;
$D$3 = $D$4 = $D$5 = void 0;
y = void 0;
continue;
}
;
}
if( next$0 ) {
;
if( x != 2 ) {
return {"value": x + y, "done": false};
}
else {
continue;
}
}
else {
x = void 0;
done$0 = true;
break
}
}
}
if( done$0 === true ) {
;
$D$0 = $D$1 = $D$2 = void 0;
;
$D$3 = $D$4 = $D$5 = void 0;
y = void 0;
if( this && this["__next__"] === next ) {
delete this["__next__"];
delete this["__throw__"];
}
;
}
;
if( throw$0 === true ) {
throw throw_error$0;
}
;
return {"value": void 0, "done": true};
}, function(err) {
if( this && this["__next__"] ) {
return this["__next__"](err, true);
}
else {
throw err
}
})
})()
$D$6 = GET_ITER$0(gen);
$D$8 = $D$6 === 0;
$D$7 = ($D$8 ? gen.length : void 0);
for( var a; $D$8 ? ($D$6 < $D$7) : !($D$7 = $D$6["next"]())["done"]; ) {
a = ($D$8 ? gen[$D$6++] : $D$7["value"]);
console.log(a)
}
;
$D$6 = $D$7 = $D$8 = void 0;
var S_ITER$0 = typeof Symbol!=='undefined'&&Symbol&&Symbol.iterator||'@@iterator';var S_MARK$0 = typeof Symbol!=='undefined'&&Symbol&&Symbol["__setObjectSetter__"];function GET_ITER$0(v){if(v){if(Array.isArray(v))return 0;var f;if(S_MARK$0)S_MARK$0(v);if(typeof v==='object'&&typeof (f=v[S_ITER$0])==='function'){if(S_MARK$0)S_MARK$0(void 0);return f.call(v);}if(S_MARK$0)S_MARK$0(void 0);if((v+'')==='[object Generator]')return v;}throw new Error(v+' is not iterable')};var $D$6;var $D$7;var $D$8;
var arr1 = [1, 2, 3], arr2 = [{a:'a'}, {a:'b'}, {a:'c'}];
var gen = (function(){var S_STAG$0 = typeof Symbol!=='undefined'&&Symbol&&Symbol["toStringTag"]||'@@toStringTag';var Generator$0 = function Generator(){if(!(this instanceof Generator$0))throw new TypeError('incompatible'+this);this["__next__"]=arguments[0];this["__throw__"]=arguments[1];};Generator$0.prototype={constructor:Generator$0,"next":function(val){if(!(this instanceof Generator$0))throw new TypeError('next method called on incompatible '+this);if(this["__next__"]){try {return this["__next__"](val);}catch(e){if(this["__throw__"])return this["__throw__"](e);else throw e;}}else return {"value":void 0,"done":true};},"throw":function(e){if(!(this instanceof Generator$0))throw new TypeError('throw method called on incompatible '+this);if(this&&this["__throw__"])return this["__throw__"](e);else throw e},"toString":function(){return '[object Generator]'}};if(S_MARK$0)S_MARK$0(Generator$0.prototype);Generator$0.prototype[S_STAG$0]='Generator';Generator$0.prototype[S_ITER$0]=function(){return this};if(S_MARK$0)S_MARK$0(void 0);var $D$0;var $D$1;var $D$2;var $D$3;var $D$4;var $D$5;var x;var y;var done$0=false;var init$0=false;var init$1=false;var state$0=1,next$0=false;return new Generator$0(function next(throw_error$0,throw$0){if(throw$0===true){done$0=true;}if(done$0===false){while(true){next$0=false;switch(state$0){case 1:if(init$0===false){$D$0 = GET_ITER$0(arr1);$D$2 = $D$0 === 0;$D$1 = ($D$2 ? arr1.length : void 0);init$0=true;}next$0=$D$2 ? ($D$0 < $D$1) : !($D$1 = $D$0["next"]())["done"];if(next$0){x = ($D$2 ? arr1[$D$0++] : $D$1["value"]);state$0=2;}else {break;}case 2:if(init$1===false){y=void 0;$D$3 = GET_ITER$0(arr2);$D$5 = $D$3 === 0;$D$4 = ($D$5 ? arr2.length : void 0);init$1=true;}next$0=$D$5 ? ($D$3 < $D$4) : !($D$4 = $D$3["next"]())["done"];if(next$0){y = ($D$5 ? arr2[$D$3++] : $D$4["value"]).a;}else{state$0=1;init$1=false;;$D$3 = $D$4 = $D$5 = void 0;y=void 0;continue;};}if(next$0){;if(x != 2){return {"value":x + y,"done":false};}else {continue;}}else{x=void 0;done$0=true;break}}}if(done$0===true){;$D$0 = $D$1 = $D$2 = void 0;;$D$3 = $D$4 = $D$5 = void 0;y=void 0;if(this&&this["__next__"]===next){delete this["__next__"];delete this["__throw__"];};};if(throw$0===true){throw throw_error$0;};return {"value":void 0,"done":true};},function(err){if(this&&this["__next__"]){return this["__next__"](err,true);}else {throw err}})})()
$D$6 = GET_ITER$0(gen);$D$8 = $D$6 === 0;$D$7 = ($D$8 ? gen.length : void 0);for( var a ;$D$8 ? ($D$6 < $D$7) : !($D$7 = $D$6["next"]())["done"];){a = ($D$8 ? gen[$D$6++] : $D$7["value"]);
console.log(a)
};$D$6 = $D$7 = $D$8 = void 0;
var arr1 = [1, 2, 3], arr2 = [{a:'a'}, {a:'b'}, {a:'c'}];
var gen = ( x + y for (x of arr1) for ({a: y} of arr2) if ( x != 2 ) )
for( let a of gen ) {
console.log(a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment