Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from grncdr/gist:4554165
Created January 3, 2014 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendethiel/8230514 to your computer and use it in GitHub Desktop.
Save vendethiel/8230514 to your computer and use it in GitHub Desktop.
macro $do {
rule {($($x = $y) (,) ...) $body} => {
(function ($x (,) ...) $body)($y (,) ...)
}
rule {$name ($($x = $y) (,) ...) $body} => {
(function $name ($x (,) ...) $body)($y (,) ...)
}
}
macro $var {
rule {[$name (,) ...] = $expr} => {
var $name (,) ...
$do (i = 0, array = $expr) {
$($name = array[i++];) ...
}
}
rule { {$name (,) ...} = $expr} => {
var $name (,) ...
$do (obj = $expr) {
$($name = obj.$name;) ...
}
}
rule { $name:ident = $expr } => {
var $name = $expr
}
}
$var [x, y, z] = [0, 1, 2]
$var {a, b} = {a: 1, b: 45}
$var [x, y, z] = [0, 1, 2];
console.log(x, y, z); // 0 1 2
$var {x, y, z} = {x: 5, y: 6, z: 7};
console.log(x, y, z); // 5 6 7
$var w = 10;
console.log(w); // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment