1.6.3-5 • Published 6 years ago

toffee-script v1.6.3-5

Weekly downloads
9
License
-
Repository
github
Last release
6 years ago

ToffeeScript

ToffeeScript is a CoffeeScript dialect with Asynchronous Grammar

Features

  1. Asynchronous everywhere
    • Condition: If, Switch
    • Loop: For In, For Of, While with guard when
    • Mathematics
    • Logical Operation
  2. Auto Callback
  3. Regexp Operator =~ and matches \~, \&, \0~\9
  4. High efficent code generated.
  5. Sourcemap Supported.
    • Follow up to CoffeeScript 1.6.2 so far
  6. Safety named-function supported.
    • Added in ToffeeScript 1.6.2-3

Installation

npm install toffee-script

Named Function

ToffeeScript support named function which is different from CoffeeScript. if the function defined in the first level of code block and the function name haven't been used, then compile it as named function. see Code Examples section It won't have compatible issue with CoffeeScript except one case

# m never declared above, m must be local variable and assign to undefined
m()
m = ->
m

in CoffeeScript will throw exception undefined is not function. Use m as constant undefined variable is rare case.

in ToffeeScript function m is hoisted, and will run function m() as Javascript does.

Code Examples

Left: ToffeeScript

Right: Generated JavaScript

Basic

a(b, function() { x = arguments0, y = arguments1; return console.log(x, y); });

with powerful CoffeeScript assignment [...]

a(b, function() { _this.x = arguments0, y = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return console.log(_this.x, y); });

Condition

if (i) { a(function() { x = arguments0; $$_0(); }); } else { b(function() { y = arguments0; $$_0(); }); }

function _$$_0() { return console.log(x, y); };

Async in condition

a(function() { $cb$_2(e = arguments0); }); function $cb$2($$0) { if ($$0) { return cb(e); } else { $$1(); } function $$_1() { return foo(); }; };

Async in condition with multi return

Async call always return first argument

fs.readFile('foo', function() { $cb$_2((e = arguments0, data = arguments1, e)); }); function $cb$2($$0) { if ($$0) { return cb(e); } else { $$1(); } function $$_1() { return console.log(data); }; };

Loop

Support For In, For Of, While with guard when

$res$_1 = []; i = _i = 1; function _step() { i = ++_i; _body(); }; function _body() { if (_i <= 3) { if (i > 2) { a(function($$2) { _step($res$1.push($$2)); }); } else { _step(); } } else { _done(); } }; function _done() { $cb$0($res$1); }; _body(); function $cb$_0() { return xs = arguments0; };

Mathematics

a(function($$_1) { b(function($$3) { c(function($$4) { $cb$2($$3 * $$4); }); }); function $cb$2($$5) { $cb$0($$1 + $$5); }; }); function $cb$_0() { return x = arguments0; };

Object

$$_1 = a; b(function($$2) { $cb$0({ a: $$1, b: $$2, c: c }); }); function $cb$_0() { return A = arguments0; };

Logical

Support ||, &&, ?, &&=, ||=, ?=

a(function($$_1) { if ($$1) { $cb$3($$1); } else { b(function($$2) { $cb$3($$2); }); } }); function $cb$3($$4) { $cb$0($$4); }; function $cb$_0() { x = arguments0; return console.log(x); };

Auto Callback

Return Multiple Values

Autocb with default args

Regexp

if ((matches = a.match(b)) || (matches = b.match(c))) { matches; matches0; matches0; matches9; }

Named Function Supported

function b() {};

null;

Those cases will be kept in non-named function

f = null;

if (a) { b = c(function() {}); }

d(e = function() {});

f = function() {};

null;

1.6.3-5

6 years ago

1.6.3-4

10 years ago

1.6.3-3

10 years ago

1.6.3-2

10 years ago

1.6.3-1

11 years ago

1.6.3

11 years ago

1.6.2-8

11 years ago

1.6.2-7

11 years ago

1.6.2-5

11 years ago

1.6.2-4

11 years ago

1.6.2-3

11 years ago

1.6.2-2

11 years ago

1.6.2-1

11 years ago

1.6.2

11 years ago

1.4.0

12 years ago

1.3.3

12 years ago

1.2.0-0

12 years ago

1.1.4-3

12 years ago

1.1.4-1

12 years ago

1.1.3-4

12 years ago

1.1.3-3

13 years ago

1.1.3-1

13 years ago

1.1.3

13 years ago

1.1.3-pre

13 years ago