Comparing version 0.8.2 to 0.8.3
@@ -7,15 +7,7 @@ (function() { | ||
resolve = terms.term({ | ||
constructor: function(term, gen1_options) { | ||
constructor: function(term) { | ||
var self = this; | ||
var alreadyPromise; | ||
alreadyPromise = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "alreadyPromise") && gen1_options.alreadyPromise !== void 0 ? gen1_options.alreadyPromise : false; | ||
self.isResolve = true; | ||
self.term = term; | ||
return self._resolve = function() { | ||
if (alreadyPromise) { | ||
return term; | ||
} else { | ||
return term.promisify(); | ||
} | ||
}(); | ||
return self._resolve = term.promisify(); | ||
}, | ||
@@ -36,5 +28,5 @@ makeAsyncCallWithCallback: function(onFulfilled, onRejected) { | ||
}); | ||
return createResolve = function(term, gen2_options) { | ||
return createResolve = function(term, gen1_options) { | ||
var alreadyPromise; | ||
alreadyPromise = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "alreadyPromise") && gen2_options.alreadyPromise !== void 0 ? gen2_options.alreadyPromise : false; | ||
alreadyPromise = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "alreadyPromise") && gen1_options.alreadyPromise !== void 0 ? gen1_options.alreadyPromise : false; | ||
var asyncResult; | ||
@@ -41,0 +33,0 @@ asyncResult = terms.asyncResult(); |
@@ -76,5 +76,3 @@ (function() { | ||
asyncForFunction = terms.moduleConstants.defineAs([ "async", "for" ], terms.javascript(asyncControl.for.toString())); | ||
return terms.scope([ init, terms.resolve(terms.functionCall(asyncForFunction, [ terms.closure([], testStatements), terms.closure([], incrStatements), terms.closure([], body) ]), { | ||
alreadyPromise: true | ||
}) ]); | ||
return terms.scope([ init, terms.resolve(terms.functionCall(asyncForFunction, [ terms.closure([], testStatements), terms.closure([], incrStatements), terms.closure([], body) ]).alreadyPromise()) ]); | ||
} else { | ||
@@ -81,0 +79,0 @@ return forExpressionTerm(init, test, incr, body); |
@@ -5,26 +5,18 @@ (function() { | ||
var self = this; | ||
return terms.term({ | ||
constructor: function(gen1_options) { | ||
var self = this; | ||
var closure, statements, term, callsFulfillOnReturn; | ||
closure = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "closure") && gen1_options.closure !== void 0 ? gen1_options.closure : void 0; | ||
statements = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "statements") && gen1_options.statements !== void 0 ? gen1_options.statements : void 0; | ||
term = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "term") && gen1_options.term !== void 0 ? gen1_options.term : void 0; | ||
callsFulfillOnReturn = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "callsFulfillOnReturn") && gen1_options.callsFulfillOnReturn !== void 0 ? gen1_options.callsFulfillOnReturn : true; | ||
self.isNewPromise = true; | ||
return self._newPromise = terms.newOperator(terms.functionCall(terms.promise(), [ closure || terms.closure([ terms.onFulfilledFunction ], statements || terms.statements([ term ]), { | ||
return function(gen1_options) { | ||
var closure, statements, term, callsFulfillOnReturn; | ||
closure = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "closure") && gen1_options.closure !== void 0 ? gen1_options.closure : void 0; | ||
statements = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "statements") && gen1_options.statements !== void 0 ? gen1_options.statements : void 0; | ||
term = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "term") && gen1_options.term !== void 0 ? gen1_options.term : void 0; | ||
callsFulfillOnReturn = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "callsFulfillOnReturn") && gen1_options.callsFulfillOnReturn !== void 0 ? gen1_options.callsFulfillOnReturn : true; | ||
if (statements && statements.statements.length === 1) { | ||
return statements.statements[0].promisify(); | ||
} else { | ||
return terms.newOperator(terms.functionCall(terms.promise(), [ closure || terms.closure([ terms.onFulfilledFunction ], statements || terms.statements([ term ]), { | ||
inPromise: true, | ||
callsFulfillOnReturn: callsFulfillOnReturn | ||
}) ])); | ||
}, | ||
generate: function(scope) { | ||
var self = this; | ||
return self._newPromise.generate(scope); | ||
}, | ||
promisify: function() { | ||
var self = this; | ||
return self; | ||
}) ])).alreadyPromise(); | ||
} | ||
}); | ||
}; | ||
}; | ||
}).call(this); |
@@ -22,5 +22,3 @@ (function() { | ||
if (statements.returnsPromise) { | ||
return terms.resolve(fn, { | ||
alreadyPromise: true | ||
}); | ||
return terms.resolve(fn.alreadyPromise()); | ||
} else { | ||
@@ -27,0 +25,0 @@ return fn; |
@@ -546,5 +546,14 @@ (function() { | ||
}, | ||
alreadyPromise: function() { | ||
var self = this; | ||
self._alreadyPromise = true; | ||
return self; | ||
}, | ||
promisify: function() { | ||
var self = this; | ||
return cg.methodCall(cg.promise(), [ "resolve" ], [ self ]); | ||
if (self._alreadyPromise) { | ||
return self; | ||
} else { | ||
return cg.methodCall(cg.promise(), [ "resolve" ], [ self ]).alreadyPromise(); | ||
} | ||
}, | ||
@@ -589,3 +598,3 @@ code: function() { | ||
term = function(members) { | ||
var termConstructor; | ||
var termConstructor, gen38_c; | ||
termConstructor = classExtending(Term, members); | ||
@@ -592,0 +601,0 @@ return function() { |
@@ -63,29 +63,38 @@ (function() { | ||
catchClause = function(body, catchParameter, catchBody) { | ||
return terms.methodCall(body, [ "then" ], [ terms.nil(), terms.closure([ catchParameter ], catchBody) ]); | ||
return terms.methodCall(body, [ "then" ], [ terms.nil(), terms.closure([ catchParameter ], catchBody) ]).alreadyPromise(); | ||
}; | ||
finallyClause = function(body, finallyBody) { | ||
var result; | ||
var result, finallyBlock; | ||
result = terms.generatedVariable([ "result" ]); | ||
return terms.methodCall(body, [ "then" ], [ terms.closure([ result ], terms.statements([ terms.methodCall(finallyBody.promisify(), [ "then" ], [ terms.closure([], terms.statements([ result ])) ]) ])) ]); | ||
finallyBlock = function(gen2_options) { | ||
var throwResult; | ||
throwResult = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "throwResult") && gen2_options.throwResult !== void 0 ? gen2_options.throwResult : false; | ||
var resultStatement; | ||
resultStatement = function() { | ||
if (throwResult) { | ||
return terms.throwStatement(result); | ||
} else { | ||
return result; | ||
} | ||
}(); | ||
return terms.closure([ result ], terms.statements([ terms.methodCall(finallyBody.promisify(), [ "then" ], [ terms.closure([], terms.statements([ resultStatement ])) ]) ])); | ||
}; | ||
return terms.methodCall(body, [ "then" ], [ finallyBlock(), finallyBlock({ | ||
throwResult: true | ||
}) ]).alreadyPromise(); | ||
}; | ||
return tryExpression = function(body, gen2_options) { | ||
return tryExpression = function(body, gen3_options) { | ||
var catchBody, catchParameter, finallyBody; | ||
catchBody = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "catchBody") && gen2_options.catchBody !== void 0 ? gen2_options.catchBody : void 0; | ||
catchParameter = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "catchParameter") && gen2_options.catchParameter !== void 0 ? gen2_options.catchParameter : void 0; | ||
finallyBody = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "finallyBody") && gen2_options.finallyBody !== void 0 ? gen2_options.finallyBody : void 0; | ||
catchBody = gen3_options !== void 0 && Object.prototype.hasOwnProperty.call(gen3_options, "catchBody") && gen3_options.catchBody !== void 0 ? gen3_options.catchBody : void 0; | ||
catchParameter = gen3_options !== void 0 && Object.prototype.hasOwnProperty.call(gen3_options, "catchParameter") && gen3_options.catchParameter !== void 0 ? gen3_options.catchParameter : void 0; | ||
finallyBody = gen3_options !== void 0 && Object.prototype.hasOwnProperty.call(gen3_options, "finallyBody") && gen3_options.finallyBody !== void 0 ? gen3_options.finallyBody : void 0; | ||
if (body.returnsPromise || catchBody && catchBody.returnsPromise || finallyBody && finallyBody.returnsPromise) { | ||
if (catchBody) { | ||
if (finallyBody) { | ||
return terms.resolve(finallyClause(catchClause(body.promisify(), catchParameter, catchBody), finallyBody), { | ||
alreadyPromise: true | ||
}); | ||
return terms.resolve(finallyClause(catchClause(body.promisify(), catchParameter, catchBody), finallyBody)); | ||
} else { | ||
return terms.resolve(catchClause(body.promisify(), catchParameter, catchBody), { | ||
alreadyPromise: true | ||
}); | ||
return terms.resolve(catchClause(body.promisify(), catchParameter, catchBody)); | ||
} | ||
} else if (finallyBody) { | ||
return terms.resolve(finallyClause(body.promisify(), finallyBody), { | ||
alreadyPromise: true | ||
}); | ||
return terms.resolve(finallyClause(body.promisify(), finallyBody)); | ||
} else { | ||
@@ -92,0 +101,0 @@ return terms.resolve(body); |
{ | ||
"name": "pogo", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "A readable, DSL friendly programming language that compiles to JavaScript", | ||
@@ -5,0 +5,0 @@ "author": "Tim Macfarlane <timmacfarlane@gmail.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
473053
7355