Skip to content

Instantly share code, notes, and snippets.

@icefapper
icefapper / gist:de509f247a9b3df5bac6
Last active March 26, 2016 11:54
small but functioning impl of a promise
function w(){this.state=null;this.c={};this.result={value:null,pending:false};}
w.prototype.toState=function(state,result){this.state=state;if(this.c[state]){var l=this;setTimeout(function(){l.c[state](result)}, 0);}else{this.result.value=result;this.result.pending=12;}}
w.prototype.onState = function(state,c){this.state=state;if(this.result.pending)this.toState(state,this.result.value ) ; }
function w5sec() {
var l = new w();
setTimeout(function(){l.toState("resolve",12);} , 5000)
return l
}
var src = 'var a, b, l = {a, [b]: {l}} = ({A}=a) => a = ({B=b}) => b = ({L=l}=40) => l';
// parse it
var syntaxNode = new Parser(src).parseProgram();
// transform what was parsed
var transformer = new Transformer();
transformer.renamer = renamer_minify;
var transformedNode = transformer.tr(syntaxNode, false);