public
Last active

parameter annotations (type, contract, etc.) in sweet.js

  • Download Gist
annotate.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
macro def {
case $name:ident ( $($params:ident : $type:ident) (,) ...) $body => {
// just throwing away the type annotation. The semantics of type
// annotations left as an exercise to the reader :)
function $name ($params (,) ...) $body
}
}
 
def add (a : Number, b : Number) {
return a + b;
}
 
add(1,2)

Note that making annotations optional are currently hampered by a bug, though there might be some clever workaround.

For closure compiler annotations, the macro needs the ability to output a comment. Currently, it seems that the literal comment is interpreted as a comment by sjs and thus not output. Is there a workaround for this?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.