Comparing version 0.10.0 to 0.10.3
@@ -154,4 +154,8 @@ /* | ||
if (Class === void 0) { | ||
return obj === void 0; | ||
} | ||
if (typeof Class !== 'function') { | ||
throw 'Trying to assert undefined class'; | ||
throw 'Trying to assert invalid class'; | ||
} | ||
@@ -198,2 +202,4 @@ | ||
this.completed = false; | ||
this.fail = false; | ||
this.success = false; | ||
this.thenListeners = []; | ||
@@ -214,7 +220,10 @@ this.catchListeners = []; | ||
then: function(fn) { | ||
this.thenListeners.push(fn); | ||
if (this.completed) { | ||
then: function(fnFulfill, fnReject) { | ||
this.thenListeners.push(fnFulfill); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
} | ||
if (fnReject) { | ||
this.catch(fnReject); | ||
} | ||
return this; | ||
@@ -225,3 +234,3 @@ }, | ||
this.catchListeners.push(fn); | ||
if (this.completed) { | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
@@ -239,2 +248,3 @@ } | ||
p.completed = true; | ||
p.success = true; | ||
p.value = value; | ||
@@ -244,3 +254,8 @@ }; | ||
Promise.doReject = function reject(p, reason) { | ||
p.catchListeners.forEach(function(listener){ | ||
if (p.catchListeners.length === 0) { | ||
console.log('Uncaught (in promise): ' + reason); | ||
} | ||
p.catchListeners.forEach(function(listener) { | ||
listener(reason); | ||
@@ -250,2 +265,3 @@ }) | ||
p.completed = true; | ||
p.fail = true; | ||
p.reason = reason; | ||
@@ -344,4 +360,4 @@ }; | ||
return new CRL.Promise(function(resolve, reject) { | ||
//schedule(next); | ||
next(); | ||
// ensure it runs asynchronously | ||
schedule(next); | ||
@@ -354,9 +370,19 @@ function next(value) { | ||
state = gen.next(value); | ||
value = state.value; | ||
try { | ||
state = gen.next(value); | ||
value = state.value; | ||
} catch (e) { | ||
console.error(e.stack ? '\n' + e.stack : e); | ||
return; | ||
} | ||
if (isPromise(value)) { | ||
value.then(function(value) { | ||
next(value); | ||
}) | ||
value.then( | ||
function onFulfilled(value) { | ||
next(value) | ||
}, | ||
function onRejected(reason) { | ||
gen.throw(reason) | ||
} | ||
) | ||
return; | ||
@@ -363,0 +389,0 @@ } |
@@ -247,2 +247,25 @@ # Documentation | ||
## Platform Compatibility | ||
Cor coroutines are based in generators, so, if you plan to use it you must take the following in consideration. | ||
When using Node.js or browsers without generator support, you must use [gnode](https://github.com/TooTallNate/gnode) and/or [regenerator](http://facebook.github.io/regenerator/). | ||
### Server | ||
* Node.js 4+ | ||
When using Node.js 0.11.x or greater, you must use the `--harmony-generators` flag or just `--harmony` to get access to generators. | ||
### Browsers | ||
* Firefox 27+ | ||
* Chrome 39+ | ||
* Opera 26+ | ||
* Edge 13+ | ||
Chrome between 28 and 38 are supported by turning on an experimental flag. | ||
## Semicolon Insertion | ||
@@ -249,0 +272,0 @@ |
@@ -47,5 +47,7 @@ # Get started | ||
After that, you are able to include the distribution script located at bower_components/cor/dist/cor.js in any html file through the <script></script> tag. | ||
After that, you are able to include the distribution script located at bower_components/cor/dist/cor.js in any html file through the `<script></script>` tag. | ||
<scritp type="text/javascript" src="bower_components/cor/dist/cor.js"> | ||
``` | ||
<script type="text/javascript" src="bower_components/cor/dist/cor.js"></script> | ||
``` | ||
@@ -52,0 +54,0 @@ ## First steps |
{ | ||
"author" : "Yosbel Marin", | ||
"name" : "cor-lang", | ||
"version" : "0.10.0", | ||
"version" : "0.10.3", | ||
"license" : "BSD", | ||
@@ -6,0 +6,0 @@ "description" : "The Language of the Web", |
@@ -102,9 +102,9 @@ require('../parser.js'); | ||
function writeAll(outPath) { | ||
function writeAll(dirPath) { | ||
var | ||
i, len,plugin, src, | ||
i, len, parsed, outPath, | ||
srcPath, absPath; | ||
for (i = 0, len = sourceDirs.length; i < len; i++) { | ||
absPath = cor.path.join(outPath, sourceDirs[i]); | ||
absPath = cor.path.join(dirPath, sourceDirs[i]); | ||
makePath(cor.path.split(absPath)); | ||
@@ -116,6 +116,10 @@ } | ||
for (srcPath in sourceCode) { | ||
outPath = cor.path.join(dirPath, srcPath); | ||
parsed = cor.path.parse(outPath); | ||
outPath = parsed.root + parsed.dir + cor.path.basename(outPath, cor.path.ext(outPath)) + '.js'; | ||
writeFile(sourceCode[srcPath], srcPath, outPath); | ||
} | ||
console.log('\nOutput in ' + path.resolve(outPath)); | ||
console.log('\nOutput in ' + path.resolve(dirPath)); | ||
} | ||
@@ -132,8 +136,8 @@ | ||
parsed = cor.path.parse(sourcePath); | ||
outPath = outPath || parsed.root + parsed.dir + cor.path.basename(sourcePath, cor.path.ext(sourcePath)) + '.js'; | ||
outPath = outPath || parsed.root + parsed.dir + cor.path.basename(sourcePath, cor.path.ext(sourcePath)) + '.js'; | ||
writeFile(sourceCode[''], sourcePath, outPath); | ||
} | ||
else if (stats.isDirectory()) { | ||
outPath = outPath || cor.path.basename(sourcePath) + ('js_' + (new Date()).getTime()); | ||
write(outPath); | ||
outPath = outPath || cor.path.basename(sourcePath) + ('js_' + (new Date()).getTime()); | ||
writeAll(outPath); | ||
} | ||
@@ -140,0 +144,0 @@ } |
@@ -123,4 +123,8 @@ (function(){ | ||
if (Class === void 0) { | ||
return obj === void 0; | ||
} | ||
if (typeof Class !== 'function') { | ||
throw 'Trying to assert undefined class'; | ||
throw 'Trying to assert invalid class'; | ||
} | ||
@@ -167,2 +171,4 @@ | ||
this.completed = false; | ||
this.fail = false; | ||
this.success = false; | ||
this.thenListeners = []; | ||
@@ -183,7 +189,10 @@ this.catchListeners = []; | ||
then: function(fn) { | ||
this.thenListeners.push(fn); | ||
if (this.completed) { | ||
then: function(fnFulfill, fnReject) { | ||
this.thenListeners.push(fnFulfill); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
} | ||
if (fnReject) { | ||
this.catch(fnReject); | ||
} | ||
return this; | ||
@@ -194,3 +203,3 @@ }, | ||
this.catchListeners.push(fn); | ||
if (this.completed) { | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
@@ -208,2 +217,3 @@ } | ||
p.completed = true; | ||
p.success = true; | ||
p.value = value; | ||
@@ -213,3 +223,8 @@ }; | ||
Promise.doReject = function reject(p, reason) { | ||
p.catchListeners.forEach(function(listener){ | ||
if (p.catchListeners.length === 0) { | ||
console.log('Uncaught (in promise): ' + reason); | ||
} | ||
p.catchListeners.forEach(function(listener) { | ||
listener(reason); | ||
@@ -219,2 +234,3 @@ }) | ||
p.completed = true; | ||
p.fail = true; | ||
p.reason = reason; | ||
@@ -313,4 +329,4 @@ }; | ||
return new CRL.Promise(function(resolve, reject) { | ||
//schedule(next); | ||
next(); | ||
// ensure it runs asynchronously | ||
schedule(next); | ||
@@ -323,9 +339,19 @@ function next(value) { | ||
state = gen.next(value); | ||
value = state.value; | ||
try { | ||
state = gen.next(value); | ||
value = state.value; | ||
} catch (e) { | ||
console.error(e.stack ? '\n' + e.stack : e); | ||
return; | ||
} | ||
if (isPromise(value)) { | ||
value.then(function(value) { | ||
next(value); | ||
}) | ||
value.then( | ||
function onFulfilled(value) { | ||
next(value) | ||
}, | ||
function onRejected(reason) { | ||
gen.throw(reason) | ||
} | ||
) | ||
return; | ||
@@ -332,0 +358,0 @@ } |
@@ -1702,3 +1702,3 @@ (function(cor){ | ||
initNode: function() { | ||
if (this.children[0] instanceof yy.VarNode ) { | ||
if (this.children[0] instanceof yy.VarNode ) { | ||
this.ref = this.children[0].name; | ||
@@ -1770,2 +1770,38 @@ } | ||
} | ||
}); | ||
yy.UnaryExistenceNode = Class(yy.ExistenceNode, { | ||
type: 'UnaryExistenceNode', | ||
initNode: function() { | ||
var ch = this.children; | ||
if (ch.length == 1 && (this.subject instanceof yy.VarNode)) { | ||
this.ref = this.subject.name; | ||
this.usingVar = true; | ||
} else { | ||
this.ref = yy.env.context().generateVar('ref'); | ||
this.yy.env.context().addLocalVar(this.ref); | ||
} | ||
}, | ||
compile: function() { | ||
var | ||
ch = this.children, | ||
ref = this.ref, | ||
condition = '!(typeof ' + ref + ' === \'undefined\' || ' + ref + ' === null)'; | ||
if (this.usingVar) { | ||
ch.splice(0, 1); | ||
} else { | ||
ch.splice(0, 0, new yy.Lit('((' + ref + ' = ', getLesserLineNumber(ch[0]))); | ||
ch.push(new yy.Lit('), ', this.lineno)); | ||
condition += ')'; | ||
} | ||
ch.push(new yy.Lit(condition, this.lineno)); | ||
} | ||
}) | ||
@@ -1772,0 +1808,0 @@ |
Sorry, the diff of this file is too big to display
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 too big to display
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
884263
143
15192