Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.