Code Monkey home page Code Monkey logo

kaffeine's Introduction

  _  __      __  __     _
 | |/ /__ _ / _|/ _|___(_)_ _  ___
 | ' </ _` |  _|  _/ -_) | ' \/ -_)
 |_|\_\__,_|_| |_| \___|_|_||_\___|
  • Progressively enhance Javascript syntax: ensure vanilla Javascript still works as normal
  • avoid nice-to-haves, concentrate on small useful feature set and pragmatism
  • Hackable, modular, extendable and testable
  • whitespace is not significant. Looks nice, but is painful to work with.

Example

Edge::add = (nick, name, complete) {
  @client.select 15
  user = User.find! {id: nick}
  puzzle = Puzzle.find! {name: name}
  err, data = client.set! "u:#{user}:p:#{puzzle}"
  complete()
}

READ MORE HERE ---> http://weepy.github.com/kaffeine <-----

also on IRC: #altjs

Tests

  • via Node

    • bin/expect will run all tests
    • bin/expect file_name will a particular test e.g. bin/expect expectations/arrow
  • via Browser

    • load browser/runner.html
  • Integration tests:

    • node test/test_node.js
    • knode test/test_knode.js

Building tests for the browser

bin/build

depends on brequire (http://github.com/weepy/brequire).

Install

npm install kaffeine

requires node >= 0.3.1

Use

Compile a script from the command line:

kaffeine -c /path/to/script.k

See kaffeine --help for more

Run a kaffeine file directly

knode /path/to/script.k

require kaffeine files in scripts (in this case my_script.k):

require('kaffeine')
require('my_script')

TODO

  • need --- operator for delimiting bangs!
  • nested for loops - is there a problem ?

kaffeine's People

Contributors

benekastah avatar blakmatrix avatar charud avatar jfhbrook avatar michaelficarra avatar weepy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kaffeine's Issues

Bad JS output

It seems like kaffeine adds a return statement to line 3 of this code:

CurlCommand.escapeConfigValue = function(argument) {
  argument += '';
  argument = argument.replace(/\\/g, '\\\\');
  argument = argument.replace(/"/g, '\\"');
  argument = argument.replace(/\n/g, '\\n');
  argument = argument.replace(/\t/g, '\\t');
  argument = argument.replace(/\r/g, '\\r');
  argument = argument.replace(/\v/g, '\\v');
  return '"'+argument+'"';
};

The error I'm getting is this:

/var/git/transloader.transload.it/api2/node_modules/transloadit/command/curl_command.js (compiled):101
  return argument = argument.replace(/\\/g, '\\\\');\n\
                                                    ^

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:399:25)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at require (module.js:348:19)
    at Object.<anonymous> (/var/git/transloader.transload.it/api2/node_modules/transloadit/assembly.js (compiled):10:19)
    at Module._compile (module.js:404:26)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)

Function syntax is ambiguous

No, I don't mean with an object literal, that's covered in the docs, I mean with a function invocation.

Suppose I define this function:

fn = (a, b, c) {
  (f) {
    f(a, b, c)
  }
}

It's a higher-order function that returns a function that accepts a functions and executes it.

You might call it like this:

a = 1
b = 2
c = 3

fn(a, b, c)({
  # + #1 + #2
})

but you might drop this second parens

fn(a, b, c) {
  # + #1 + #2
}

and then for whatever reason you might add a space after the function:

fn (a, b, c) {
  # + #1 + #2
}

which is ambiguous with calling fn if fn were defined as

fn = (f) {
  f(1, 2, 3)
}

I didn't encounter this in actual code, I just noticed it. You could solve it by doing what ruby does and not allowing a space between a function and the parens.

Add Existential Operator

In CS, this a feature I heavily use when writing templates, and it is very useful, since it makes your code more safe (because null/undefined will throw an error on accessing properties)

Example:

zip = lottery.drawWinner?().address?.zipcode

Loops aren't optimized

You have

for(_a = 0; _a < zoo.length; _a++)

instead of

for(_a = 0, l = zoo.length; _a < l; _a++)

which is faster and should be used everywhere.

install error (can't find plugins directory?)

after a fresh install of sudo npm install kaffeine:
(i also tried with -g)

~/node_modules/kaffeine/bin> ./kaffeine

~/node_modules/kaffeine/bin/command.js:13
for(var i =0; i< files.length;i++) {
^
TypeError: Cannot read property 'length' of undefined
at ~/node_modules/kaffeine/bin/command.js:13:27

~/node_modules/kaffeine/bin> node --version
v0.5.0-pre

~/node_modules/kaffeine/bin> npm --version
1.0.5

it looks like it's having problems finding the plugins directory.

splats in arg lists

this looks a bit complex ... personally never use it.

thoughts any one else ?

npm install issues

I installed via: npm install -g kaffeine

to get it to work, I had to:
from the kaffeine/bin directory:
ln -s ../lib/plugins plugins
because it's looking for the plugins off of the bin directory.

and at the top of commands.js I had to:
var Kaffeine = require("$complete_path_to_kaffeine_directory"),

I'm sure there is a better way, but that works for me for now.

also, I had optparse installed via:
npm install optparse
but it couldn't find it, so i had to remove that and
npm install -g optparse
I have no idea why, guess I should read up on npm one of these days.

Executing kaffeine files

I might be doing this wrong, but I was hoping to be able to execute kaffeine files with node.js directly by typing:

$ kaffeine my_file.k

But currently that seems to do nothing. Is that the expected behavior?

Async bug?

This:

sleep = { setTimeout #1, #0 }

for x in [1,2,3]
  sleep!(100)
  console.log(x)

Results in:

var sleep;

sleep = function() {
   return setTimeout(arguments[1], arguments[0]);
};

for (x in [ 1, 2, 3 ]) sleep(100, function() {});  

console.log(x);

Shouldn't the console.log be included in the sleep callback?

Switch statements cause compile errors

And when this is fixed, it would also be nice if break statements aren't required. They're silly. I would like something like:

switch foo {
  case :bar:
    aha()
  case :batz:
    doSomething()
    fallthrough
  default
    bar()
}

Just an idea.

Kaffeine chokes on some return statements

Kaffeine chockes on return statements like this:

return typeof step === 'string';

The output I get is:

/var/git/transloader.transload.it/api2/node_modules/transloadit/assembly.js (compiled):254
      return typeof return step === 'string';
                    ^^^^^^

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
SyntaxError: Unexpected token return
    at Module._compile (module.js:399:25)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at require (module.js:348:19)
    at Object.<anonymous> (/var/git/transloader.transload.it/api2/node_modules/transloadit/assembly_manager.js (compiled):4:16)
    at Module._compile (module.js:404:26)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)

The problem goes way when changing my line to:

return (typeof step === 'string');

But since my code was valid JS to begin with, I think this is probably a bug.

Horrible nodejs support

I've made countless changes to the nodejs compiler and executor to get it to simply run and it now compiles wrong. When I compile this code with $ kaffeine --compile...

http.createServer (request, response) {
  // stuff
}

It compiles to:

http.createServer((request, response)(function() {
  // stuff
}));

and obviously doesn't work as expected. The same code compiles perfectly in the browser.

@__define(G/S)etter__ doesn't work

An example error:
TypeError: Object function __defineSetter__() { [native code] } has no method 'tail'

This doesn't occur when simply writing this.__define(G/S)etter.

Switch/Case bug

This:

switch(1) {
  case 'a': console.log('..');
}```

Gives this error:
 >> Error: Unexpected token: punc ({) (line: 0, col: 19, pos: 19)

Obviously, this is not real code. It was taken from a bigger file but I've tried to isolate the problem. Thanks!


do/while loops fail to parse

var x = 0;
do {
x++;
console.log(x);
} while(x < 10);

Actual Result:
Error: Unexpected token: keyword (while) (line: 4, col: 3, pos: 66)

Expected result:
Same output code as input.

for own key in { ... }

Are there plans to develop a method to easily generate a javascript for...in loop like:

var obj = {a: 'a', b: 'b'}
for (var key in obj) {
  if (obj.hasOwnProperty(key)) {
    doSomething();
  }
}

I think a variant of CoffeeScript's solution would be elegant:

for own key in obj {
  doSomething();
}

For me, this is the only really crucial thing I find missing from kaffeine. I will probably still end up using (and contributing) to it even with this missing because of how awesome async programming will be with this tool.

errs out on switch statement

function a(topic) {
switch (topic) {
case 'a':
console.log(topic);
break;
}
}

Error at position: [ 1, 15 ] in plugin: undouble_brackets
function a(topic) {
^
TypeError: Cannot read property 'rbracket' of null

Integrate in Express?

I tried the following in Express:

var kaffeine = new (require("kaffeine"))();
app.register('.k', {
compile: function(str, options) {
return function(locals) { return kaffeine.compile(str) };
}
});
app.get('/:script.js', function(req, res) {
res.header('Content-Type', 'text/plain');
res.render(req.params.script+".k", { layout: false });
});

but I get bad output, e.g. source:

$( () {
$("input").attr("id", () { @name; });
});

converts to:
$( ()(function() {
return $("input").attr("id", ()(function() { return this.name; }).call(this));
}).call(this));

[the version in index.js is 0.0.6]

Is there any place to discuss kaffeine?

I discovered node, coffeescript, and couchdb just 3 or 4 weeks ago (I know, I live under a rock). I am starting a new project and I've made the crazy decision to jump from lamp to node/couchdb. In just a few weeks the tools have been so great that I have hand-grown my own virtual hosting environment and an html generation tool that are awesome, if I say so myself.

To get to the point, I have had two serious problems with my new wonderland. One is the nested async calls problem (which is causing serious strife on the nodejs board) and the second problem is unpredictable results from coffeescript forced-indentation. I like Python's indentation and used it for years, but for some reason the coffeescript indentation syntax is driving me crazy. I would be happy to discuss these indentation problems anytime to explain further.

Ok, now I'll really get to the point. Kaffeine seems to solve both of my problems in a simple way. Plus I get most of the cool syntax sugar I have been enjoying in coffeescript. I am about to try out Kaffeine and especially see I can port my html generator to it.

However (this is finally the real point), I am concerned that I can't find any discussion of kaffeine anywhere. Weepy seems to be a lone voice. This naturally makes me worry whether Kaffeine will grow to be a community-supported tool or not. In order to make a crazy decision to jump to a coffeescript replacement for a lengthy project that I'm already three weeks into, I have to do some serious thinking.

I could live with a new tool with no support if it was simple enough to support myself. That is something I will investigate. I could also add some support to the project but I could never spend serious resources on it.

update: I am also new to github and I thought there had been no issues here. I just discovered the closed messages. So there is some discussion that happened here that I will read.

`knode` error

C:\Users\Vilius\Desktop\tests\node js\kaffeine js\node_modules\kaffeine\bin\knode:5
var x = process.ARGV.length - 1
                     ^

TypeError: Cannot read property 'length' of undefined

What I typed in console:
knode main.k

Kaffeine does not like alternative do ... while syntax

I sometimes use this:

do {
} while (condition);

But it seems kaffeine struggles with it:

/var/git/transloader.transload.it/api2/node_modules/transloadit/command.js (compiled):28
    }) while (arg.pair == true);
       ^^^^^

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
SyntaxError: Unexpected token while
    at Module._compile (module.js:399:25)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at require (module.js:348:19)
    at Object.<anonymous> (/var/git/transloader.transload.it/api2/node_modules/transloadit/tool.js (compiled):3:11)
    at Module._compile (module.js:404:26)
    at /usr/local/lib/node_modules/kaffeine/lib/index.js:94:12
    at Object..js (/var/git/transloader.transload.it/api2/node_modules/transloadit/transloadit.js:9:12)

I did not find a workaround for this one yet.

Error with double parentheses

With v. 0.15 and also the live web demo:
(1/2 + (1/2))
yields:
Error: TypeError: Cannot set property 'matching' of undefined

(1/2 + 1/2)
works fine. I assume the extra parentheses should still be valid.

slices

like

x = a[1..]
y = b[1...v]

Cannot find module 'optparse'

Hi, I installed Kaffeine with:

npm install kaffeine

and get this error when i try to execute kaffeine

module.js:337
    throw new Error("Cannot find module '" + request + "'");
          ^
Error: Cannot find module 'optparse'
    at Function._resolveFilename (module.js:337:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:359:17)
    at require (module.js:375:17)
    at Object.<anonymous> (/Users/Cesar/node_modules/kaffeine/bin/command.js:4:22)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Module.require (module.js:359:17)

is this the way to install it?

additional info:
node -v
v0.6.19

OSX 10.6.8

knode

redis = require 'redis'
client = redis.createClient()
foo = client.get! 'foo'

mini:~ tyler$ knode test.kaf
/Users/tyler/test.kaf:1
require 'redis'
^^^^^^^

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected string
at Module._compile (module.js:399:25)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at require (module.js:348:19)
at Object. (/usr/local/lib/node/.npm/kaffeine/0.0.8/package/bin/knode:13:1)
at Module._compile (module.js:404:26)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)

GH pages

create a nice demo page in GH pages

Webpage Documentation doesn't seem to match current version

I was trying this project out, there's a nice webpage at
http://weepy.github.io/kaffeine/index.html

However, the content there doesn't seem to correspond to the latest version of this repository.

In particular the arrow notation for functions is not described on that webpage.

What is up?

Does that website need to be updated or am I installing the wrong version? I tried installing both the version in npm and cloning this repository directly and installing that.

Plugin: macro

like a function but is inserted into local scope.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.