jsfu
Improve your Javascript fu with language extensions
jsfu is a dead simple rewriter, without any grammars, AST:s or parsers.
All extensions will be pluggable and it will be easy include your own.
The current version (0.1.2) contains two extensions.
An interface for modifying which extensions get loaded is
not yet available.
This code is currently experimental.
Install
npm install jsfu
Or globally
npm install -g jsfu
Usage
From the command line
Transpile files from src/jsfu
to bin/js
:
$ jsfu --input src/jsfu --output bin/js
Or run the included example with:
$ jsfu example sushi
Add the -p
parameter to see the transpiled source of the example,
or store it in a file with `--output``
jsfu also supports reading from stdin and stdout using
-s
or --stdin
for stdin
-p
or --print
for stdout
Example:
$ echo '(a, b) => {}' | ./bin/jsfu -sp | grep functionfunction {}
From node.js
var jsfu = ; var source = '(a, b) => {};';var transpiled = ; console;
will output
{};
Featuers
Transpile your code with jsfu and get access to:
Automatic Continuation
The Automatic Continuation feature will replace the §
symbol
with a callback containing any code that comes below the function call.
It will turn
var piece = ;;
into
;
Another example, before transcompilation:
{ // Lunch hour. Need to stand in line first. ;} var sushi = ;console;
After transcompilation:
{ // Lunch hour. Need to stand in line first. ;} ;
Async Wrapping
Parallel calls are supported by encapsulating the code inside a function:
Without async wrapping:
var r = ;var r = ;var r = ;
This will first run A
When A is completed C will run
When C is completed B will run
With async wrapping:
{ var a = ; var c = ; };var b = ;
This will run A and B in parallel
When A is completed C will run
Compact function definitions
Use an arrow to create compact function definitions Useful when passing a function as a parameter
Turn
// A parameter; // Or a definitionvar { };
into
// A parameter; // Or a definition { };
Known Bugs
A bracket }
symbol below an asynchronous call that's not
part of its wrapping function will cause an error.
Example
{ var sushi = ; sushi; myRating = rating: 5 // <- this } will cause an error } // <- this } will not cause an error
This bug will be fixed in 0.1.3
License
(The MIT License)
Copyright (c) 2012 Charlie Rudenstål <charlie4@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.