Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created February 19, 2014 03:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaronpowell/9085724 to your computer and use it in GitHub Desktop.
Save aaronpowell/9085724 to your computer and use it in GitHub Desktop.
AngularJS macros in Sweet.js
let module = macro {
case {_
$name
import $params (,) ...
} => {
letstx $name_str = [makeValue(unwrapSyntax(#{$name}), #{here})];
return #{
angular.module($name_str, [$params (,) ...])
};
}
}
let factory = macro {
case {_
$name {
import $iparams
$($mname $mparams $mbody) ...
}
} => {
letstx $name_str = [makeValue(unwrapSyntax(#{$name}), #{here})];
return #{
.factory($name_str, function $iparams {
var ret = {};
$(ret.$mname
= function $mname $mparams $mbody; ) ...
return ret;
})
};
}
}
module foo
import '$a', '$b'
factory myFactory {
import ($a, $b)
say (foo) {
console.log($a);
console.log($b);
return {
a: $a[0]
};
}
}
factory anotherFactory {
import ($http)
getFoo () {
return $http.get('http://foo');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment