satyr / coco Goto Github PK
View Code? Open in Web Editor NEWUnfancy CoffeeScript
Home Page: http://satyr.github.com/coco/
License: MIT License
Unfancy CoffeeScript
Home Page: http://satyr.github.com/coco/
License: MIT License
return if get()
↓
var _ref;
if (_ref = get()) return _ref;
When installing coco manually using readme instructions, the following occurs:
node.js:63
throw e;
^s:275:15)
at require (node.js:411:14)
at Object.<anonymous> (/Users/KUHRT/coco/bin/coco:20:5)
at Module._compile (node.js:462:23)
at Module._loadScriptSync (node.js:469:10)
at Module.loadSync (node.js:338:12)
at loadModule (node.js:283:14)
at require (node.js:411:14)
at Object.<anonymous> (/Users/KUHRT/coco/bin/coke:11:15)
at Module._compile (node.js:462:23)
I can overcome this by manually copying the optpase file from the lib directory to the bin directory. I also npm'd optparse but haven't tried loading the module from there (after I realized the problem code was using a local path). I see that you've symlinked the coke file to bin so I am not sure why this is happening.
Am I doing something wrong?
Currently the import
or <<<
feature is handy but a version that allows for only undefined values to be imported would help I think.
Below is a common use-case:
human = (args)->
defaults =
height: 6
hair: 'brown'
args <<< defaults
console.log args, defaults
human do
country: 'canada'
job: 'mail man'
height: 3
In this example, defaults.height
overrides args.height
.
Maybe the syntax could be something like:
<<<?
<<<<?
I am not sold on those at all, just potentials.
Maybe we could change <<< to behave non-destructively by default. Then we could provide bang syntax to force overrides, like such:
<<<!
<<<<!
code &&+= '\n'
↓
code && (code += '\n');
a.b&.c
↓
__bind((_ref = a.b).c, _ref)
/// \n #{? if multi then 'g' else '' }///
↓
RegExp('\n', multi ? 'g' : '')
Any thoughts of integrating this in coco?
class C
(@attr) =>
↓
var C;
C = (function(){
function C(_arg){
var _this = new _ctor;
_this.attr = _arg;
return _this;
}
C.name = "C";
function _ctor(){}
_ctor.prototype = C.prototype;
return C;
}());
Since the return value of JS delete
is hardly useful and rarely used.
v = delete o.p
delete o.k
↓
var _ref;
v = (_ref = o.k, delete o.k, ref);
delete o.k;
So that hacks like
`EXIT:`
for i from 3 to 5
for j from 7 to 9
`break EXIT` if Math.random() < .2
say i * j
works as expected.
@:: import ...
).import
for real.<<<
for import
, <<<<
for import all
?
return that if get()
↓
var that;
if (that = get()) {
return that;
}
So that this:
$ coco -e 'console.log arguments is (switch case 1 then arguments)'
false
results in true
.
console.log(arguments === (function(){
switch (false) {
case !1:
return arguments;
}
}.apply(this, arguments)));
console.log(arguments === (function(_args){
switch (false) {
case !1:
return _args;
}
}(arguments)));
Install instructions state:
git clone git:github.com/satyr/coco.git && cd coco && bin/coke i
But should be:
git clone git://github.com/satyr/coco.git && cd coco && bin/coke i
ok = if cond
expr()
true
else
false
↓
var ok;
ok = (function(){
if (cond) {
expr();
return true;
} else {
return false;
}
}());
var ok;
ok = cond ? (expr(), true) : false;
With syntax like:
obj = {
prop: function -> 42
prop: function (item) -> alert item
}
↓
var obj;
obj = {
get prop(){
return 42;
},
set prop(item){
return alert(item);
}
};
$ git log -1 --format=oneline
4a67699c0e66707299fe22c3311c3be35b4fe4f grammar: removed Case
$ coke bench
Lex : 1026[ms] (18388 tokens)
Rewrite : 135[ms] (20772 tokens)
Parse : 150[ms]
Compile : 212[ms] (119587 chars)
TOTAL : 1523[ms]
Apparently there is a problem with package.json. According to isaacs the bin hash should be filenames not module ids.
~ $ npm install coco --loglevel verbose npm info it worked if it ends with ok
npm verb cli [ 'install',
npm verb cli 'coco',
npm verb cli '--loglevel',
npm verb cli 'verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb config file /Users/stuarts/.npmrc
npm verb config file /Users/stuarts/local/etc/npmrc
npm verb install [ 'coco' ]
npm verb install [ 'coco' ]
npm verb install pkglist [ 'coco' ]
npm verb must install [ 'coco' ]
npm verb install coco
npm verb must install? [ [ 'coco' ], true ]
npm verb GET coco
npm verb etag "2V412V9E96NYDOLEOXV5L3HMB"
npm verb response http://registry.npmjs.org/coco npm verb etag coco from cache
npm verb Supported versions [ '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]',
npm verb Supported versions '[email protected]' ]
npm verb coco tag latest
npm verb install [email protected]
npm verb must install? [ [ 'coco', '0.3.2' ],
npm verb must install? true ]
npm verb [email protected] exact
npm verb caching /Users/stuarts/local/lib/node/.npm/.cache/coco/0.3.2/package.json
npm verb install list [ [ 'coco', '0.3.2' ] ]
npm verb mkdir done: /Users/stuarts/local/lib/node/.npm/coco/0.3.2
npm verb unpackTar uid, gid [ undefined, undefined ]
npm verb success gzip "--decompress" "--stdout" "/Users/stuarts/local/lib/node/.npm/.cache/coco/0.3.2/package.tgz"
npm verb success tar "-mvxpf" "-" "-C" "/Users/stuarts/local/lib/node/.npm/coco/0.3.2"
npm verb unpacked, building coco,0.3.2
npm verb caching /Users/stuarts/local/lib/node/.npm/coco/0.3.2/package/package.json
npm info preinstall [email protected]
npm verb deps being resolved [ { name: 'coco',
npm verb deps being resolved description: 'Unfancy CoffeeScript',
npm verb deps being resolved keywords:
npm verb deps being resolved [ 'language',
npm verb deps being resolved 'compiler',
npm verb deps being resolved 'coffeescript',
npm verb deps being resolved 'javascript' ],
npm verb deps being resolved author:
npm verb deps being resolved { name: 'satyr',
npm verb deps being resolved email: '[email protected]',
npm verb deps being resolved url: 'http://satyr.github.com' },
npm verb deps being resolved version: '0.3.2',
npm verb deps being resolved homepage: 'http://satyr.github.com/coco/',
npm verb deps being resolved repository:
npm verb deps being resolved { type: 'git',
npm verb deps being resolved url: 'git://github.com/satyr/coco.git' },
npm verb deps being resolved licenses:
npm verb deps being resolved [ { type: 'MIT',
npm verb deps being resolved url: 'https://github.com/satyr/coco/raw/master/LICENSE' } ],
npm verb deps being resolved engines: { node: '>=0.2.6' },
npm verb deps being resolved directories: { lib: './lib', bin: './bin' },
npm verb deps being resolved main: './lib/coco',
npm verb deps being resolved bin:
npm verb deps being resolved { coco: './lib/command',
npm verb deps being resolved coke: './lib/coke' },
npm verb deps being resolved id: '[email protected]',
npm verb deps being resolved engineSupported: true,
npm verb deps being resolved npmVersion: '0.3.15',
npm verb deps being resolved nodeVersion: 'v0.4.2',
npm verb deps being resolved files: [ '' ],
npm verb deps being resolved defaultsLoaded: true,
npm verb deps being resolved dist:
npm verb deps being resolved { shasum: 'd5aff68b204e5f5f84f7db0298b2af6d2da3370e',
npm verb deps being resolved tarball: 'http://registry.npmjs.org/coco/-/coco-0.3.2.tgz' },
npm verb deps being resolved _bundledDeps: [] },
npm verb deps being resolved [] ]
npm verb linkBins [email protected]
npm verb linkBin coco ./lib/command
npm verb linkBin coke ./lib/coke
npm verb linkMans [email protected]
npm ERR! failed to link bins
npm ERR! install failed Error: ENOENT, No such file or directory '/Users/stuarts/local/bin/[email protected]'
npm info install failed rollback
npm info uninstall [ '[email protected]' ]
npm verb removing [ [ 'coco', '0.3.2' ] ]
npm verb from cache /Users/stuarts/local/lib/node/.npm/coco/0.3.2/package/package.json
npm info preuninstall [email protected]
npm info uninstall [email protected]
npm info auto-deactive not symlink
npm verb uninstall [email protected] remove links
npm verb uninstall [email protected] remove bins
npm verb uninstall [email protected] remove public modules
npm info postuninstall [email protected]
npm verb uninstall [email protected] remove package dir
npm info uninstall [email protected] complete
npm info install failed rolled back
npm ERR! Error: ENOENT, No such file or directory '/Users/stuarts/local/bin/[email protected]'
npm ERR! Report this entire log at http://github.com/isaacs/npm/issues
npm ERR! or email it to [email protected]
npm ERR! Just tweeting a tiny part of the error will not be helpful.
npm ERR! System Darwin 10.6.0
npm ERR! argv { remain: [ 'coco' ],
npm ERR! argv cooked:
npm ERR! argv [ 'install',
npm ERR! argv 'coco',
npm ERR! argv '--loglevel',
npm ERR! argv 'verbose' ],
npm ERR! argv original:
npm ERR! argv [ 'install',
npm ERR! argv 'coco',
npm ERR! argv '--loglevel',
npm ERR! argv 'verbose' ] }
npm verb exit [ 2, true ]
npm not ok
function f1() ->
f2 = function () ->
↓
var f2;
function f1(){}
f2 = (function(){
function f2(){}
return f2;
}());
Allow arbitrary trailing alphabets, for specifying units etc.
setTimeout cb, 512ms
day = 24hours * 60seconds
So that code like
### (c) 2010 me ###
"use strict"
I = -> it
works as expected.
a: 1
a: 2
↓
({
a: 1,
a: 2
});
SyntaxError: duplicated property name "a"
Introduce 0b101010
and 0o52
, then disallow 052
per ES5.
a[4,2]
↓
[a[4], a[2]];
The property syntax is already special in allowing an indented expression as RHS:
$ coco -bpe '
> k:
> 1
> '
({
k: 1
});
But not block:
$ coco -bpe '
> k:
> 1
> 2
> '
Error: Parse error on line 3: Unexpected 'TERMINATOR'
Allowing the latter as an implicit array literal seems reasonable.
Should be able to optimize if the right operand is a bare array/object.
C:: import d: e, (f): g
↓
var _ref;
_ref = C.prototype, _ref.d = e, _ref[f] = g;
edit: On second thought, array case is pretty pointless.
[1 to 3]
[1 to 5 by 2]
↓
[1, 2, 3]
[1, 3, 5]
Should be able to expand within lexer.
\word
\+
↓
'word';
'+';
Expressions like []()
should be syntax errors at compile time.
Currently, do (x = y) -> ...
compiles to
(function(x){
x == null && (x = y);
...
}());
which is really just an inefficient way of writing
(function(x){
...
}(y));
Changing do
to rewrite in this way would also allow you to write do (x = x)
, which currently is nonsensical, to capture a particular value of x
(useful in loops).
I would also suggest that do (x)
be made a shorthand for do (x = x)
.
a <- f
x
(b, c) <- g ..., d
y
↑
f (a) ->
x
g (b, c) ->
y
, d
...
can be used as a placeholder for the callback function, as normally it is useless in the presence of another argument.switch task
case prepare
do sing
fallthrough # prevents auto-break
default
do dance
↓
switch (task) {
case prepare:
sing();
default:
dance();
}
Scope mixups:
a = 1
say do (a = a) -> a # 1
say do []= (a = a) -> a # undefined
do
being a simple sugar for ()
is consistent and easier to grok.
let (a = b) -> # (function(a){})(b)
let (a) -> # (function(a){})(a)
let (@a) -> # (function(a){})(this.a)
let ~> # (function(){}).call(this)
As you can now do the same without them using groov-y dots.
The current workaround (
→ L:
) is too awkward.break L;
Would it a terrible idea to allow other languages within coco?
Here's a simple example of what I am thinking:
paragraph =
:markdown
Hello,
======
Today is a *fine* day.
$('#welcome-message').inject paragraph
The :markdown is just an example of how one might signify the beginning of a new language block. I guess coco would need to have a 'hook' for authors to plugin/reference other language compilers. I imagine it wouldn't be too hard to manage that part. The issue may be more the usefulness of such a feature, and enough use-cases to make it worthwhile.
f ...
↓
f.apply(this, arguments);
a.b ||= {}
a.b.c ||= []
a.b.c.push e
↓
a%[email protected] e # ((a.b ||= {})c ||= [])push e
Useful, or ugly?
obj[\x, \y] = a
obj{x, y} = o
↓
obj['x'] = a[0], obj['y'] = a[1];
obj.x = o.x, obj.y = o.y;
Now that you can super ...
instead of super
(which compiles to the same thing), make it a literal for greater flexibility (such as a.map super.bind this
).
with f()
@p = q
↓
(function(){
return this.p = q;
}).call(f());
(a = 0, b ?= 1, c ||= 2) -> # where "a" is a sugar for "b"
↓
(a = 0, b ? 1, c || 2) -> # "a" stays for compatibility
The destructuring defaults would then be less confusing:
[x = 0, y or= 1] = z
↓
[x ? 0, y or 1] = z
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.